Spaces

Client for Spaces, the permissioned data of the AT Protocol: records with an access perimeter, such as bookmarks, drafts, private posts and group forums. This package requests and renews space credentials, sends each request to the server that holds the data, and verifies what comes back.

Warning

Spaces are in beta. The classes, the methods and the lexicons behind them can still change with the protocol.

SpaceClient / AsyncSpaceClient

A space as one account sees it. Reads the space and writes the repo of the account in it.

SpaceReader / AsyncSpaceReader

A space read with space credentials only, for a service that keeps its own copy of spaces.

SpaceManager / AsyncSpaceManager

The policy, the writers and the members of a space, for its authority.

SpaceType

A space type as its lexicon declares it: the type of the key and the record collections.

Tip

For how to use these, covering scopes, records, blobs, managing a space and syncing one, see the Spaces guide.

class atproto_space.AsyncSpaceClient(client: AsyncClient, space: str | SpaceRef, space_type: SpaceType | None = None, *, client_attestation_provider: Callable[[str], str | Awaitable[str]] | None = None, notify_registration_provider: Callable[[SpaceRef], models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None | Awaitable[models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None]] | None = None, id_resolver: AsyncIdResolver | None = None, request: AsyncRequest | None = None)

Client of a space that acts for an account. It reads the space and writes the repo of the account in it.

A request for the repo of the account goes to the PDS of the account with the session of the client: every write, and every read that is given no repo or the DID of the account. Any other read goes where AsyncSpaceReader sends it, with a space credential that the client requests with a delegation token of the PDS of the account.

Note

The client asks the PDS of the account for no MAC on the repo of the account. Of the repo of the account, a record is taken as the PDS sent it, and a commit is checked for its form only.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • client – Client that is logged in as the account.

  • space – URI of the space or a reference to it.

  • space_type – Type of the space. The space must be of this type, and the records of other collections than the ones it declares are flagged as invalid.

  • client_attestation_provider – Returns a client attestation for the given audience. For spaces that admit certain applications only. May be a coroutine function.

  • notify_registration_provider – Returns the endpoint that the host of the space notifies of updates. It is registered with every credential. May be a coroutine function.

  • id_resolver – Identity resolver. One that caches DID documents in memory by default.

  • request – HTTP client of the requests that carry the space credential. It must carry no session of an account, so the one of a client is refused.

async all_records() → AsyncIterator[SpaceRecord]

Iterate over the records of every repo in the space, each flagged with whether it is valid.

Each repo is read in full and verified before its records are yielded. The repos that were removed from the space are left out, and so are the ones that are not found, taken down, suspended or deactivated. Up to four repos are read at a time.

Yields:

SpaceRecord – Record of the space.

Raises:
async apply_writes(writes: Sequence[WriteOperation], validate: bool | None = None) → models.ComAtprotoSpaceApplyWrites.Response

Apply a batch of writes to the repo of the account in the space. All of them are applied, or none.

Parameters:
Returns:

Results of the operations, in their order.

Return type:

models.ComAtprotoSpaceApplyWrites.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async authorize(renew: bool = False) → SpaceCredential

Get the space credential, requesting it from the host of the space when needed.

The first read requests the credential on its own. Call this method to learn early whether the space grants access.

Parameters:

renew – Request a new credential even when the current one is still good.

Returns:

Space credential.

Return type:

SpaceCredential

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async clear_records() → bool

Delete every record of the repo of the account in the space.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property client: AsyncClient

Client of the account.

async create_record(record: UnknownInputType, rkey: str | None = None, validate: bool | None = None) → models.ComAtprotoSpaceCreateRecord.Response

Create a record in the repo of the account in the space.

Parameters:
  • record – Record model, or a dict with $type. The type is the collection of the record.

  • rkey – Record key. One that the PDS generates by default.

  • validate – True requires the PDS to validate the record against its lexicon and False skips the validation. By default the PDS validates the records of the lexicons that it knows.

Returns:

Reference to the created record.

Return type:

models.ComAtprotoSpaceCreateRecord.Response

Raises:
async classmethod create_space(client: AsyncClient, space_type: SpaceType | str, policy: SpacePolicy, skey: str | None = None, **kwargs: Unpack[_AsyncClientOptions]) → Self

Create a space that the account is the authority of, and open it.

Parameters:
  • client – Client that is logged in as the account.

  • space_type – Type of the space, or its NSID.

  • policy – Policy that governs the space.

  • skey – Key of the space. The key of a type with a literal key by default, otherwise one that the PDS generates.

  • **kwargs – Other arguments of the client.

Returns:

Client of the new space.

Return type:

AsyncSpaceClient

Raises:
async delete_record(collection: str, rkey: str) → bool

Delete a record from the repo of the account in the space, or ensure it doesn’t exist.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property did: str

DID of the account that the client acts for.

async get_blob(blob: BlobReference, repo: str | None = None) → bytes

Get a blob of a repo in the space, verified against its CID.

Parameters:
  • blob – CID of the blob, or a reference to it as a record holds it, with a model or without one.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Content of the blob.

Return type:

bytes

Raises:
async get_latest_commit(repo: str | None = None) → models.ComAtprotoSpaceDefs.Commit

Get the current commit of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Commit of the repo.

Return type:

models.ComAtprotoSpaceDefs.Commit

Raises:
async get_record(collection: str, rkey: str, repo: str | None = None) → models.ComAtprotoSpaceGetRecord.Response

Get a record of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, and takes the record as its PDS sent it.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Record.

Return type:

models.ComAtprotoSpaceGetRecord.Response

Raises:
async get_repo(repo: str | None = None) → RepoSnapshot

Get a repo of the space in full, verified against the MAC of its host and against its commit.

Note

The whole repo is read into memory. A client gets no MAC for the repo of its account, so the records are verified against the commit only.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Records of the repo, and the state to sync the repo from later.

Return type:

RepoSnapshot

Raises:
async list_blobs(repo: str | None = None, limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListBlobs.Response

List the CIDs of the blobs that the records of a repo in the space refer to.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • limit – Maximum number of blobs to list.

  • cursor – Cursor of the page.

Returns:

Page of CIDs.

Return type:

models.ComAtprotoSpaceListBlobs.Response

Raises:
async list_records(repo: str | None = None, collection: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRecords.Response

List the records of a repo in the space.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

  • limit – Maximum number of records to list.

  • cursor – Cursor of the page.

  • exclude_values – List the records without their values.

Returns:

Page of records.

Return type:

models.ComAtprotoSpaceListRecords.Response

Raises:
async list_repo_ops(repo: str | None = None, since: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRepoOps.Response

List the operation log of a repo in the space, with the current commit of the repo.

The commit is verified against the MAC of its host.

Note

The operations are not verified. sync_repo() applies them to a known state of the repo. A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • since – Revision of the repo to list the operations after.

  • limit – Maximum number of operations to list.

  • cursor – Cursor of the page.

  • exclude_values – List the operations without the values of the records.

Returns:

Page of operations.

Return type:

models.ComAtprotoSpaceListRepoOps.Response

Raises:
async list_writers(limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListWriters.Response

List the accounts that hold a repo in the space, as the host of the space knows them.

Parameters:
  • limit – Maximum number of repos to list.

  • cursor – Revision of the space to list the repos updated after.

Returns:

Latest update of each repo, in the order of the revisions of the space.

Return type:

models.ComAtprotoSpaceListWriters.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async pull_repo(head: RepoHead | None = None, lookup: Callable[[str, str], str | None | Awaitable[str | None]] | None = None, repo: str | None = None) → RepoChanges | RepoSnapshot | None

Bring a repo in the space up to date.

The repo is synced from its known state. It is read in full when there is no known state, for example on the first pull, or when the operation log does not continue the known state.

Parameters:
  • head – Known state of the repo, if any. The head that the repo was pulled with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. Required with the known state. May be a coroutine function.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state, RepoSnapshot when the repo was read in full and its records replace every known one, or None when the host has no such repo, so every known record of it is gone.

Return type:

RepoChanges

Raises:
async put_record(record: UnknownInputType, rkey: str, validate: bool | None = None) → models.ComAtprotoSpacePutRecord.Response

Create or replace a record in the repo of the account in the space.

Parameters:
  • record – Record model, or a dict with $type. The type is the collection of the record.

  • rkey – Record key.

  • validate – True requires the PDS to validate the record against its lexicon and False skips the validation. By default the PDS validates the records of the lexicons that it knows.

Returns:

Reference to the record.

Return type:

models.ComAtprotoSpacePutRecord.Response

Raises:
async records(repo: str | None = None, collection: str | None = None) → AsyncIterator[SpaceRecord]

Iterate over the records of a repo in the space, each flagged with whether it is valid.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

Yields:

SpaceRecord – Record of the repo.

Raises:
property ref: SpaceRef

Reference to the space.

property request: AsyncRequest

HTTP client of the reader.

property space_type: SpaceType | None

Type of the space, when the reader was given one.

async sync_repo(head: RepoHead, lookup: Callable[[str, str], str | None | Awaitable[str | None]], repo: str | None = None) → RepoChanges

Bring a known state of a repo in the space up to date from the operation log of the repo.

Every operation is checked against the known state, and the resulting state against the commit of the repo, which is verified against the MAC of its host.

Parameters:
  • head – Known state of the repo. The head that the repo was read or synced with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. May be a coroutine function.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state.

Return type:

RepoChanges

Raises:
property uri: str

URI of the space.

async writers(cursor: str | None = None) → AsyncIterator[Writer]

Iterate over the accounts that hold a repo in the space, in the order of their latest update.

A repo that was removed from the space is listed as RepoRemoved. A repo that is updated during the iteration can be listed again, and its last entry is the current one.

Note

The highest space_rev listed so far is the cursor to list the repos updated since. The host of a space may forget a removal after 72 hours, so with an older cursor list every repo and drop the ones that are not listed.

Parameters:

cursor – Revision of the space to list the repos updated after.

Yields:

models.ComAtprotoSpaceDefs.RepoWrite or models.ComAtprotoSpaceDefs.RepoRemoved – Latest update of a repo. Entries of an unknown kind are left out.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

class atproto_space.AsyncSpaceManager(client: AsyncClient, space: str | SpaceRef)

Manager of a space that acts for its authority: the policy of the space, its writers and its members.

Only the authority of a space manages it, so the client must be logged in as the account that the URI of the space names.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • client – Client that is logged in as the authority of the space.

  • space – URI of the space or a reference to it.

property client: AsyncClient

Client of the authority of the space.

async delete_space() → bool

Delete the space, along with the repo of its authority in it. The repos of other accounts are left.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async get_space() → Response

Get the space with the policy that governs it.

Returns:

Space and its policy.

Return type:

models.ComAtprotoSpaceGetSpace.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async list_members(limit: int | None = None, cursor: str | None = None) → Response

List the members of the space. For a space that a member list governs.

Parameters:
  • limit – Maximum number of members to list.

  • cursor – Cursor of the page.

Returns:

Page of members.

Return type:

models.ComAtprotoMemberspaceListMembers.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async members() → AsyncIterator[Member]

Iterate over the members of the space. For a space that a member list governs.

Yields:

models.ComAtprotoMemberspaceDefs.Member – Member with its access to the space.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async put_members(members: Sequence[Member]) → bool

Add members to the space, or replace the access of the ones it has. For a space that a member list governs.

Parameters:

members – Members with their access to the space, 100 at most. The last entry of an account counts.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property ref: SpaceRef

Reference to the space.

async remove_members(dids: Sequence[str]) → bool

Remove members from the space. For a space that a member list governs.

Parameters:

dids – DIDs of the members, 100 at most. The ones of other accounts are ignored.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async remove_writer(repo: str) → bool

Remove the repo of an account from the writer set of the space.

Note

The repo is added back when the account writes to the space again and the policy lets it.

Parameters:

repo – DID of the account that the repo belongs to.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async update_space(policy: SpacePolicy) → bool

Replace the policy of the space as a whole.

Note

A policy of another type discards the state of the previous one, such as a member list.

Parameters:

policy – Policy to govern the space.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property uri: str

URI of the space.

class atproto_space.AsyncSpaceReader(space: str | SpaceRef, space_type: SpaceType | None = None, *, delegation_token_provider: Callable[[SpaceRef], str | None | Awaitable[str | None]] | None = None, client_attestation_provider: Callable[[str], str | Awaitable[str]] | None = None, notify_registration_provider: Callable[[SpaceRef], models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None | Awaitable[models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None]] | None = None, id_resolver: AsyncIdResolver | None = None, request: AsyncRequest | None = None)

Reader of a space that acts for no account. For services that sync spaces.

A request goes to the PDS of the account whose repo it reads, or to the host of the space when it reads no repo. It is authorized with a space credential, which the reader requests from the host of the space on the first read and renews on its own.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • space – URI of the space or a reference to it.

  • space_type – Type of the space. The space must be of this type, and the records of other collections than the ones it declares are flagged as invalid.

  • delegation_token_provider – Returns the delegation token of an account that reads the space, to exchange for a space credential. Only a space that anyone can read needs none. May be a coroutine function.

  • client_attestation_provider – Returns a client attestation for the given audience. For spaces that admit certain applications only. May be a coroutine function.

  • notify_registration_provider – Returns the endpoint that the host of the space notifies of updates. It is registered with every credential. May be a coroutine function.

  • id_resolver – Identity resolver. One that caches DID documents in memory by default. Readers can share it.

  • request – HTTP client of the reader. Readers can share it. It must carry no session of an account, so the one of a client is refused.

async all_records() → AsyncIterator[SpaceRecord]

Iterate over the records of every repo in the space, each flagged with whether it is valid.

Each repo is read in full and verified before its records are yielded. The repos that were removed from the space are left out, and so are the ones that are not found, taken down, suspended or deactivated. Up to four repos are read at a time.

Yields:

SpaceRecord – Record of the space.

Raises:
async authorize(renew: bool = False) → SpaceCredential

Get the space credential, requesting it from the host of the space when needed.

The first read requests the credential on its own. Call this method to learn early whether the space grants access.

Parameters:

renew – Request a new credential even when the current one is still good.

Returns:

Space credential.

Return type:

SpaceCredential

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async get_blob(blob: BlobReference, repo: str | None = None) → bytes

Get a blob of a repo in the space, verified against its CID.

Parameters:
  • blob – CID of the blob, or a reference to it as a record holds it, with a model or without one.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Content of the blob.

Return type:

bytes

Raises:
async get_latest_commit(repo: str | None = None) → models.ComAtprotoSpaceDefs.Commit

Get the current commit of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Commit of the repo.

Return type:

models.ComAtprotoSpaceDefs.Commit

Raises:
async get_record(collection: str, rkey: str, repo: str | None = None) → models.ComAtprotoSpaceGetRecord.Response

Get a record of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, and takes the record as its PDS sent it.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Record.

Return type:

models.ComAtprotoSpaceGetRecord.Response

Raises:
async get_repo(repo: str | None = None) → RepoSnapshot

Get a repo of the space in full, verified against the MAC of its host and against its commit.

Note

The whole repo is read into memory. A client gets no MAC for the repo of its account, so the records are verified against the commit only.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Records of the repo, and the state to sync the repo from later.

Return type:

RepoSnapshot

Raises:
async list_blobs(repo: str | None = None, limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListBlobs.Response

List the CIDs of the blobs that the records of a repo in the space refer to.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • limit – Maximum number of blobs to list.

  • cursor – Cursor of the page.

Returns:

Page of CIDs.

Return type:

models.ComAtprotoSpaceListBlobs.Response

Raises:
async list_records(repo: str | None = None, collection: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRecords.Response

List the records of a repo in the space.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

  • limit – Maximum number of records to list.

  • cursor – Cursor of the page.

  • exclude_values – List the records without their values.

Returns:

Page of records.

Return type:

models.ComAtprotoSpaceListRecords.Response

Raises:
async list_repo_ops(repo: str | None = None, since: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRepoOps.Response

List the operation log of a repo in the space, with the current commit of the repo.

The commit is verified against the MAC of its host.

Note

The operations are not verified. sync_repo() applies them to a known state of the repo. A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • since – Revision of the repo to list the operations after.

  • limit – Maximum number of operations to list.

  • cursor – Cursor of the page.

  • exclude_values – List the operations without the values of the records.

Returns:

Page of operations.

Return type:

models.ComAtprotoSpaceListRepoOps.Response

Raises:
async list_writers(limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListWriters.Response

List the accounts that hold a repo in the space, as the host of the space knows them.

Parameters:
  • limit – Maximum number of repos to list.

  • cursor – Revision of the space to list the repos updated after.

Returns:

Latest update of each repo, in the order of the revisions of the space.

Return type:

models.ComAtprotoSpaceListWriters.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

async pull_repo(head: RepoHead | None = None, lookup: Callable[[str, str], str | None | Awaitable[str | None]] | None = None, repo: str | None = None) → RepoChanges | RepoSnapshot | None

Bring a repo in the space up to date.

The repo is synced from its known state. It is read in full when there is no known state, for example on the first pull, or when the operation log does not continue the known state.

Parameters:
  • head – Known state of the repo, if any. The head that the repo was pulled with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. Required with the known state. May be a coroutine function.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state, RepoSnapshot when the repo was read in full and its records replace every known one, or None when the host has no such repo, so every known record of it is gone.

Return type:

RepoChanges

Raises:
async records(repo: str | None = None, collection: str | None = None) → AsyncIterator[SpaceRecord]

Iterate over the records of a repo in the space, each flagged with whether it is valid.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

Yields:

SpaceRecord – Record of the repo.

Raises:
property ref: SpaceRef

Reference to the space.

property request: AsyncRequest

HTTP client of the reader.

property space_type: SpaceType | None

Type of the space, when the reader was given one.

async sync_repo(head: RepoHead, lookup: Callable[[str, str], str | None | Awaitable[str | None]], repo: str | None = None) → RepoChanges

Bring a known state of a repo in the space up to date from the operation log of the repo.

Every operation is checked against the known state, and the resulting state against the commit of the repo, which is verified against the MAC of its host.

Parameters:
  • head – Known state of the repo. The head that the repo was read or synced with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. May be a coroutine function.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state.

Return type:

RepoChanges

Raises:
property uri: str

URI of the space.

async writers(cursor: str | None = None) → AsyncIterator[Writer]

Iterate over the accounts that hold a repo in the space, in the order of their latest update.

A repo that was removed from the space is listed as RepoRemoved. A repo that is updated during the iteration can be listed again, and its last entry is the current one.

Note

The highest space_rev listed so far is the cursor to list the repos updated since. The host of a space may forget a removal after 72 hours, so with an older cursor list every repo and drop the ones that are not listed.

Parameters:

cursor – Revision of the space to list the repos updated after.

Yields:

models.ComAtprotoSpaceDefs.RepoWrite or models.ComAtprotoSpaceDefs.RepoRemoved – Latest update of a repo. Entries of an unknown kind are left out.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

class atproto_space.RecordChange(collection: str, rkey: str, cid: str | None, prev: str | None, value: Dict[str, Any] | None = None)

Change of a record of a repo in a space since a known state.

collection

NSID of the record collection.

Type:

str

rkey

Record key.

Type:

str

cid

CID of the record after the change. None when the record was deleted.

Type:

str | None

prev

CID of the record before the change. None when the record was created.

Type:

str | None

value

Record as decoded from DAG-CBOR, unless it was deleted. A link is a atproto_core.cid.CID.

Type:

Dict[str, Any] | None

class atproto_space.RepoChanges(commit: models.ComAtprotoSpaceDefs.Commit, head: RepoHead, changes: List[RecordChange])

Changes of a repo of a space since a known state, verified against its commit.

commit

Commit of the repo.

Type:

models.ComAtprotoSpaceDefs.Commit

head

State to sync the repo from later.

Type:

atproto_space.models.RepoHead

changes

Changes since the known state, one for each record that changed.

Type:

List[atproto_space.models.RecordChange]

class atproto_space.RepoHead(rev: str, state: bytes)

State of a repo in a space as a syncer knows it. The state to sync the repo from later.

rev

Revision of the commit that the state matches.

Type:

str

state

State of the set hash of the records. See atproto_space.commit.RepoCommit.

Type:

bytes

class atproto_space.RepoRecord(collection: str, rkey: str, cid: str, value: Dict[str, Any])

Record of a repo in a space.

collection

NSID of the record collection.

Type:

str

rkey

Record key.

Type:

str

cid

CID of the record.

Type:

str

value

Record as decoded from DAG-CBOR. A link is a atproto_core.cid.CID.

Type:

Dict[str, Any]

class atproto_space.RepoSnapshot(commit: models.ComAtprotoSpaceDefs.Commit, head: RepoHead, records: List[RepoRecord])

Repo of a space in full, verified against its commit.

commit

Commit of the repo.

Type:

models.ComAtprotoSpaceDefs.Commit

head

State to sync the repo from later.

Type:

atproto_space.models.RepoHead

records

Records of the repo in the order of their paths.

Type:

List[atproto_space.models.RepoRecord]

class atproto_space.SpaceClient(client: Client, space: str | SpaceRef, space_type: SpaceType | None = None, *, client_attestation_provider: Callable[[str], str] | None = None, notify_registration_provider: Callable[[SpaceRef], models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None] | None = None, id_resolver: IdResolver | None = None, request: Request | None = None)

Client of a space that acts for an account. It reads the space and writes the repo of the account in it.

A request for the repo of the account goes to the PDS of the account with the session of the client: every write, and every read that is given no repo or the DID of the account. Any other read goes where SpaceReader sends it, with a space credential that the client requests with a delegation token of the PDS of the account.

Note

The client asks the PDS of the account for no MAC on the repo of the account. Of the repo of the account, a record is taken as the PDS sent it, and a commit is checked for its form only.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • client – Client that is logged in as the account.

  • space – URI of the space or a reference to it.

  • space_type – Type of the space. The space must be of this type, and the records of other collections than the ones it declares are flagged as invalid.

  • client_attestation_provider – Returns a client attestation for the given audience. For spaces that admit certain applications only.

  • notify_registration_provider – Returns the endpoint that the host of the space notifies of updates. It is registered with every credential.

  • id_resolver – Identity resolver. One that caches DID documents in memory by default.

  • request – HTTP client of the requests that carry the space credential. It must carry no session of an account, so the one of a client is refused.

all_records() → Iterator[SpaceRecord]

Iterate over the records of every repo in the space, each flagged with whether it is valid.

Each repo is read in full and verified before its records are yielded. The repos that were removed from the space are left out, and so are the ones that are not found, taken down, suspended or deactivated.

Yields:

SpaceRecord – Record of the space.

Raises:
apply_writes(writes: Sequence[WriteOperation], validate: bool | None = None) → models.ComAtprotoSpaceApplyWrites.Response

Apply a batch of writes to the repo of the account in the space. All of them are applied, or none.

Parameters:
Returns:

Results of the operations, in their order.

Return type:

models.ComAtprotoSpaceApplyWrites.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

authorize(renew: bool = False) → SpaceCredential

Get the space credential, requesting it from the host of the space when needed.

The first read requests the credential on its own. Call this method to learn early whether the space grants access.

Parameters:

renew – Request a new credential even when the current one is still good.

Returns:

Space credential.

Return type:

SpaceCredential

Raises:

atproto.exceptions.AtProtocolError – Base exception.

clear_records() → bool

Delete every record of the repo of the account in the space.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property client: Client

Client of the account.

create_record(record: UnknownInputType, rkey: str | None = None, validate: bool | None = None) → models.ComAtprotoSpaceCreateRecord.Response

Create a record in the repo of the account in the space.

Parameters:
  • record – Record model, or a dict with $type. The type is the collection of the record.

  • rkey – Record key. One that the PDS generates by default.

  • validate – True requires the PDS to validate the record against its lexicon and False skips the validation. By default the PDS validates the records of the lexicons that it knows.

Returns:

Reference to the created record.

Return type:

models.ComAtprotoSpaceCreateRecord.Response

Raises:
classmethod create_space(client: Client, space_type: SpaceType | str, policy: SpacePolicy, skey: str | None = None, **kwargs: Unpack[_ClientOptions]) → Self

Create a space that the account is the authority of, and open it.

Parameters:
  • client – Client that is logged in as the account.

  • space_type – Type of the space, or its NSID.

  • policy – Policy that governs the space.

  • skey – Key of the space. The key of a type with a literal key by default, otherwise one that the PDS generates.

  • **kwargs – Other arguments of the client.

Returns:

Client of the new space.

Return type:

SpaceClient

Raises:
delete_record(collection: str, rkey: str) → bool

Delete a record from the repo of the account in the space, or ensure it doesn’t exist.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property did: str

DID of the account that the client acts for.

get_blob(blob: BlobReference, repo: str | None = None) → bytes

Get a blob of a repo in the space, verified against its CID.

Parameters:
  • blob – CID of the blob, or a reference to it as a record holds it, with a model or without one.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Content of the blob.

Return type:

bytes

Raises:
get_latest_commit(repo: str | None = None) → models.ComAtprotoSpaceDefs.Commit

Get the current commit of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Commit of the repo.

Return type:

models.ComAtprotoSpaceDefs.Commit

Raises:
get_record(collection: str, rkey: str, repo: str | None = None) → models.ComAtprotoSpaceGetRecord.Response

Get a record of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, and takes the record as its PDS sent it.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Record.

Return type:

models.ComAtprotoSpaceGetRecord.Response

Raises:
get_repo(repo: str | None = None) → RepoSnapshot

Get a repo of the space in full, verified against the MAC of its host and against its commit.

Note

The whole repo is read into memory. A client gets no MAC for the repo of its account, so the records are verified against the commit only.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Records of the repo, and the state to sync the repo from later.

Return type:

RepoSnapshot

Raises:
list_blobs(repo: str | None = None, limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListBlobs.Response

List the CIDs of the blobs that the records of a repo in the space refer to.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • limit – Maximum number of blobs to list.

  • cursor – Cursor of the page.

Returns:

Page of CIDs.

Return type:

models.ComAtprotoSpaceListBlobs.Response

Raises:
list_records(repo: str | None = None, collection: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRecords.Response

List the records of a repo in the space.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

  • limit – Maximum number of records to list.

  • cursor – Cursor of the page.

  • exclude_values – List the records without their values.

Returns:

Page of records.

Return type:

models.ComAtprotoSpaceListRecords.Response

Raises:
list_repo_ops(repo: str | None = None, since: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRepoOps.Response

List the operation log of a repo in the space, with the current commit of the repo.

The commit is verified against the MAC of its host.

Note

The operations are not verified. sync_repo() applies them to a known state of the repo. A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • since – Revision of the repo to list the operations after.

  • limit – Maximum number of operations to list.

  • cursor – Cursor of the page.

  • exclude_values – List the operations without the values of the records.

Returns:

Page of operations.

Return type:

models.ComAtprotoSpaceListRepoOps.Response

Raises:
list_writers(limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListWriters.Response

List the accounts that hold a repo in the space, as the host of the space knows them.

Parameters:
  • limit – Maximum number of repos to list.

  • cursor – Revision of the space to list the repos updated after.

Returns:

Latest update of each repo, in the order of the revisions of the space.

Return type:

models.ComAtprotoSpaceListWriters.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

pull_repo(head: RepoHead | None = None, lookup: Callable[[str, str], str | None] | None = None, repo: str | None = None) → RepoChanges | RepoSnapshot | None

Bring a repo in the space up to date.

The repo is synced from its known state. It is read in full when there is no known state, for example on the first pull, or when the operation log does not continue the known state.

Parameters:
  • head – Known state of the repo, if any. The head that the repo was pulled with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. Required with the known state.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state, RepoSnapshot when the repo was read in full and its records replace every known one, or None when the host has no such repo, so every known record of it is gone.

Return type:

RepoChanges

Raises:
put_record(record: UnknownInputType, rkey: str, validate: bool | None = None) → models.ComAtprotoSpacePutRecord.Response

Create or replace a record in the repo of the account in the space.

Parameters:
  • record – Record model, or a dict with $type. The type is the collection of the record.

  • rkey – Record key.

  • validate – True requires the PDS to validate the record against its lexicon and False skips the validation. By default the PDS validates the records of the lexicons that it knows.

Returns:

Reference to the record.

Return type:

models.ComAtprotoSpacePutRecord.Response

Raises:
records(repo: str | None = None, collection: str | None = None) → Iterator[SpaceRecord]

Iterate over the records of a repo in the space, each flagged with whether it is valid.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

Yields:

SpaceRecord – Record of the repo.

Raises:
property ref: SpaceRef

Reference to the space.

property request: Request

HTTP client of the reader.

property space_type: SpaceType | None

Type of the space, when the reader was given one.

sync_repo(head: RepoHead, lookup: Callable[[str, str], str | None], repo: str | None = None) → RepoChanges

Bring a known state of a repo in the space up to date from the operation log of the repo.

Every operation is checked against the known state, and the resulting state against the commit of the repo, which is verified against the MAC of its host.

Parameters:
  • head – Known state of the repo. The head that the repo was read or synced with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state.

Return type:

RepoChanges

Raises:
property uri: str

URI of the space.

writers(cursor: str | None = None) → Iterator[Writer]

Iterate over the accounts that hold a repo in the space, in the order of their latest update.

A repo that was removed from the space is listed as RepoRemoved. A repo that is updated during the iteration can be listed again, and its last entry is the current one.

Note

The highest space_rev listed so far is the cursor to list the repos updated since. The host of a space may forget a removal after 72 hours, so with an older cursor list every repo and drop the ones that are not listed.

Parameters:

cursor – Revision of the space to list the repos updated after.

Yields:

models.ComAtprotoSpaceDefs.RepoWrite or models.ComAtprotoSpaceDefs.RepoRemoved – Latest update of a repo. Entries of an unknown kind are left out.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

class atproto_space.SpaceCredential(token: str, private_key: EllipticCurvePrivateKey, renew_at: float, space_rev: str | None = None)

Space credential together with the key it is bound to.

Parameters:
  • token – Space credential.

  • private_key – P-256 private key that the credential is bound to.

  • renew_at – Unix timestamp after which the credential should be renewed.

  • space_rev – Revision of the space when the credential was issued.

headers(audience: str) → Dict[str, str]

Get the headers that present the credential to a host.

Parameters:

audience – DID of the repo for the methods of a repo, DID of the space authority for the methods of a space.

Returns:

Authorization, audience and signature headers. They are created once per audience.

Return type:

dict

property needs_renewal: bool

Tell whether the credential should be renewed.

classmethod parse(token: str, private_key: EllipticCurvePrivateKey, space_rev: str | None = None) → SpaceCredential

Parse a space credential that was requested for the given key.

Note

The signature of the credential is not verified. The hosts of the repos verify it.

Parameters:
  • token – Space credential.

  • private_key – P-256 private key that the credential was requested for.

  • space_rev – Revision of the space when the credential was issued.

Returns:

Space credential.

Return type:

SpaceCredential

Raises:

atproto_space.exceptions.SpaceTokenError – The token is not a space credential bound to the key.

property renew_at: float

Unix timestamp after which the credential should be renewed.

property space_rev: str | None

Revision of the space when the credential was issued, if the space had any update.

A reader that last saw an earlier revision has missed updates of the space.

property token: str

Space credential.

class atproto_space.SpaceManager(client: Client, space: str | SpaceRef)

Manager of a space that acts for its authority: the policy of the space, its writers and its members.

Only the authority of a space manages it, so the client must be logged in as the account that the URI of the space names.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • client – Client that is logged in as the authority of the space.

  • space – URI of the space or a reference to it.

property client: Client

Client of the authority of the space.

delete_space() → bool

Delete the space, along with the repo of its authority in it. The repos of other accounts are left.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

get_space() → Response

Get the space with the policy that governs it.

Returns:

Space and its policy.

Return type:

models.ComAtprotoSpaceGetSpace.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

list_members(limit: int | None = None, cursor: str | None = None) → Response

List the members of the space. For a space that a member list governs.

Parameters:
  • limit – Maximum number of members to list.

  • cursor – Cursor of the page.

Returns:

Page of members.

Return type:

models.ComAtprotoMemberspaceListMembers.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

members() → Iterator[Member]

Iterate over the members of the space. For a space that a member list governs.

Yields:

models.ComAtprotoMemberspaceDefs.Member – Member with its access to the space.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

put_members(members: Sequence[Member]) → bool

Add members to the space, or replace the access of the ones it has. For a space that a member list governs.

Parameters:

members – Members with their access to the space, 100 at most. The last entry of an account counts.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property ref: SpaceRef

Reference to the space.

remove_members(dids: Sequence[str]) → bool

Remove members from the space. For a space that a member list governs.

Parameters:

dids – DIDs of the members, 100 at most. The ones of other accounts are ignored.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

remove_writer(repo: str) → bool

Remove the repo of an account from the writer set of the space.

Note

The repo is added back when the account writes to the space again and the policy lets it.

Parameters:

repo – DID of the account that the repo belongs to.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

update_space(policy: SpacePolicy) → bool

Replace the policy of the space as a whole.

Note

A policy of another type discards the state of the previous one, such as a member list.

Parameters:

policy – Policy to govern the space.

Returns:

Success status.

Return type:

bool

Raises:

atproto.exceptions.AtProtocolError – Base exception.

property uri: str

URI of the space.

class atproto_space.SpaceReader(space: str | SpaceRef, space_type: SpaceType | None = None, *, delegation_token_provider: Callable[[SpaceRef], str | None] | None = None, client_attestation_provider: Callable[[str], str] | None = None, notify_registration_provider: Callable[[SpaceRef], models.ComAtprotoSpaceAuthorizeSpaceSync.Notify | None] | None = None, id_resolver: IdResolver | None = None, request: Request | None = None)

Reader of a space that acts for no account. For services that sync spaces.

A request goes to the PDS of the account whose repo it reads, or to the host of the space when it reads no repo. It is authorized with a space credential, which the reader requests from the host of the space on the first read and renews on its own.

Warning

Spaces are in beta. The methods can change together with the protocol.

Parameters:
  • space – URI of the space or a reference to it.

  • space_type – Type of the space. The space must be of this type, and the records of other collections than the ones it declares are flagged as invalid.

  • delegation_token_provider – Returns the delegation token of an account that reads the space, to exchange for a space credential. Only a space that anyone can read needs none.

  • client_attestation_provider – Returns a client attestation for the given audience. For spaces that admit certain applications only.

  • notify_registration_provider – Returns the endpoint that the host of the space notifies of updates. It is registered with every credential.

  • id_resolver – Identity resolver. One that caches DID documents in memory by default. Readers can share it.

  • request – HTTP client of the reader. Readers can share it. It must carry no session of an account, so the one of a client is refused.

all_records() → Iterator[SpaceRecord]

Iterate over the records of every repo in the space, each flagged with whether it is valid.

Each repo is read in full and verified before its records are yielded. The repos that were removed from the space are left out, and so are the ones that are not found, taken down, suspended or deactivated.

Yields:

SpaceRecord – Record of the space.

Raises:
authorize(renew: bool = False) → SpaceCredential

Get the space credential, requesting it from the host of the space when needed.

The first read requests the credential on its own. Call this method to learn early whether the space grants access.

Parameters:

renew – Request a new credential even when the current one is still good.

Returns:

Space credential.

Return type:

SpaceCredential

Raises:

atproto.exceptions.AtProtocolError – Base exception.

get_blob(blob: BlobReference, repo: str | None = None) → bytes

Get a blob of a repo in the space, verified against its CID.

Parameters:
  • blob – CID of the blob, or a reference to it as a record holds it, with a model or without one.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Content of the blob.

Return type:

bytes

Raises:
get_latest_commit(repo: str | None = None) → models.ComAtprotoSpaceDefs.Commit

Get the current commit of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Commit of the repo.

Return type:

models.ComAtprotoSpaceDefs.Commit

Raises:
get_record(collection: str, rkey: str, repo: str | None = None) → models.ComAtprotoSpaceGetRecord.Response

Get a record of a repo in the space, verified against the MAC of its host.

Note

A client gets no MAC for the repo of its account, and takes the record as its PDS sent it.

Parameters:
  • collection – NSID of the record collection.

  • rkey – Record key.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Record.

Return type:

models.ComAtprotoSpaceGetRecord.Response

Raises:
get_repo(repo: str | None = None) → RepoSnapshot

Get a repo of the space in full, verified against the MAC of its host and against its commit.

Note

The whole repo is read into memory. A client gets no MAC for the repo of its account, so the records are verified against the commit only.

Parameters:

repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Records of the repo, and the state to sync the repo from later.

Return type:

RepoSnapshot

Raises:
list_blobs(repo: str | None = None, limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListBlobs.Response

List the CIDs of the blobs that the records of a repo in the space refer to.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • limit – Maximum number of blobs to list.

  • cursor – Cursor of the page.

Returns:

Page of CIDs.

Return type:

models.ComAtprotoSpaceListBlobs.Response

Raises:
list_records(repo: str | None = None, collection: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRecords.Response

List the records of a repo in the space.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

  • limit – Maximum number of records to list.

  • cursor – Cursor of the page.

  • exclude_values – List the records without their values.

Returns:

Page of records.

Return type:

models.ComAtprotoSpaceListRecords.Response

Raises:
list_repo_ops(repo: str | None = None, since: str | None = None, limit: int | None = None, cursor: str | None = None, exclude_values: bool | None = None) → models.ComAtprotoSpaceListRepoOps.Response

List the operation log of a repo in the space, with the current commit of the repo.

The commit is verified against the MAC of its host.

Note

The operations are not verified. sync_repo() applies them to a known state of the repo. A client gets no MAC for the repo of its account, so only the form of the commit is checked.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • since – Revision of the repo to list the operations after.

  • limit – Maximum number of operations to list.

  • cursor – Cursor of the page.

  • exclude_values – List the operations without the values of the records.

Returns:

Page of operations.

Return type:

models.ComAtprotoSpaceListRepoOps.Response

Raises:
list_writers(limit: int | None = None, cursor: str | None = None) → models.ComAtprotoSpaceListWriters.Response

List the accounts that hold a repo in the space, as the host of the space knows them.

Parameters:
  • limit – Maximum number of repos to list.

  • cursor – Revision of the space to list the repos updated after.

Returns:

Latest update of each repo, in the order of the revisions of the space.

Return type:

models.ComAtprotoSpaceListWriters.Response

Raises:

atproto.exceptions.AtProtocolError – Base exception.

pull_repo(head: RepoHead | None = None, lookup: Callable[[str, str], str | None] | None = None, repo: str | None = None) → RepoChanges | RepoSnapshot | None

Bring a repo in the space up to date.

The repo is synced from its known state. It is read in full when there is no known state, for example on the first pull, or when the operation log does not continue the known state.

Parameters:
  • head – Known state of the repo, if any. The head that the repo was pulled with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record. Required with the known state.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state, RepoSnapshot when the repo was read in full and its records replace every known one, or None when the host has no such repo, so every known record of it is gone.

Return type:

RepoChanges

Raises:
records(repo: str | None = None, collection: str | None = None) → Iterator[SpaceRecord]

Iterate over the records of a repo in the space, each flagged with whether it is valid.

Note

Listed records are not verified against the commit of the repo.

Parameters:
  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

  • collection – NSID of the collection to list. Every collection by default.

Yields:

SpaceRecord – Record of the repo.

Raises:
property ref: SpaceRef

Reference to the space.

property request: Request

HTTP client of the reader.

property space_type: SpaceType | None

Type of the space, when the reader was given one.

sync_repo(head: RepoHead, lookup: Callable[[str, str], str | None], repo: str | None = None) → RepoChanges

Bring a known state of a repo in the space up to date from the operation log of the repo.

Every operation is checked against the known state, and the resulting state against the commit of the repo, which is verified against the MAC of its host.

Parameters:
  • head – Known state of the repo. The head that the repo was read or synced with last.

  • lookup – Returns the CID of a record in the known state of the repo by its collection and record key, or None when there is no such record.

  • repo – DID of the account that the repo belongs to. A client reads the repo of its account by default.

Returns:

Changes of the records since the known state.

Return type:

RepoChanges

Raises:
property uri: str

URI of the space.

writers(cursor: str | None = None) → Iterator[Writer]

Iterate over the accounts that hold a repo in the space, in the order of their latest update.

A repo that was removed from the space is listed as RepoRemoved. A repo that is updated during the iteration can be listed again, and its last entry is the current one.

Note

The highest space_rev listed so far is the cursor to list the repos updated since. The host of a space may forget a removal after 72 hours, so with an older cursor list every repo and drop the ones that are not listed.

Parameters:

cursor – Revision of the space to list the repos updated after.

Yields:

models.ComAtprotoSpaceDefs.RepoWrite or models.ComAtprotoSpaceDefs.RepoRemoved – Latest update of a repo. Entries of an unknown kind are left out.

Raises:

atproto.exceptions.AtProtocolError – Base exception.

class atproto_space.SpaceRecord(repo: str, collection: str, rkey: str, cid: str, value: Any, valid: bool, error: ModelError | None = None)

Record of a space, flagged with whether it is valid.

A record is valid when its type is the collection it is stored under, the type of the space declares the collection, and the record matches the model of the collection.

repo

DID of the account that the record belongs to.

Type:

str

collection

NSID of the record collection.

Type:

str

rkey

Record key.

Type:

str

cid

CID of the record.

Type:

str

value

Record model, or atproto_client.models.dot_dict.DotDict for a collection without a model. An invalid record has the value that its host returned, if any. A value that is not a model is in the JSON form when it was listed, and as decoded from DAG-CBOR when its repo was read in full, so a link is then a atproto_core.cid.CID.

Type:

Any

valid

Whether the record is valid.

Type:

bool

error

Reason why the record is invalid.

Type:

ModelError | None

class atproto_space.SpaceType(nsid: str, key: str, collections: Tuple[str, ...] = ())

Type of a space, as its lexicon declares it.

nsid

NSID of the space type.

Type:

str

key

Type of the space key: any, nsid, tid or literal:<key>.

Type:

str

collections

NSIDs of the collections that the spaces of this type hold.

Type:

Tuple[str, …]

Raises:

ValueError – The key is not a type of a space key.

classmethod from_lexicon(lexicon: LexiconDoc) → SpaceType

Create SpaceType instance from the lexicon that declares it.

Parameters:

lexicon – Lexicon document whose main definition is a space.

Returns:

Type of a space.

Return type:

SpaceType

Raises:

ValueError – The main definition of the lexicon is not a space.

property literal_key: str | None

Key that every space of this type has, if the type declares one.

ref_for(space_did: str, skey: str | None = None) → SpaceRef

Get the reference to a space of this type.

Parameters:
  • space_did – DID of the space authority.

  • skey – Key of the space. The key of a type with a literal key by default.

Returns:

Reference to the space.

Return type:

atproto_core.uri.SpaceRef

Raises:

Submodules

The clients are built from these. You need them directly only when you verify space data that you fetched yourself.