air_sdk.air_model#

Attributes#

Classes#

BaseModel

AirModel

Helper class that provides a standard way to create an ABC using

ForeignKeyMixin

AirModel mixin for lazily resolving the instance.

ApiNotImplementedMixin

Mixin used to allow AirModel subclasses to have an unimplemented API.

EndpointMethodMixin

Mixin class for defining common endpoint methods.

BaseEndpointAPI

Mixin class for defining common endpoint methods.

Functions#

_generate_special_field(→ SpecialField)

Get a unique mapping for assignment of metadata on special BaseModel fields.

Module Contents#

air_sdk.air_model.T#
air_sdk.air_model.TAirModel#
air_sdk.air_model.TAirModel_co#
air_sdk.air_model.TParentAirModel_co#
air_sdk.air_model.TSupportedPrimitive#
type air_sdk.air_model.PrimaryKey = str | UUID#
air_sdk.air_model.SpecialField#
air_sdk.air_model.DataDict#
air_sdk.air_model._generate_special_field() SpecialField[source]#

Get a unique mapping for assignment of metadata on special BaseModel fields.

class air_sdk.air_model.BaseModel[source]#
__serializing__ = False#
dict() DataDict[source]#
json() str[source]#
class air_sdk.air_model.AirModel[source]#

Bases: BaseModel, abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

_api: dataclasses.InitVar#
FIELD_FOREIGN_KEY: ClassVar[SpecialField]#
FIELD_LAZY: ClassVar[SpecialField]#
__post_init__(_api: air_sdk.AirApi) None[source]#
property primary_key_field: str#

Returns the name of the field representing the primary key.

property __pk__: PrimaryKey#

Returns current model’s primary key for API-related actions.

property detail_url: str#
clear_cached_property(property_name: str) None[source]#

Clear a cached property to force re-computation on next access.

Parameters:

property_name – Name of the cached property to clear

Example

>>> simulation.clear_cached_property('ztp_script')
>>> # Next access will re-query the API
>>> print(simulation.ztp_script)
__eq__(other: Any) bool[source]#
__getitem__(key: str) Any[source]#

Enable dictionary-style access to fields: obj[‘field_name’]

__setitem__(key: str, value: Any) None[source]#

Enable dictionary-style assignment to fields: obj[‘field_name’] = value

__contains__(key: str) bool[source]#

Enable membership testing: ‘field_name’ in obj

__getattribute__(name: str) Any[source]#
__refresh__(refreshed_obj: BaseModel | None = None) None[source]#

Refreshed the instances data from the backend.

Raises:

NotImplementedError - When the model's API does not implement get.

classmethod get_model_api() Type[BaseEndpointAPI[TAirModel_co]][source]#
Abstractmethod:

Returns the respective AirModelAPI type for this model.

refresh() None[source]#

Refresh the instance by querying new API data.

This uses the get method on the model’s EndpointAPI by default.

_ensure_pk_exists(context: str) None[source]#
update(*args: Any, **kwargs: Any) None[source]#
full_update(*args: Any, **kwargs: Any) None[source]#
delete() None[source]#

Delete the instance and nullify the primary key.

class air_sdk.air_model.ForeignKeyMixin(primary_key: uuid.UUID, _api: air_sdk.AirApi)[source]#

Bases: Generic[TAirModel_co]

AirModel mixin for lazily resolving the instance.

__fk__#
__fk_resolved__ = False#
__api__#
property __pk__: PrimaryKey#
__getattribute__(name: str) Any[source]#

Loads the instance upon initial access to an exposed attribute.

class air_sdk.air_model.ApiNotImplementedMixin[source]#

Mixin used to allow AirModel subclasses to have an unimplemented API.

__refresh__(refreshed_obj: BaseModel | None = None) None[source]#
class air_sdk.air_model.EndpointMethodMixin[source]#

Mixin class for defining common endpoint methods.

This is used to prevent with the intention of raising a NotImplementedError instead of an AttributeError when specific endpoint methods are not implemented in the SDK or API.

abstractmethod list(**kwargs: Any) Iterator[AirModel][source]#
abstractmethod create(*args: Any, **kwargs: Any) AirModel[source]#
abstractmethod get(*args: Any, **kwargs: Any) AirModel[source]#
abstractmethod put(*args: Any, **kwargs: Any) AirModel[source]#
abstractmethod patch(*args: Any, **kwargs: Any) AirModel[source]#
abstractmethod delete(*args: Any, **kwargs: Any) None[source]#
class air_sdk.air_model.BaseEndpointAPI(
api: air_sdk.AirApi,
default_filters: dict[str, Any] | None = None,
)[source]#

Bases: EndpointMethodMixin, Generic[TAirModel_co]

Mixin class for defining common endpoint methods.

This is used to prevent with the intention of raising a NotImplementedError instead of an AttributeError when specific endpoint methods are not implemented in the SDK or API.

model: Type[TAirModel_co]#
API_PATH: str = ''#
__api__#
default_filters#
property url: str#
property open_api_url: str#
property model_cls_type_hints: DataDict#
property model_cls_fields: Tuple[dataclasses.Field[Any], Ellipsis]#
load_model(data: DataDict) TAirModel_co[source]#

Construct a new model instance, validate data, and set the API Client.

get_defaults_for_missing_fields(
dc_fields: list[dataclasses.Field[Any]],
) DataDict[source]#

Get default values for fields missing from API response.

parse_provided_fields(
dc_fields: list[dataclasses.Field[Any]],
data: DataDict,
) DataDict[source]#
parse_field(
hint: Type[T],
metadata: Mapping[Any, Any],
provided_value: Any,
context: str,
) T[source]#

Parse the provided value based on the type hint of the value.

This allows us to perform type checking of provided values and assists in the implementation of our FIELD_FOREIGN_KEY and FIELD_LAZY fields.

If parsing fails (e.g., due to API type changes), falls back to returning the raw value to prevent crashes.

handle_list_field(
hint: Type[list[T]],
metadata: Mapping[Any, Any],
provided_value: Any | list[Any],
) list[T][source]#

Provided data argument is validated to be an actual list. Each item in data list is then validated against the target type and parsed individually.

handle_optional_field(
hint: Type[T | None],
metadata: Mapping[Any, Any],
provided_value: Any,
) T | None[source]#
handle_air_model_field(
hint: Type[TAirModel_co],
metadata: Mapping[Any, Any],
provided_value: Any,
) TAirModel_co[source]#

AirModel fields are validated as follows: - Foreign key fields are reserved for on-demand loading - Otherwise, field is parsed as a regular BaseModel

handle_datetime_field(provided_value: Any) datetime.datetime[source]#
handle_primitive_field(
hint: Type[TSupportedPrimitive],
provided_value: Any,
) TSupportedPrimitive[source]#

Primitive fields are validated for type mismatch and returned as-is.