SlyMastodon.mastodon#

Mastodon API client and authenticated types

https://docs.joinmastodon.org/api/

Classes

AuthorizedPost(id, created_at, account, ...)

A post made by the authorized user with some extra fields

AuthorizedUser(id, username, acct, ...)

The currently authenticated user

CredentialSource(sensitive, language, note, ...)

Extra info provided for the account of an authorized user

Mastodon(instance_url, auth[, lang])

Mastodon API client

PollSetup(options, expires_in, multiple, ...)

Parameters for creating a poll when posting

ScheduledPost(id, scheduled_at, params, ...)

A scheduled post that has not been posted yet

ScheduledPostParams(text, poll, media_ids, ...)

https://docs.joinmastodon.org/entities/ScheduledStatus/#params

ScopeGranular()

Granular scopes for OAuth2

ScopeSimple()

Top level scopes for OAuth2

class SlyMastodon.mastodon.ScopeSimple#

Top level scopes for OAuth2

https://docs.joinmastodon.org/api/oauth-scopes/

READ = 'read'#
WRITE = 'write'#
FOLLOW = 'follow'#
PUSH = 'push'#
class SlyMastodon.mastodon.ScopeGranular#

Granular scopes for OAuth2

https://docs.joinmastodon.org/api/oauth-scopes/

READ_ACCOUNTS = 'read:accounts'#
READ_BLOCKS = 'read:blocks'#
READ_BOOKMARKS = 'read:bookmarks'#
READ_FAVOURITES = 'read:favourites'#
READ_FILTERS = 'read:filters'#
READ_FOLLOWS = 'read:follows'#
READ_LISTS = 'read:lists'#
READ_MUTES = 'read:mutes'#
READ_NOTIFICATIONS = 'read:notifications'#
READ_STATUSES = 'read:statuses'#
WRITE_ACCOUNTS = 'write:accounts'#
WRITE_BLOCKS = 'write:blocks'#
WRITE_BOOKMARKS = 'write:bookmarks'#
WRITE_CONVERSATIONS = 'write:conversations'#
WRITE_FAVOURITES = 'write:favourites'#
WRITE_FILTERS = 'write:filters'#
WRITE_FOLLOWS = 'write:follows'#
WRITE_LISTS = 'write:lists'#
WRITE_MEDIA = 'write:media'#
WRITE_MUTES = 'write:mutes'#
WRITE_NOTIFICATIONS = 'write:notifications'#
WRITE_REPORTS = 'write:reports'#
WRITE_STATUSES = 'write:statuses'#
class SlyMastodon.mastodon.CredentialSource(sensitive: bool, language: str, note: str, privacy: PrivacyDirect, fields: list[UserField], follow_requests_count: int)#

Bases: DataclassJsonMixin

Extra info provided for the account of an authorized user

sensitive: bool#
language: str#
note: str#
privacy: PrivacyDirect#
fields: list[UserField]#
follow_requests_count: int#
classmethod from_json(value: JsonTypeCo) T#
class SlyMastodon.mastodon.AuthorizedUser(id: str, username: str, acct: str, display_name: str, locked: bool, bot: bool, created_at: datetime, discoverable: bool, note: str, url: str, avatar: str, avatar_static: str, header: str, header_static: str, followers_count: int, following_count: int, statuses_count: int, last_status_at: datetime, emojis: list[Emoji], fields: list[UserField])#

Bases: User

The currently authenticated user

https://docs.joinmastodon.org/entities/Account/#CredentialAccount

source: CredentialSource#
role: Role#
property at_username: str#

Full webfinger address

classmethod from_json(value: JsonTypeCo) T#
id: str#
username: str#
acct: str#
display_name: str#
locked: bool#
bot: bool#
created_at: datetime#
discoverable: bool#
note: str#
url: str#
avatar: str#
avatar_static: str#
header: str#
header_static: str#
followers_count: int#
following_count: int#
statuses_count: int#
last_status_at: datetime#
emojis: list[Emoji]#
fields: list[UserField]#
class SlyMastodon.mastodon.AuthorizedPost(id: str, created_at: str, account: User, visibility: PrivacyDirect, sensitive: bool, spoiler_text: str, media_attachments: list[MediaAttachment], application: Application | None, mentions: list[StatusMention], tags: list[StatusTag], emojis: list[Emoji], reblogs_count: int, favourites_count: int, replies_count: int, url: str | None, in_reply_to_id: str | None, in_reply_to_account_id: str | None, reblog: Post | None, poll: Poll | None, card: PreviewCard | None, language: str | None, edited_at: str | None)#

Bases: Post

A post made by the authorized user with some extra fields

https://docs.joinmastodon.org/entities/Status/#favourited

favourited: bool#
reblogged: bool#
muted: bool#
bookmarked: bool#
pinned: bool#
filtered: bool#
classmethod from_json(value: JsonTypeCo) T#
content: str#
id: str#
created_at: str#
account: User#
visibility: PrivacyDirect#
sensitive: bool#
spoiler_text: str#
media_attachments: list[MediaAttachment]#
application: Application | None#
mentions: list[StatusMention]#
tags: list[StatusTag]#
emojis: list[Emoji]#
reblogs_count: int#
favourites_count: int#
replies_count: int#
url: str | None#
in_reply_to_id: str | None#
in_reply_to_account_id: str | None#
reblog: Post | None#
poll: Poll | None#
card: PreviewCard | None#
language: str | None#
edited_at: str | None#
class SlyMastodon.mastodon.PollSetup(options: list[str], expires_in: int, multiple: bool | None, hide_totals: bool | None)#

Parameters for creating a poll when posting

options: list[str]#
expires_in: int#
multiple: bool | None#
hide_totals: bool | None#
class SlyMastodon.mastodon.ScheduledPostParams(text: str, poll: PollSetup | None, media_ids: list[str] | None, sensitive: bool | None, spoiler_text: str | None, visibility: PrivacyDirect, in_reply_to_id: str | None, language: str | None, application_id: str | None, idempotency: str | None, with_rate_limit: bool)#

Bases: DataclassJsonMixin

https://docs.joinmastodon.org/entities/ScheduledStatus/#params

text: str#
poll: PollSetup | None#
media_ids: list[str] | None#
sensitive: bool | None#
spoiler_text: str | None#
visibility: PrivacyDirect#
in_reply_to_id: str | None#
language: str | None#
application_id: str | None#
idempotency: str | None#
with_rate_limit: bool#
classmethod from_json(value: JsonTypeCo) T#
class SlyMastodon.mastodon.ScheduledPost(id: str, scheduled_at: datetime, params: ScheduledPostParams, media_attachments: list[MediaAttachment])#

Bases: DataclassJsonMixin

A scheduled post that has not been posted yet

https://docs.joinmastodon.org/entities/ScheduledStatus/

id: str#
scheduled_at: datetime#
params: ScheduledPostParams#
media_attachments: list[MediaAttachment]#
classmethod from_json(value: JsonTypeCo) T#
class SlyMastodon.mastodon.Mastodon(instance_url: str, auth: OAuth2, lang: str = 'en')#

Bases: MastodonPublic

Mastodon API client

lang: str#
set_default_lanuage(lang: str)#

Set the default language used to annotate posts with ISO 639 ex. “en”, “ja”, “zh”, “fr”

await me() AuthorizedUser#

Get the currently authenticated user

await post(text: str, media: list[str | MediaAttachment] | None = None, reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) Post#

Make a new post

await post_media(media: list[str | MediaAttachment], reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) Post#

Make a new post with no text and only images

await post_poll(text: str, poll: PollSetup, reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) Post#

Make a new post with a poll

await edit_post(post_id: str, text: str, media: list[str | MediaAttachment] | None = None, reply_to: str | None = None, poll: PollSetup | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, scheduled_at: datetime | None = None, lang: str | None = None) Post#

Replace an existing post

await get_my_post(post_id: str) AuthorizedPost#

Get a post with extra info, if posted by the authorized user, by ID

await delete_post(post_id: str) DeletedPost#

Delete a post by ID

await boost(post_id: str, privacy: Privacy = Privacy.PUBLIC)#

Boost a post

await schedule_post(text: str, scheduled_at: datetime, media: list[str | MediaAttachment] | None = None, reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) ScheduledPost#

Schedule a new post, at least 5 minutes in the future

await schedule_media(media: list[str | MediaAttachment], scheduled_at: datetime, reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) ScheduledPost#

Schedule a new post with no text and only images, at least 5 minutes in the future

await schedule_poll(text: str, poll: PollSetup, scheduled_at: datetime, reply_to: str | None = None, sensitive: bool = False, spoiler_text: str | None = None, privacy: Privacy = Privacy.PUBLIC, lang: str | None = None) ScheduledPost#

Schedule a new post with a poll, at least 5 minutes in the future

await delete_json(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: Any = None, headers: dict[str, str] | None = None)#
await get_form(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, data: Any | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
get_full_url(path: str) str#

Convert a relative path to an absolute url for this API

await get_json(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']] | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
await get_post(post_id: str) Post#

Get a post by ID

await get_text(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']] | None = None, headers: dict[str, str] | None = None) str#
paginated(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]], limit: int | None) AsyncLazy[dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]]#

Return an awaitable and async iterable over google or twitter-style paginated items. You can also await the return value to get the entire list.

await post_form(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, data: Any | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
await post_form_empty(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, data: Any | None = None, headers: dict[str, str] | None = None)#
await post_json(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']] | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
await post_json_empty(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']] | None = None, headers: dict[str, str] | None = None)#
await put_form(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, data: Any | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
await put_json(path: str, params: Mapping[str, int | str | Enum | None | Set[ParamType] | Sequence[ParamType]] | None = None, json: dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']] | None = None, headers: dict[str, str] | None = None) dict[str, int | float | bool | str | None | list['JsonType'] | dict[str, 'JsonType']]#
await user(at_or_id: str) User#

Lookup an account by ID or username @user : defaults to the current domain @user@domain : any other domain

base_url: str#
auth: Auth#
await media(media_id: str) MediaAttachment#

Get information about a media file

await upload(file: str | tuple[str, Union[bytes, IO[bytes]]], thumbnail: str | tuple[str, Union[bytes, IO[bytes]]] | None = None, description: str | None = None, focus: tuple[float, float] | None = None) MediaAttachment#

Upload a file to the server

await update_media(media: str | MediaAttachment | UnuploadedMediaAttachment, thumbnail: str | tuple[str, Union[bytes, IO[bytes]]] | None = None, description: str | None = None, focus: tuple[float, float] | None = None)#