Client#
- class atproto.xrpc_client.client.client.Client(base_url: Optional[str] = None, *args, **kwargs)#
Bases:
SessionMethodsMixin
,TimeMethodsMixin
,ClientRaw
High-level client for XRPC of ATProto.
- delete_post(post_rkey: str, profile_identify: Optional[str] = None) bool #
Delete post.
- Parameters:
post_rkey – ID (slug) of the post.
profile_identify – Handler or DID. Who created the post.
- Returns:
Success status.
- Return type:
bool
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- export_session_string() str #
Export session string.
Note
This method is useful for storing the session and reusing it later.
Warning
You should use it if you create the client instance often. Because of server rate limits for createSession. Rate limited by handle. 30/5 min, 300/day.
Example
>>> from atproto import Client >>> # the first time login with login and password >>> client = Client() >>> client.login('login', 'password') >>> session_string = client.export_session_string() >>> # store session_string somewhere. >>> # for example, in env and next time use it for login >>> client2 = Client() >>> client2.login(session_string=session_string)
- Returns:
Session string.
- Return type:
str
- get_current_time() datetime #
Get current time in Server Timezone (UTC).
- get_current_time_iso() str #
Get current time in Server Timezone (UTC) and ISO format.
- get_time_from_timestamp(timestamp: int) datetime #
Get datetime from timestamp in Server Timezone (UTC).
- invoke_procedure(nsid: str, params: Optional[ParamsModelBase] = None, data: Optional[Union[DataModelBase, bytes]] = None, **kwargs) Response #
- invoke_query(nsid: str, params: Optional[ParamsModelBase] = None, data: Optional[Union[DataModelBase, bytes]] = None, **kwargs) Response #
- like(subject: Main) Response #
Like the post.
- Parameters:
subject – Reference to the post that should be liked.
- Returns:
Reference to the created like record.
- Return type:
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- login(login: Optional[str] = None, password: Optional[str] = None, session_string: Optional[str] = None) ProfileViewDetailed #
Authorize a client and get profile info.
- Parameters:
login – Handle/username of the account.
password – Main or app-specific password of the account.
session_string – Session string (use
export_session_string
to obtain it).
Note
Either session_string or login and password should be provided.
- Returns:
Profile information.
- Return type:
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- me: t.Optional[models.AppBskyActorDefs.ProfileViewDetailed]#
- repost(subject: Main, profile_identify: Optional[str] = None) Response #
Repost post.
Note
If profile_identify is not provided will be sent to the current profile.
- Parameters:
subject – Reference to the post that should be reposted.
profile_identify – Handle or DID. Where to make repost.
- Returns:
Reference to the reposted post record.
- Return type:
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- send_image(text: str, image: bytes, image_alt: str, profile_identify: Optional[str] = None, reply_to: Optional[Union[ReplyRef, ReplyRef]] = None) Response #
Send post with attached image.
Note
If profile_identify is not provided will be sent to the current profile.
- Parameters:
text – Text of the post.
image – Binary image to attach.
image_alt – Text version of the image
profile_identify – Handle or DID. Where to send post.
reply_to – Root and parent of the post to reply to.
- Returns:
Reference to the created post record.
- Return type:
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- send_post(text: str, profile_identify: Optional[str] = None, reply_to: Optional[Union[ReplyRef, ReplyRef]] = None, embed: Optional[Union[Main, Main, Main, Main]] = None, langs: Optional[List[str]] = None) Response #
Send post.
Note
If profile_identify is not provided will be sent to the current profile.
The default language is
en
. Available languages are defined inatproto.xrpc_client.models.languages
.- Parameters:
text – Text of the post.
profile_identify – Handle or DID. Where to send post.
reply_to – Root and parent of the post to reply to.
embed – Embed models that should be attached to the post.
langs – List of used languages in the post.
- Returns:
Reference to the created post record.
- Return type:
- Raises:
atproto.exceptions.AtProtocolError – Base exception.
- unlike(record_key: str, profile_identify: Optional[str] = None) bool #
Unlike the post.
- Parameters:
record_key – ID (slog) of the post.
profile_identify – Handler or DID. Who did the like.
- Returns:
Success status.
- Return type:
bool
- Raises:
atproto.exceptions.AtProtocolError – Base exception.