Class "Site"
Implements the StackExchange APIs client for a specific site.
Note #1: the **kwargs argument in methods is necessary for request parameters, like pagesize, order, etc.
Note #2: The Item class in the methods return type hint is a standard dict class with the ability to get values not only using the d['key'] construction, but also d.key.
Methods:
__init__
__init__Signature:
__init__(self, name: str, access_token: str | None = None,
app_key: str | None = None) -> NoneArguments:
name- site's name (see Module "sites" page);access_token- access token;app_key- application key.
get
getSignature:
get(self, query: str, **kwargs: Any) -> dictReturns raw result of calling query to API.
post
postAuth required
Signature:
post(self, query: str, **kwargs: Any) -> RawResponseDictReturns raw result of POST-calling query to API.
add_answer
add_answerAuth required
Signature:
add_answer(self, q_id: int, body: str, **kwargs: Any) -> ItemCreate a new answer on the given question.
add_answers_suggested_edit
add_answers_suggested_editAuth required
Signature:
add_answers_suggested_edit(self, a_id: int, body: str,
comment: str, **kwargs: Any) -> ItemCreate a suggested edit on an existing answer.
add_comment
add_commentAuth required
Signature:
add_comment(self, post_id: int, body: str, **kwargs: Any) -> ItemCreate a new comment.
add_question
add_questionAuth required
Signature:
add_question(self, title: str, body: str, tags: list[str], **kwargs: Any) -> ItemCreate a new question.
add_questions_suggested_edit
add_questions_suggested_editAuth required
Signature:
add_answers_suggested_edit(self, a_id: int, body: str,
comment: str, **kwargs: Any) -> ItemCreate a suggested edit on an existing question.
delete_answer
delete_answerAuth required
Signature:
delete_answer(self, a_id: int, **kwargs: Any) -> NoneDeletes an answer.
delete_comment
delete_commentAuth required
Signature:
delete_comment(self, c_id: int, **kwargs: Any) -> NoneDeletes a comment.
delete_question
delete_questionAuth required
Signature:
delete_question(self, q_id: int, **kwargs: Any) -> NoneDeletes a question.
edit_answer
edit_answerAuth required
Signature:
edit_answer(self, a_id: int, body: str, **kwargs: Any) -> ItemEdits an existing answer.
edit_comment
edit_commentAuth required
Signature:
edit_answer(self, a_id: int, body: str, **kwargs: Any) -> ItemEdits an existing comment.
edit_question
edit_questionAuth required
Signature:
edit_question(self, q_id: int, title: str, body: str, tags: list[str],
**kwargs: Any) -> ItemEdits an existing question.
get_answers
get_answersSignature:
get_answers(self, ids: Iterable[int] | None = None, *kwargs: Any) -> list[Item]Returns, if ids is set, all the undeleted answers in the system, else the set of answers identified by ids.
get_answer
get_answerSignature:
get_answer(self, a_id: int, **kwargs: Any) -> Item | NoneReturns answer identified by a_id. Returns None if requested object don't found.
get_answers_on_collectives
get_answers_on_collectivesSignature:
get_answers_on_collectives(self, slugs: Iterable[str], **kwargs: Any) -> list[Item]Returns answers belonging to collectives in slugs found on the site.
get_answers_on_questions
get_answers_on_questionsSignature:
get_answers_on_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the answers to a set of questions identified by ids.
get_articles
get_articlesSignature:
get_articles(self, ids: Iterable[int] | None = None, **kwargs: Any) -> list[Item]Returns, if ids is set, all articles on the site, else the articles identified by ids.
get_article
get_articleSignature:
get_article(self, a_id: int, **kwargs: Any) -> Item | NoneReturns article identified by a_id. Returns None if requested object don't found.
get_badges
get_badgesSignature:
get_badges(self, **kwargs: Any) -> list[Item]Returns all badges in the system.
get_badges_recipients
get_badges_recipientsSignature:
get_badges_recipients(self, ids: Iterable[int] | None = None,
**kwargs: Any) -> list[Item]Returns, if ids is set, recently awarded badges in the system, constrained to a certain set of badges, else recently awarded badges in the system.
get_tag_based_badges
get_tag_based_badgesSignature:
get_tag_based_badges(self, **kwargs: Any) -> list[Item]Returns the badges that are awarded for participation in specific tags.
get_non_tag_based_badges
get_non_tag_based_badgesSignature:
get_non_tag_based_badges(self, **kwargs: Any) -> list[Item]Returns all non-tagged-based badges in alphabetical order.
get_collectives
get_collectivesSignature:
get_collectives(self, slugs: Iterable[str] | None = None,
**kwargs: Any) -> list[Item]Returns, if slugs is set, collectives in slugs found on the site, else, all collectives in the system.
get_collective
get_collectiveSignature:
get_collective(self, slug: str, **kwargs: Any) -> Item | NoneReturns collective with specific slug. Returns None if requested object don't found.
get_comments
get_commentsSignature:
get_comments(self, ids: Iterable[int] | None = None, **kwargs: Any) -> list[Item]Returns, if ids is set, the comments identified by ids, else, all comments on the site.
get_comment
get_commentSignature:
get_comment(self, c_id: int, **kwargs: Any) -> Item | NoneReturns the comment identified in c_id. Returns None if requested object don't found.
get_comments_on_answers
get_comments_on_answersSignature:
get_comments_on_answers(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the comments on a set of answers.
get_comments_on_articles
get_comments_on_articlesSignature:
get_comments_on_articles(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the comments on a set of articles.
get_comments_on_posts
get_comments_on_postsSignature:
get_comments_on_posts(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the comments on a set of posts.
get_comments_on_questions
get_comments_on_questionsSignature:
get_comments_on_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the comments on a set of questions.
get_info
get_infoSignature:
get_info(self) -> ItemReturns a collection of statistics about the site.
get_linked_in_articles
get_linked_in_articlesSignature:
get_linked_in_articles(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions that are linked to the articles identified by ids.
get_linked_in_questions
get_linked_in_questionsSignature:
get_linked_in_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns questions which link to those questions identified by ids.
get_posts
get_postsSignature:
get_posts(self, ids: Iterable[int] | None = None, **kwargs: Any) -> list[Item]Returns, if ids is set, the posts identified by ids, else, all posts on the site.
get_post
get_postSignature:
get_post(self, p_id: int, **kwargs: Any) -> Item | NoneReturns the post identified in p_id. Returns None if requested object don't found.
get_privileges
get_privilegesSignature:
get_privileges(self, **kwargs: Any) -> list[Item]Returns the earnable privileges on a site.
get_questions
get_questionsSignature:
get_questions(self, ids: Iterable[int] | None = None, **kwargs: Any) -> list[Item]Returns, if ids is set, all the undeleted questions in the system, else the set of questions identified by ids.
get_question
get_questionSignature:
get_question(self, q_id: int, **kwargs: Any) -> Item | NoneReturns the question identified in q_id. Returns None if requested object don't found.
get_questions_on_answers
get_questions_on_answersSignature:
get_questions_on_answers(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions on a set of answers.
get_bountied_questions
get_bountied_questionsSignature:
get_bountied_questions(self, **kwargs: Any) -> list[Item]Returns all the questions with active bounties in the system.
get_questions_on_collectives
get_questions_on_collectivesSignature:
get_questions_on_collectives(self, slugs: Iterable[str], **kwargs: Any) -> list[Item]Returns the questions on a set of collectives.
get_questions_with_no_answers
get_questions_with_no_answersSignature:
get_questions_with_no_answers(self, **kwargs: Any) -> list[Item]Returns questions which have received no answers.
get_related_to_questions
get_related_to_questionsSignature:
get_related_to_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns questions that the site considers related to those identified by ids.
get_unanswered_questions
get_unanswered_questionsSignature:
get_unanswered_questions(self, **kwargs: Any) -> list[Item]Returns questions the site considers to be unanswered.
get_unanswered_questions_on_my_tags
get_unanswered_questions_on_my_tagsAuth required
Signature:
get_unanswered_questions_on_my_tags(self, **kwargs: Any) -> list[Item]Returns questions the site considers to be unanswered, which are within a user's favorite tags.
If a user has no favorites, their frequented tags are used instead.
get_revisions
get_revisionsSignature:
get_revisions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns edit revisions identified by ids.
get_revisions_on_posts
get_revisions_on_postsSignature:
get_revisions_on_posts(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns revisions on the set of posts, identified by ids.
search
searchSignature:
search(self, **kwargs: Any) -> list[Item]Searches a site for any questions which fit the given criteria.
Warning: one of
taggedorintitlekeyword arguments must be set.
advanced_search
advanced_searchSignature:
advanced_search(self, **kwargs: Any) -> list[Item]Searches a site for any questions which fit the given criteria.
get_similar
get_similarSignature:
get_similar(self, title: str, **kwargs: Any) -> list[Item]Returns questions which are similar to a hypothetical one based on a title and tag combination.
get_suggested_edits
get_suggested_editsSignature:
get_suggested_edits(self, ids: Iterable[int] | None = None,
**kwargs: Any) -> list[Item]Returns, if ids is set, the suggested edits identified by ids, else all suggested edits on the site.
get_suggested_edits_on_posts
get_suggested_edits_on_postsSignature:
get_suggested_edits_on_posts(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns suggested edits on the set of posts, identified by ids.
get_tags
get_tagsSignature:
get_tags(self, **kwargs: Any) -> list[Item]Returns all tags in the system.
get_top_answerers_on_tag
get_top_answerers_on_tagSignature:
get_top_answerers_on_tag(self, tag: str, period: str,
**kwargs: Any) -> list[Item] | NoReturnReturns the top 20 answerers active in a given tag, of either all-time or the last 30 days.
get_top_askers_on_tag
get_top_askers_on_tagSignature:
get_top_askers_on_tag(self, tag: str, period: str,
**kwargs: Any) -> list[Item] | NoReturnReturns the top 20 askers active in a given tag, of either all-time or the last 30 days.
get_tags_wikis
get_tags_wikisSignature:
get_tags_wikis(self, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns the wikis that go with the given set of tags in tags.
get_tags_on_collectives
get_tags_on_collectivesSignature:
get_tags_on_collectives(self, slugs: Iterable[str], **kwargs: Any) -> list[Item]Returns tags belonging to collectives in slugs found on the site.
get_tags_info
get_tags_infoSignature:
get_tags_info(self, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns tags' info from the tags found on the site.
get_tags_faq
get_tags_faqSignature:
get_tags_faq(self, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns the frequently asked questions for the given set of tags in tags.
get_me
get_meAuth required
Signature:
get_me(self, **kwargs: Any) -> ItemReturns the user associated with the passed access_token.
get_moderator_only_tags
get_moderator_only_tagsSignature:
get_moderator_only_tags(self, **kwargs: Any) -> list[Item]Returns the tags found on a site that only moderators can use.
get_my_full_reputation_history
get_my_full_reputation_historyAuth required
Signature:
get_my_full_reputation_history(self, **kwargs: Any) -> list[Item]Returns user's full reputation history, including private events.
get_my_inbox
get_my_inboxAuth required
Signature:
get_my_inbox(self, **kwargs: Any) -> list[Item]Returns the user identified by access_token's inbox.
get_my_unread_inbox
get_my_unread_inboxAuth required
Signature:
get_my_unread_inbox(self, **kwargs: Any) -> list[Item] Returns the unread items in the user identified by access_token's inbox.
get_related_tags
get_related_tagsSignature:
get_related_tags(self, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns the tags that are most related to those in tags.
get_required_tags
get_required_tagsSignature:
get_required_tags(self, **kwargs: Any) -> list[Item]Returns the tags found on a site that fulfill required tag constraints on questions.
get_tags_synonyms
get_tags_synonymsSignature:
get_tags_synonyms(self, tags: Iterable[str] | None = None,
**kwargs: Any) -> list[Item]Returns, if tags is set, all the synonyms that point to the tags identified in tags, else all tag synonyms found on the site.
get_questions_timeline
get_questions_timelineSignature:
get_questions_timeline(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns a subset of the events that have happened to the questions identified by ids.
get_users
get_usersSignature:
get_users(self, ids: Iterable[int] | None = None, **kwargs: Any) -> list[Item]Returns, if ids is set, the users identified by ids, else all users on a site.
get_user
get_userSignature:
get_user(self, uid: int, **kwargs: Any) -> Item | NoneReturns the user identified in uid. Returns None if requested object don't found.
get_users_answers
get_users_answersSignature:
get_users_answers(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the answers the users in ids have posted.
get_users_badges
get_users_badgesSignature:
get_users_badges(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the badges the users in ids have earned.
get_users_on_collectives
get_users_on_collectivesSignature:
get_users_on_collectives(self, slugs: Iterable[str], **kwargs: Any) -> list[Item]Returns users belonging to collectives in slugs found on the site.
get_users_comments
get_users_commentsSignature:
get_users_comments(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the comments posted by users in ids.
get_users_comments_to
get_users_comments_toSignature:
get_users_comments_to(self, ids: Iterable[int], toid: int, **kwargs: Any) -> list[Item]Returns the comments that the users in ids have posted in reply to the single user identified in toid.
get_users_favorites
get_users_favoritesSignature:
get_users_favorites(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions that users in ids have bookmarked.
get_users_mentions
get_users_mentionsSignature:
get_users_mentions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns all the comments that the users in ids were mentioned in.
get_users_posts
get_users_postsSignature:
get_users_posts(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the posts the users in ids have posted.
get_user_privileges
get_user_privilegesSignature:
get_user_privileges(self, uid: int, **kwargs: Any) -> list[Item]Returns the privileges a user with ID uid has.
get_users_questions
get_users_questionsSignature:
get_users_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions asked by the users in ids.
get_users_unaccepted_questions
get_users_unaccepted_questionsSignature:
get_users_unaccepted_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions asked by the users in ids which have at least one answer, but no accepted answer.
get_users_unanswered_questions
get_users_unanswered_questionsSignature:
get_users_unanswered_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions asked by the users in ids which the site considers unanswered, while still having at least one answer posted.
get_users_bountied_questions
get_users_bountied_questionsSignature:
get_users_bountied_questions(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions on which the users in {ids} have active bounties.
get_users_questions_with_no_answers
get_users_questions_with_no_answersSignature:
get_users_questions_with_no_answers(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the questions asked by the users in ids which have no answers.
get_users_reputation
get_users_reputationSignature:
get_users_reputation(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns a subset of the reputation changes for users in {ids}.
get_users_reputation_history
get_users_reputation_historySignature:
get_users_reputation_history(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns users' public reputation history.
get_users_suggested_edits
get_users_suggested_editsSignature:
get_users_suggested_edits(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the suggested edits that the users in ids have submitted.
get_users_tags
get_users_tagsSignature:
get_users_tags(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns the tags the users identified in ids have been active in.
get_user_top_answers_on_tags
get_user_top_answers_on_tagsSignature:
get_user_top_answers_on_tags(self, uid: int, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns the top 30 answers a user has posted in response to questions with the given tags.
get_user_top_questions_on_tags
get_user_top_questions_on_tagsSignature:
get_user_top_questions_on_tags(self, uid: int, tags: Iterable[str], **kwargs: Any) -> list[Item]Returns the top 30 questions a user has asked with the given tags.
get_users_timeline
get_users_timelineSignature:
get_users_timeline(self, ids: Iterable[int], **kwargs: Any) -> list[Item]Returns a subset of the actions the users in ids have taken on the site.
get_user_top_answers_tags
get_user_top_answers_tagsSignature:
get_user_top_answers_tags(self, uid: int, **kwargs: Any) -> list[Item]Returns a single user's top tags by answer score.
get_user_top_questions_tags
get_user_top_questions_tagsSignature:
get_user_top_questions_tags(self, uid: int, **kwargs: Any) -> list[Item]Returns a single user's top tags by question score.
get_user_top_tags
get_user_top_tagsSignature:
get_user_top_tags(self, uid: int, **kwargs: Any) -> list[Item]Returns a single user's top tags by combined question and answer score.
get_moderators
get_moderatorsSignature:
get_moderators(self, **kwargs: Any) -> list[Item]Returns those users on a site who can exercise moderation powers.
get_elected_moderators
get_elected_moderatorsSignature:
get_elected_moderators(self, **kwargs: Any) -> list[Item]Returns those users on a site who both have moderator powers, and were actually elected.
Last updated