Models

Every lexicon of the network, generated as a Pydantic model. Browse by NSID: the authority, then the namespace, then the record or method.

atproto_client.models.create_strong_ref(model: _StrongRefSource) β†’ Main

Create a strong ref from the model.

Parameters:

model – Any model with cid and uri fields.

Example

>>> from atproto import Client
>>> client = Client()
>>> client.login('my-handle', 'my-password')
>>> response = client.send_post(text='Hello World from Python!')
>>> strong_ref = create_strong_ref(response)
Returns:

Strong ref.

Return type:

atproto.xrpc_client.models.com.atproto.repo.strong_ref.Main

atproto_client.models.get_model_as_dict(model: DotDict | BlobRef | ModelBase) β†’ Dict[str, Any]
atproto_client.models.get_model_as_json(model: DotDict | BlobRef | ModelBase) β†’ str
atproto_client.models.get_or_create(model_data: M | Mapping[str, Any] | None, model: Type[M] | None = None, *, strict: bool = True, strict_string_format: bool = False) β†’ M | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | Record | DotDict | None

Get model instance from raw data.

Note

The record could have additional fields and be completely custom. For example, third-party bsky clients add a β€œvia” field to indicate that it was posted using a not official client. Such records are corresponding to the lexicon, but have additional fields. This is called β€œextended record”. Extended records will be decoded to proper models with extra, non-typehinted fields available only in runtime. Unknown record types will be decoded to atproto.xrpc_client.models.base.DotDict. A union member with an unrecognized β€œ$type” is decoded to a DotDict too, without failing the rest of the model.

Note

By default, the method raises an exception on custom models if you have passed the expected model. To fall back to a atproto.xrpc_client.models.base.DotDict type, disable strict mode using the argument.

Note

Model auto-resolve works only with a Record type for now.

Parameters:
  • model_data – Raw data.

  • model – Class of the model or any another type. If None, it will be resolved automatically.

  • strict – Disable fallback to dictionary (atproto.xrpc_client.models.base.DotDict) if it can’t be properly deserialized in provided model. Will raise the exception instead.

  • strict_string_format – Enable strict string format validation.

Returns:

Instance of model or None or atproto.xrpc_client.models.dot_dict.DotDict if strict is disabled.

atproto_client.models.is_record_type(model: ModelBase | DotDict | None, expected_type: Any) β†’ bool

Verify that the model is the expected Record type.

Note

Passing a Python module or a Record class narrows the type of model for static type checkers. Narrowing is not performed for the NSID form because a string carries no type information.

Warning

A custom or extended record that failed validation is decoded to atproto_client.models.dot_dict.DotDict. Such a model matches its own type by NSID, so the narrowed type is not guaranteed to be an instance of the Record class in runtime.

Parameters:
  • model – Model to be verified. None is never a record.

  • expected_type – Excepted type. Could be NSID, Python Module, or Record class.

Example

>>> from atproto import Client, models
>>> from atproto_client.models import ids, is_record_type
>>> client = Client()
>>> client.login('username', 'pass')
>>> record = client.com.atproto.repo.get_record(...)
>>> # using NSID:
>>> is_record_type(record.value, ids.AppBskyFeedPost)
>>> # using Python module:
>>> is_record_type(record.value, models.AppBskyFeedPost)
>>> # using Record class:
>>> is_record_type(record.value, models.AppBskyFeedPost.Record)
Returns:

Is record or not.

Return type:

bool

Lexicons

One page per NSID, generated from the lexicons the network publishes.

app

Application lexicons: everything an app exposes to the people using it.

app
chat

Private messaging lexicons.

chat
com

The protocol itself, plus the lexicons of third-party services.

com
internal

Internal lexicons that are not part of the public API.

internal
network

Infrastructure services behind the network.

network
place

Place.

place
site

Websites published on atproto.

site
social

Social.

social
tools

Tooling for the people who operate the network.

tools

Core

The hand-written machinery every generated model is built on.

base

Base classes every generated model inherits from.

base
blob_ref

References to blobs stored on a PDS.

blob_ref
bytes_type

Lexicon bytes, carried as base64 in JSON.

bytes_type
common

Types shared across the generated models.

common
dot_dict

Dict wrapper that also allows attribute access.

dot_dict
languages

ISO language codes used by posts.

languages
models_loader

Lazy import of the generated model modules.

models_loader
record_registry

Registry mapping record NSIDs to their model.

record_registry
string_formats

Validation of the AT Protocol string formats.

string_formats
type_conversion

Conversion between models, dicts, and raw JSON.

type_conversion
unknown_type

Fallback for records of an unrecognised type.

unknown_type
unknown_union

Fallback for union members of an unrecognised type.

unknown_union
utils

Helpers for working with model instances.

utils