Core
Schema
Field
- class belso.core.Field(name: str, type: Any, description: str = '', required: bool = True, default: Any | None = None, enum: List[Any] | None = None, range: tuple | None = None, exclusive_range: tuple | None = None, length_range: tuple | None = None, items_range: tuple | None = None, properties_range: tuple | None = None, regex: str | None = None, multiple_of: float | None = None, format: str | None = None)[source]
Bases:
objectFactory class that returns the correct
BaseFieldsubtype (BaseField,NestedField, orArrayField).
SchemaProcessor
- class belso.core.SchemaProcessor[source]
Bases:
objectA unified class for schema processing, including translation and validation. This class combines the functionality of the previous Translator and Validator classes.
- static convert(schema, to, from_format=None)[source]
Convert a schema to a specific format. This method can automatically detect the input schema format and convert it to our internal format before translating to the target format.
Args
schema (
Any): the schema to conver.to (
str): the target format. Can be a string or abelso.utils.FORMATSattribute.from_format (
Optional[str]): optional format hint for the input schema. IfNone, the format will be auto-detected. Defaults toNone.
Returns
Dict[str, Any]
- static detect_format(schema)[source]
Detect the format of a schema.
Args
schema (
Any): the schema to detect.
Returns
str: the detected format as a string.
- static display(schema, format_type=None)[source]
Pretty-print a schema using colors and better layout, including nested fields.
Args
schema (
Any): the schema to print.format_type (
Optional[str]): format of the schema. Defaults toNone.
- static load(path, standardize=True)[source]
Load a schema from a file in the specified format.
Args
path (
Union[str, Path]): the path to the file to load.standardize (
bool): whether to convert the schema to our internal ‘belso’ format. Defaults toTrue.
Returns
Any: the loaded schema.
- static save(schema, path)[source]
Save a schema to a file in the specified format.
Args
schema (
Any): the schema to save.path (
Union[str, Path]): the path to save the schema to.
- static standardize(schema, from_format=None)[source]
Convert a schema from a specific format to our internal ‘belso’ format. If from_format is not specified, it will be auto-detected.
Args
schema (
Any): the schema to convert.from_format (
Optional[str]): the format of the input schema. IfNone, the format will be auto-detected. Defaults toNone.
Returns
Type[belso.Schema]: the converted belso schema.