SAM Pydantic Base Classes
These are the base Pydantic models used as the foundations for all Smarter API Manifest (SAM) models.
Pydantic models for Smarter API Manifests.
- class smarter.lib.manifest.models.AbstractSAMBase(*, apiVersion: str, kind: str, metadata: AbstractSAMMetadataBase, spec: AbstractSAMSpecBase, status: AbstractSAMStatusBase | None = None)[source]
Bases:
SmarterBasePydanticModel,ABCAbstract base class for all Smarter API Manifest (SAM) models.
This class serves as the foundational Pydantic model for representing Smarter API manifests. It is intended to be subclassed by concrete manifest classes that define specific resource types within the Smarter API ecosystem.
The
AbstractSAMBaseclass provides a strongly-typed structure for manifest data, ensuring that all manifests adhere to a consistent schema and validation logic. It includes built-in validation for core manifest fields and supports structured access to manifest data.Subclasses should implement or extend this class to define the specific data and behaviors required for their respective manifest types. This design promotes code reuse, type safety, and robust validation across all Smarter API manifests.
The class also provides methods for validating manifest data and for representing the manifest as a string for debugging or logging purposes.
Note
Do not instantiate this class directly. Instead, create subclasses that define the required fields and any additional validation or methods specific to your manifest type.
- metadata: AbstractSAMMetadataBase
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- spec: AbstractSAMSpecBase
- status: AbstractSAMStatusBase | None
- classmethod validate_apiVersion(v)[source]
Validates the
apiVersionfield for a manifest.This method ensures that the
apiVersionattribute is present and matches one of the supported API versions defined inSmarterApiVersions. If the value is missing or invalid, aSAMValidationErroris raised.- Parameters:
v (str) – The value of the
apiVersionfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the value is missing or not a supported version.
- Returns:
The validated
apiVersionstring.- Return type:
- classmethod validate_metadata(v)[source]
Validates the
metadatafield for a manifest.This method ensures that the
metadataattribute is an instance ofAbstractSAMMetadataBase. If a dictionary is provided, it will be coerced into anAbstractSAMMetadataBaseobject. This guarantees that the manifest metadata is always properly structured and validated.- Parameters:
v (dict or AbstractSAMMetadataBase) – The value of the
metadatafield to validate.- Returns:
The validated
metadataobject.- Return type:
- class smarter.lib.manifest.models.AbstractSAMMetadataBase(*, name: str, description: str | None, version: str | None, tags: List[str] | None = <factory>, annotations: List[dict[str, str | int | float | bool | ~datetime.date | ~datetime.datetime | ~decimal.Decimal | ~uuid.UUID | bytes | list | dict]] | None=<factory>)[source]
Bases:
SmarterBasePydanticModel,ABCAbstract base class for manifest metadata in the Smarter API.
This class defines the required structure and validation logic for metadata associated with Smarter API manifests. It is designed to be subclassed by concrete manifest metadata classes, which may extend or customize the metadata fields as needed for specific resource types.
The
AbstractSAMMetadataBaseenforces strong typing and validation for core metadata fields, such as resource name, description, version, tags, and annotations. It ensures that all metadata adheres to expected formats and constraints, promoting consistency and reliability across all manifest definitions.Subclasses should inherit from this class to implement metadata for their specific manifest types. This approach encourages code reuse, enforces validation, and provides a unified interface for working with manifest metadata throughout the Smarter API ecosystem.
Note
This class is abstract and should not be instantiated directly. Instead, create subclasses that define any additional fields or validation required for your manifest’s metadata.
- annotations: List[dict[str, str | int | float | bool | date | datetime | Decimal | UUID | bytes | list | dict]] | None
- classmethod coerce_annotations_to_list(v)[source]
Pre-validator to coerce stringified JSON lists to Python lists for annotations. This ensures that if the input is a string (e.g., ‘[{“key”: “value”}]’), it is parsed as a list before type validation.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- classmethod validate_annotations(v)[source]
Validates the
annotationsfield for a manifest. Accepts a list of dicts, where each dict can be a single key-value pair or a flat dict with multiple key-value pairs. Supports multi-line string values (YAML block scalars). Ensures each annotation key is URL-friendly and each value is a string or scalar (including multi-line strings). Raises SAMValidationError if invalid.- Parameters:
v (Optional[List[dict[str, Any]]]) – The value of the
annotationsfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If any annotation is invalid.
- Returns:
The validated list of annotations.
- Return type:
Optional[List[dict[str,Union[str,int,float,bool,date,datetime,Decimal,UUID,bytes,list,dict]]]]
- classmethod validate_description(v)[source]
Validates the
descriptionfield for a manifest. This method ensures that thedescriptionattribute is present. If the value is missing, aSAMValidationErroris raised.- Parameters:
v (str) – The value of the
descriptionfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the value is missing.
- Returns:
The validated
descriptionstring.- Return type:
- classmethod validate_name(v)[source]
Validates the
namefield for a manifest.Ensures the value is a string, present, and meets all constraints. Raises if not a string.
- Return type:
- classmethod validate_tags(v)[source]
Validates the
tagsfield for a manifest. This method ensures that each tag in thetagslist adheres to URL-friendly character rules. If any tag is invalid, aSAMValidationErroris raised.- Parameters:
v (Optional[List[str]]) – The value of the
tagsfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If any tag is invalid.
- Returns:
The validated list of tags.
- Return type:
- classmethod validate_version(v)[source]
Validates the
versionfield for a manifest. This method ensures that theversionattribute is present and follows semantic versioning rules. If the value is missing or invalid, aSAMValidationErroris raised- Parameters:
v (str) – The value of the
versionfield to validate.- Raises:
smarter.lib.manifest.exceptions.SAMValidationError – If the value is missing or invalid.
- Returns:
The validated
versionstring.- Return type:
- class smarter.lib.manifest.models.AbstractSAMSpecBase[source]
Bases:
SmarterBasePydanticModel,ABCPydantic Spec base class. Expected to be subclassed by specific manifest classes.
- class smarter.lib.manifest.models.AbstractSAMStatusBase(*, recordLocator: str, created: datetime, modified: datetime)[source]
Bases:
SmarterBasePydanticModel,ABCPydantic Status base class. Expected to be subclassed by specific manifest classes.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- class smarter.lib.manifest.models.SmarterBasePydanticModel[source]
Bases:
BaseModel,SmarterHelperMixinSmarter API Base Pydantic Model.
- __init__(**data)[source]
Add support for passing a ‘user’ argument when initializing the model, which will be stored in a private attribute.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'from_attributes': True, 'frozen': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Return type:
- Parameters:
self – The BaseModel instance.
context – The context.
- property user_profile: UserProfile | None
Get the user profile associated with this manifest, if any.
- smarter.lib.manifest.models.VALID_ANNOTATION_VALUE_TYPES_SET = (<class 'str'>, <class 'int'>, <class 'float'>, <class 'bool'>, <class 'datetime.date'>, <class 'datetime.datetime'>, <class 'decimal.Decimal'>, <class 'uuid.UUID'>, <class 'bytes'>, <class 'list'>, <class 'dict'>)
Types allowed for annotation values in manifest metadata.
( <class 'str'>, <class 'int'>, <class 'float'>, <class 'bool'>, <class 'datetime.date'>, <class 'datetime.datetime'>, <class 'decimal.Decimal'>, <class 'uuid.UUID'>, <class 'bytes'>, <class 'list'>, <class 'dict'>, )