Instance-wide data and search¶
Instance information¶
These functions allow you to fetch information associated with the current instance as well as data from the instance-wide profile directory.
-
Mastodon.
instance
()[source]¶ Retrieve basic information about the instance, including the URI and administrative contact email.
Does not require authentication unless locked down by the administrator.
Returns an instance dict.
Added: Mastodon v1.1.0, last changed: Mastodon v2.3.0
-
Mastodon.
instance_activity
()[source]¶ Retrieve activity stats about the instance. May be disabled by the instance administrator - throws a MastodonNotFoundError in that case.
Activity is returned for 12 weeks going back from the current week.
Returns a list of activity dicts.
Added: Mastodon v2.1.2, last changed: Mastodon v2.1.2
-
Mastodon.
instance_peers
()[source]¶ Retrieve the instances that this instance knows about. May be disabled by the instance administrator - throws a MastodonNotFoundError in that case.
Returns a list of URL strings.
Added: Mastodon v2.1.2, last changed: Mastodon v2.1.2
-
Mastodon.
instance_health
()[source]¶ Basic health check. Returns True if healthy, False if not.
Added: Mastodon v3.0.0, last changed: Mastodon v3.0.0
-
Mastodon.
instance_nodeinfo
(schema='http://nodeinfo.diaspora.software/ns/schema/2.0')[source]¶ Retrieves the instance’s nodeinfo information.
For information on what the nodeinfo can contain, see the nodeinfo specification: https://github.com/jhass/nodeinfo . By default, Mastodon.py will try to retrieve the version 2.0 schema nodeinfo.
To override the schema, specify the desired schema with the schema parameter.
Added: Mastodon v3.0.0, last changed: Mastodon v3.0.0
-
Mastodon.
instance_rules
()[source]¶ Retrieve instance rules.
Returns a list of id + text dicts, same as the rules field in the instance dicts.
Added: Mastodon v3.4.0, last changed: Mastodon v3.4.0
Profile directory¶
-
Mastodon.
directory
(offset=None, limit=None, order=None, local=None)[source]¶ Fetch the contents of the profile directory, if enabled on the server.
offset how many accounts to skip before returning results. Default 0.
limit how many accounts to load. Default 40.
- order “active” to sort by most recently posted statuses (default) or
- “new” to sort by most recently created profiles.
local True to return only local accounts.
Returns a list of account dicts.
Added: Mastodon v3.0.0, last changed: Mastodon v3.0.0
Announcements¶
These functions allow you to fetch announcements, mark annoucements read and modify reactions.
Reading¶
Writing¶
-
Mastodon.
announcement_dismiss
(id)[source]¶ Set the given annoucement to read.
Added: Mastodon v3.1.0, last changed: Mastodon v3.1.0
-
Mastodon.
announcement_reaction_create
(id, reaction)[source]¶ Add a reaction to an announcement. reaction can either be a unicode emoji or the name of one of the instances custom emoji.
Will throw an API error if the reaction name is not one of the allowed things or when trying to add a reaction that the user has already added (adding a reaction that a different user added is legal and increments the count).
Added: Mastodon v3.1.0, last changed: Mastodon v3.1.0
Trends¶
These functions, when enabled, allow you to fetch trending tags, statuses and links.
Fetch trending-hashtag information, if the instance provides such information.
Specify limit to limit how many results are returned (the maximum number of results is 10, the endpoint is not paginated).
Does not require authentication unless locked down by the administrator.
Important versioning note: This endpoint does not exist for Mastodon versions between 2.8.0 (inclusive) and 3.0.0 (exclusive).
Pass lang to override the global locale parameter, which may affect trend ordering.
Returns a list of hashtag dicts, sorted by the instance’s trending algorithm, descending.
Added: Mastodon v3.5.0, last changed: Mastodon v3.5.0
-
Mastodon.
trending_statuses
(limit=None, lang=None)[source]¶ Fetch trending-status information, if the instance provides such information.
Specify limit to limit how many results are returned (the maximum number of results is 10, the endpoint is not paginated).
Pass lang to override the global locale parameter, which may affect trend ordering.
Returns a list of status dicts, sorted by the instances’s trending algorithm, descending.
Added: Mastodon v3.5.0, last changed: Mastodon v3.5.0
-
Mastodon.
trending_links
(limit=None, lang=None)[source]¶ Fetch trending-link information, if the instance provides such information.
Specify limit to limit how many results are returned (the maximum number of results is 10, the endpoint is not paginated).
Returns a list of card dicts, sorted by the instances’s trending algorithm, descending.
Added: Mastodon v3.5.0, last changed: Mastodon v3.5.0
-
Mastodon.
trends
(limit=None)[source]¶ Old alias for trending_tags()
Deprecated. Please use trending_tags() instead.
Added: Mastodon v2.4.3, last changed: Mastodon v3.5.0
Search¶
These functions allow you to search for users, tags and, when enabled, full text, by default within your own posts and those you have interacted with.
-
Mastodon.
search
(q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True)[source]¶ Fetch matching hashtags, accounts and statuses. Will perform webfinger lookups if resolve is True. Full-text search is only enabled if the instance supports it, and is restricted to statuses the logged-in user wrote or was mentioned in.
result_type can be one of “accounts”, “hashtags” or “statuses”, to only search for that type of object.
Specify account_id to only get results from the account with that id.
offset, min_id and max_id can be used to paginate.
exclude_unreviewed can be used to restrict search results for hashtags to only those that have been reviewed by moderators. It is on by default. When using the v1 search API (pre 2.4.1), it is ignored.
Will use search_v1 (no tag dicts in return values) on Mastodon versions before 2.4.1), search_v2 otherwise. Parameters other than resolve are only available on Mastodon 2.8.0 or above - this function will throw a MastodonVersionError if you try to use them on versions before that. Note that the cached version number will be used for this to avoid uneccesary requests.
Returns a search result dict, with tags as `hashtag dicts`_.
Added: Mastodon v1.1.0, last changed: Mastodon v2.8.0
-
Mastodon.
search_v2
(q, resolve=True, result_type=None, account_id=None, offset=None, min_id=None, max_id=None, exclude_unreviewed=True)[source]¶ Identical to search_v1(), except in that it returns tags as hashtag dicts, has more parameters, and resolves by default.
For more details documentation, please see search()
Returns a search result dict.
Added: Mastodon v2.4.1, last changed: Mastodon v2.8.0