bundle.core.data ================ .. py:module:: bundle.core.data Attributes ---------- .. autoapisummary:: bundle.core.data.D Classes ------- .. autoapisummary:: bundle.core.data.Data Functions --------- .. autoapisummary:: bundle.core.data.configuration Module Contents --------------- .. py:data:: D .. py:function:: configuration(arbitrary_types_allowed: bool = True, from_attributes: bool = True, extra: str = 'forbid', json_encoders: dict[type, collections.abc.Callable] | None = None) Public interface to define configuration settings for Pydantic models. :param arbitrary_types_allowed: Allows arbitrary types, defaults to True. :type arbitrary_types_allowed: bool :param from_attributes: Whether to use model attributes for configuration, defaults to True. :type from_attributes: bool :param extra: Policy for extra attributes, defaults to "forbid". :type extra: str :param json_encoders: Custom JSON encoders for specific types. :type json_encoders: dict[type, Callable] | None :returns: A `ConfigDict` instance with the specified configuration settings. .. py:class:: Data(/, **data: Any) Bases: :py:obj:`pydantic.BaseModel` Base data model class, providing utilities for serialization and deserialization from/to JSON, along with JSON Schema generation. .. attribute:: model_config Default model configuration settings. .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:method:: from_dict(data: dict) -> D :classmethod: :async: Create an instance of the model from a dictionary. :param data: The data dictionary from which to create the model instance. :type data: dict :returns: An instance of the model. :raises Exception: If the model instantiation fails. .. py:method:: as_dict() -> dict :async: Create an instance of the model from a JSON file. :param json_path: The path to the JSON file. :type json_path: Path :returns: An instance of the model. :raises Exception: If the model instantiation from the JSON file fails. .. py:method:: from_json(json_source: str | pathlib.Path) -> D :classmethod: :async: Create an instance of the model from either a JSON string or a path to a JSON file. :param json_source: The JSON string or path to the JSON file. :type json_source: str | Path :returns: An instance of the model. :raises RuntimeError: If the `json_source` is neither a string nor a Path instance. :raises Exception: If the model instantiation from the JSON source fails. .. py:method:: as_json() -> str :async: Serialize the model instance to a JSON string. :returns: A JSON string representation of the model instance. :raises Exception: If serialization to JSON fails. .. py:method:: dump_json(path: pathlib.Path) -> None :async: Write the JSON representation of the model instance to a file. :param path: The file path where the JSON data will be saved. :type path: Path :raises Exception: If writing to the file fails. .. py:method:: as_jsonschema(mode: pydantic.json_schema.JsonSchemaMode = 'serialization') -> dict :classmethod: :async: Generate the JSON Schema of the model. :param mode: The mode of the JSON Schema, defaults to "serialization". :type mode: json_schema.JsonSchemaMode :returns: A dictionary representing the JSON Schema of the model. :raises Exception: If generating the JSON Schema fails. .. py:method:: as_jsonschema_str(mode: pydantic.json_schema.JsonSchemaMode = 'serialization') -> str :classmethod: :async: Serialize the JSON Schema of the model to a JSON string. :param mode: The mode of the JSON Schema, defaults to "serialization". :type mode: json_schema.JsonSchemaMode :returns: A JSON string representation of the model's JSON Schema. :raises Exception: If serializing the JSON Schema to a string fails. .. py:method:: dump_jsonschema(path: pathlib.Path, mode: pydantic.json_schema.JsonSchemaMode = 'serialization') -> None :async: Write the JSON Schema of the model to a file. :param path: The file path where the JSON Schema will be saved. :type path: Path :param mode: The mode of the JSON Schema, defaults to "serialization". :type mode: json_schema.JsonSchemaMode :raises Exception: If writing the JSON Schema to the file fails.