momoa [source] ¶
package momoa
Basic class to parse a schema and prepare the model class.
Classes
-
Schema — Basic class to parse the schema and prepare the model class.
momoa.Schema [source] ¶
class Schema(schema: dict[str, Any], model_factory: ModelFactory = Model.make_model)
Basic class to parse the schema and prepare the model class.
Constructs the Schema class instance.
Parameters
-
schema : dict[str, Any] — A Python dict representation of the JSONSchema specification.
-
model_factory : ModelFactory — A callable that creates a model subclass from a JSON Schema. Can be used to customize Model creation.
Raises
Methods
-
from_uri — Instantiates the Schema from a URI to the schema document.
-
from_file — Helper to instantiate the Schema from a local file path.
-
model — Retrieves the top model class of the schema.
-
deserialize — Converts raw data to the Model instance, validating it in the process.
momoa.Schema.from_uri [source] ¶
classmethod Schema.from_uri(input_uri: str) → Schema
Instantiates the Schema from a URI to the schema document.
For local files use the file://
scheme. This method also dereferences
the internal $ref
links.
Parameters
-
input_uri : str — String representation of the URI to the schema.
Returns
-
Schema — Schema instance.
momoa.Schema.from_file [source] ¶
classmethod Schema.from_file(file_path: Path | str) → Schema
Helper to instantiate the Schema from a local file path.
Note: This method will not dereference any internal $ref
links.
Parameters
-
file_path : Path | str — Either a simple string path or a
pathlib.Path
object.
Returns
-
Schema — Schema instance.
momoa.Schema.model [source] ¶
method Schema.model() → type[Model]
Retrieves the top model class of the schema.
Returns Model subclass.
momoa.Schema.deserialize [source] ¶
method Schema.deserialize(raw_data: Mapping[str, Any] | str) → Model
Converts raw data to the Model instance, validating it in the process.
Parameters
-
raw_data : Mapping[str, Any] | str — The raw data to deserialize. Can be either a JSON string or a preloaded Python mapping object.
Returns
-
Model — An instance of the Model class.