aries_cloudagent.messaging.models package

Common code for messaging models.


aries_cloudagent.messaging.models.base module

Base classes for Models and Schemas.

class aries_cloudagent.messaging.models.base.BaseModel[source]

Bases: ABC

Base model that provides convenience methods.

class Meta[source]

Bases: object

BaseModel meta data.

schema_class = None
property Schema: Type[BaseModelSchema]

Accessor for the model’s schema class.


The schema class

classmethod deserialize(obj) ModelType[source]
classmethod deserialize(obj, *, unknown: Optional[str] = None) ModelType
classmethod deserialize(obj, *, none2none: typing_extensions.Literal.False, unknown: ~typing.Optional[str] = None) ModelType
classmethod deserialize(obj, *, none2none: typing_extensions.Literal.True, unknown: ~typing.Optional[str] = None) Optional[ModelType]

Convert from JSON representation to a model instance.

  • obj – The dict to load into a model instance

  • unknown – Behaviour for unknown attributes

  • none2none – Deserialize None to None


A model instance for this data

classmethod from_json(json_repr: Union[str, bytes], unknown: Optional[str] = None)[source]

Parse a JSON string into a model instance.


json_repr – JSON string


A model instance representation of this JSON

classmethod serde(obj: Union[BaseModel, Mapping]) Optional[SerDe][source]

Return serialized, deserialized representations of input object.

serialize(*, as_string: typing_extensions.Literal.True, unknown: ~typing.Optional[str] = None) str[source]
serialize(*, unknown: Optional[str] = None) dict

Create a JSON-compatible dict representation of the model instance.


as_string – Return a string of JSON instead of a dict


A dict representation of this model, or a JSON string if as_string is True

to_json(unknown: Optional[str] = None) str[source]

Create a JSON representation of the model instance.


A JSON representation of this message

validate(unknown: Optional[str] = None)[source]

Validate a constructed model.

exception aries_cloudagent.messaging.models.base.BaseModelError(*args, error_code: Optional[str] = None, **kwargs)[source]

Bases: BaseError

Base exception class for base model errors.

class aries_cloudagent.messaging.models.base.BaseModelSchema(*args: Any, **kwargs: Any)[source]

Bases: Schema

BaseModel schema.

class Meta[source]

Bases: object

BaseModelSchema metadata.

model_class = None
ordered = True
skip_values = [None]
property Model: type

Accessor for the schema’s model class.


The model class

make_model(data: dict, **kwargs)

Return model instance after loading.


A model instance

remove_skipped_values(data, **kwargs)

Remove values that are are marked to skip.


Returns this modified data

skip_dump_only(data, **kwargs)

Skip fields that are only expected during serialization.


data – The incoming data to clean


The modified data

class aries_cloudagent.messaging.models.base.SerDe(ser, de)

Bases: tuple


Alias for field number 1


Alias for field number 0

aries_cloudagent.messaging.models.base.resolve_class(the_cls, relative_cls: Optional[type] = None) type[source]

Resolve a class.

  • the_cls – The class to resolve

  • relative_cls – Relative class to resolve from


The resolved class


ClassNotFoundError – If the class could not be loaded

aries_cloudagent.messaging.models.base.resolve_meta_property(obj, prop_name: str, defval=None)[source]

Resolve a meta property.

  • prop_name – The property to resolve

  • defval – The default value


The meta property

aries_cloudagent.messaging.models.base_record module

Classes for BaseStorage-based record management.

class aries_cloudagent.messaging.models.base_record.BaseExchangeRecord(id: Optional[str] = None, state: Optional[str] = None, *, trace: bool = False, **kwargs)[source]

Bases: BaseRecord

Represents a base record with event tracing capability.

class aries_cloudagent.messaging.models.base_record.BaseExchangeSchema(*args: Any, **kwargs: Any)[source]

Bases: BaseRecordSchema

Base schema for exchange records.

class Meta[source]

Bases: object

BaseExchangeSchema metadata.


alias of BaseExchangeRecord

class aries_cloudagent.messaging.models.base_record.BaseRecord(id: Optional[str] = None, state: Optional[str] = None, *, created_at: Optional[Union[str, datetime]] = None, updated_at: Optional[Union[str, datetime]] = None, new_with_id: bool = False)[source]

Bases: BaseModel

Represents a single storage record.

EVENT_NAMESPACE: str = 'acapy::record'
class Meta[source]

Bases: object

BaseRecord metadata.

RECORD_TOPIC: Optional[str] = None
STATE_DELETED = 'deleted'
TAG_NAMES = {'state'}
async classmethod clear_cached_key(session: ProfileSession, cache_key: str)[source]

Shortcut method to clear a cached key value, if any.

  • session – The profile session to use

  • cache_key – The unique cache identifier

async delete_record(session: ProfileSession)[source]

Remove the stored record.


session – The profile session to use

async emit_event(session: ProfileSession, payload: Optional[Any] = None)[source]

Emit an event.

  • session – The profile session to use

  • payload – The event payload

classmethod from_storage(record_id: str, record: Mapping[str, Any])[source]

Initialize a record from its stored representation.

  • record_id – The unique record identifier

  • record – The stored representation

classmethod get_attributes_by_prefix(prefix: str, walk_mro: bool = True)[source]

List all values for attributes with common prefix.

  • prefix – Common prefix to look for

  • walk_mro – Walk MRO to find attributes inherited from superclasses

async classmethod get_cached_key(session: ProfileSession, cache_key: str)[source]

Shortcut method to fetch a cached key value.

  • session – The profile session to use

  • cache_key – The unique cache identifier

classmethod get_tag_map() Mapping[str, str][source]

Accessor for the set of defined tags.

classmethod log_state(msg: str, params: Optional[dict] = None, settings: Optional[BaseSettings] = None, override: bool = False)[source]

Print a message with increased visibility (for testing).

async post_save(session: ProfileSession, new_record: bool, last_state: Optional[str], event: Optional[bool] = None)[source]

Perform post-save actions.

  • session – The profile session to use

  • new_record – Flag indicating if the record was just created

  • last_state – The previous state value

  • event – Flag to override whether the event is sent

classmethod prefix_tag_filter(tag_filter: dict)[source]

Prefix unencrypted tags used in the tag filter.

async classmethod query(session: ProfileSession, tag_filter: Optional[dict] = None, *, post_filter_positive: Optional[dict] = None, post_filter_negative: Optional[dict] = None, alt: bool = False) Sequence[RecordType][source]

Query stored records.

  • session – The profile session to use

  • tag_filter – An optional dictionary of tag filter clauses

  • post_filter_positive – Additional value filters to apply matching positively

  • post_filter_negative – Additional value filters to apply matching negatively

  • alt – set to match any (positive=True) value or miss all (positive=False) values in post_filter

property record_tags: dict

Accessor to define implementation-specific tags.

property record_value: dict

Accessor to define custom properties for the JSON record value.

async classmethod retrieve_by_id(session: ProfileSession, record_id: str, *, for_update=False) RecordType[source]

Retrieve a stored record by ID.

  • session – The profile session to use

  • record_id – The ID of the record to find

async classmethod retrieve_by_tag_filter(session: ProfileSession, tag_filter: dict, post_filter: Optional[dict] = None, *, for_update=False) RecordType[source]

Retrieve a record by tag filter.

  • session – The profile session to use

  • tag_filter – The filter dictionary to apply

  • post_filter – Additional value filters to apply matching positively, with sequence values specifying alternatives to match (hit any)

async save(session: ProfileSession, *, reason: Optional[str] = None, log_params: Optional[Mapping[str, Any]] = None, log_override: bool = False, event: Optional[bool] = None) str[source]

Persist the record to storage.

  • session – The profile session to use

  • reason – A reason to add to the log

  • log_params – Additional parameters to log

  • override – Override configured logging regimen, print to stderr instead

  • event – Flag to override whether the event is sent

async classmethod set_cached_key(session: ProfileSession, cache_key: str, value: Any, ttl=None)[source]

Shortcut method to set a cached key value.

  • session – The profile session to use

  • cache_key – The unique cache identifier

  • value – The value to cache

  • ttl – The cache ttl

property storage_record: StorageRecord

Accessor for a StorageRecord representing this record.

classmethod strip_tag_prefix(tags: dict)[source]

Strip tilde from unencrypted tag names.

property tags: dict

Accessor for the record tags generated for this record.

property value: dict

Accessor for the JSON record value generated for this record.

class aries_cloudagent.messaging.models.base_record.BaseRecordSchema(*args: Any, **kwargs: Any)[source]

Bases: BaseModelSchema

Schema to allow serialization/deserialization of base records.

class Meta[source]

Bases: object

BaseRecordSchema metadata.

model_class = None
aries_cloudagent.messaging.models.base_record.match_post_filter(record: dict, post_filter: dict, positive: bool = True, alt: bool = False) bool[source]

Determine if a record value matches the post-filter.

  • record – record to check

  • post_filter – filter to apply (empty or None filter matches everything)

  • positive – whether matching all filter criteria positively or negatively

  • alt – set to match any (positive=True) value or miss all (positive=False) values in post_filter

aries_cloudagent.messaging.models.openapi module

Base class for OpenAPI artifact schema.

class aries_cloudagent.messaging.models.openapi.OpenAPISchema(*args: Any, **kwargs: Any)[source]

Bases: Schema

Schema for OpenAPI artifacts: excluding unknown fields, not raising exception.

class Meta[source]

Bases: object

OpenAPISchema metadata.

model_class = None