utils#
- atproto.xrpc_client.models.utils.create_strong_ref(model: ModelBase) 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!') >>> client.like(create_strong_ref(response)) >>> client.repost(create_strong_ref(response))
- Returns:
Strong ref.
- Return type:
- atproto.xrpc_client.models.utils.get_model_as_dict(model: Union[DotDict, BlobRef, ModelBase]) dict #
- atproto.xrpc_client.models.utils.get_or_create(model_data: Optional[Union[M, dict]], model: Optional[Type[M]] = None, *, strict: bool = True) Optional[Union[M, Main, Main, Main, Main, Main, Main, Main, Main, Main, Main, Main, DotDict]] #
Get model instance from raw data.
Note
The record could have custom fields and be completely custom. For example, custom bsky clients add a “via” field to indicate that it was posted using a not official client. Such custom types can’t be decoded into proper models, and will be decoded to
atproto.xrpc_client.models.base.DotDict
.Note
By default, the method raises an exception on custom models. 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 can’t be properly deserialized. Will raise the exception instead.
- Returns:
Instance of
model
orNone
oratproto.xrpc_client.models.dot_dict.DotDict
if strict is disabled.
- atproto.xrpc_client.models.utils.is_json(json_data: Union[str, bytes]) bool #
- atproto.xrpc_client.models.utils.is_record_type(model: Union[ModelBase, DotDict], expected_type: Union[str, module]) bool #
Verify that the model is the expected Record type.
- Parameters:
model – Model to be verified.
expected_type – Excepted type. Could be NSID or Python Module.
Example
>>> from atproto import Client, models >>> from atproto.xrpc_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)
- Returns:
Is record or not.
- Return type:
bool