atproto#

class atproto.AsyncClient(base_url: Optional[str] = None, *args, **kwargs)#

Bases: SessionMethodsMixin, TimeMethodsMixin, AsyncClientRaw

High-level client for XRPC of ATProto.

app: async_ns.AppNamespace#
com: async_ns.ComNamespace#
async 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.

async 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:

models.ComAtprotoRepoCreateRecord.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async 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:

models.AppBskyActorDefs.ProfileViewDetailed

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async 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:

models.ComAtprotoRepoCreateRecord.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async 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:

models.ComAtprotoRepoCreateRecord.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async 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 async default language is en. Available languages are async defined in atproto.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:

models.ComAtprotoRepoCreateRecord.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async 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.

class atproto.AtUri(host: str, pathname: str, hash_: str, search_params: List[Tuple[str, Any]])#

Bases: object

ATP URI Scheme.

Examples

Repository: at://alice.host.com

Repository: at://did:plc:bv6ggog3tya2z3vxsub7hnal

Collection: at://alice.host.com/io.example.song

Record: at://alice.host.com/io.example.song/3yI5-c1z-cc2p-1a

Record Field: at://alice.host.com/io.example.song/3yI5-c1z-cc2p-1a#/title

property collection: str#

Get collection name.

classmethod from_str(uri: str) AtUri#

Create AtUri instance from URI.

property hostname: str#

Get hostname.

property http: str#

Convert instance to HTTP URI.

property origin: str#

Get origin.

property protocol: str#

Get protocol.

property rkey: str#

Get record key (rkey).

class atproto.CAR(root: CID, blocks: Dict[CID, dict])#

Bases: object

CAR file.

property blocks: Dict[CID, dict]#

Get blocks.

classmethod from_bytes(data: bytes) CAR#

Decode CAR file.

Note

You could pass as data response of client.com.atproto.sync.get_repo, for example. And other responses of methods in the sync namespace.

Example

>>> from atproto import CAR, Client
>>> client = Client()
>>> client.login('my-handle', 'my-password')
>>> repo = client.com.atproto.sync.get_repo({'did': client.me.did})
>>> car_file = CAR.from_bytes(repo)
>>> print(car_file.root)
>>> print(car_file.blocks)
Parameters:

data – Content of the CAR file.

Returns:

Parsed CAR file.

Return type:

atproto.CAR

property root: CID#

Get root.

class atproto.CID(_cid: str, version: int, codec: int, hash: atproto.cid.Multihash)#

Bases: object

codec: int#
classmethod decode(value: str) CID#
encode() str#
hash: Multihash#
version: int#
class atproto.Client(base_url: Optional[str] = None, *args, **kwargs)#

Bases: SessionMethodsMixin, TimeMethodsMixin, ClientRaw

High-level client for XRPC of ATProto.

app: sync_ns.AppNamespace#
com: sync_ns.ComNamespace#
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.

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:

models.ComAtprotoRepoCreateRecord.Response

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:

models.AppBskyActorDefs.ProfileViewDetailed

Raises:

atproto.exceptions.AtProtocolError – Base exception.

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:

models.ComAtprotoRepoCreateRecord.Response

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:

models.ComAtprotoRepoCreateRecord.Response

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 in atproto.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:

models.ComAtprotoRepoCreateRecord.Response

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.

class atproto.NSID(segments: ~typing.List[str] = <factory>)#

Bases: object

NameSpaced IDs (NSIDs).

Examples

com.example.status

io.social.getFeed

net.users.bob.ping

property authority: str#

Get authority of NSID.

com.example.thing ^^^^^^^^^^^——–> example.com

delim joined self.segments[:-1][::-1]

classmethod from_str(nsid: str) NSID#

Create NSID instance from string.

property name: str#

Get name.

segments: List[str]#

Subpackages#

Submodules#