betty.json.schema module

Provide JSON utilities.

class betty.json.schema.AllOf[source]

Bases: _Container

A JSON Schema allOf.

class betty.json.schema.AnyOf[source]

Bases: _Container

A JSON Schema anyOf.

class betty.json.schema.Array[source]

Bases: _Type

A JSON Schema array type.

__init__(items: Schema, *, def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
class betty.json.schema.Boolean[source]

Bases: _Type

A JSON Schema boolean type.

class betty.json.schema.Const[source]

Bases: Schema

A JSON Schema const.

__init__(const: bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump], *, def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
class betty.json.schema.Def[source]

Bases: str

The name of a named Betty schema.

Using this instead of str directly allows Betty to bundle schemas together under a project namespace.

See betty.json.schema.Schema.def_name.

static __new__(cls, def_name: str)[source]
class betty.json.schema.Enum[source]

Bases: Schema

A JSON Schema enum.

__init__(*values: bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump], def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
class betty.json.schema.FileBasedSchema[source]

Bases: Schema

A JSON Schema that is stored in a file.

async classmethod new_for(file_path: Path, *, def_name: str | None = None, title: str | None = None, description: str | None = None) Self[source]

Create a new instance.

class betty.json.schema.Integer[source]

Bases: _Type

A JSON Schema integer type.

class betty.json.schema.JsonSchemaReference[source]

Bases: String

The JSON Schema schema.

__init__()[source]
final class betty.json.schema.JsonSchemaSchema[source]

Bases: FileBasedSchema

The JSON Schema Draft 2020-12 schema.

async classmethod new() Self[source]

Create a new instance.

class betty.json.schema.Null[source]

Bases: _Type

A JSON Schema null type.

class betty.json.schema.Number[source]

Bases: _Type

A JSON Schema number type.

class betty.json.schema.Object[source]

Bases: _Type

A JSON Schema object type.

__init__(*, def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
add_property(property_name: str, property_schema: Schema, property_required: bool = True) None[source]

Add a property to the object schema.

class betty.json.schema.OneOf[source]

Bases: _Container

A JSON Schema oneOf.

class betty.json.schema.Ref[source]

Bases: Schema

A JSON Schema that references a named Betty schema.

__init__(def_name: str)[source]
class betty.json.schema.Schema[source]

Bases: object

A JSON Schema.

All schemas using this class MUST follow JSON Schema Draft 2020-12.

To test your own subclasses, use betty.test_utils.json.schema.SchemaTestBase.

__init__(*, def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
property def_name: str | None

The schema machine name when embedded into another schema’s $defs.

property defs: MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]]

The JSON Schema’s $defs definitions, kept separately, so they can be merged when this schema is embedded.

Only top-level definitions are supported. You MUST NOT nest definitions. Instead, prefix or suffix their names.

property description: str | None

The schema’s human-readable US English (long) description.

embed(into: Schema) MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]][source]

Embed this schema.

This is where the raw schema may be enhanced before being returned.

property schema: MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]]

The raw JSON Schema.

property title: str | None

The schema’s human-readable US English (short) title.

validate(data: Any) None[source]

Validate data against this schema.

class betty.json.schema.String[source]

Bases: _Type

A JSON Schema string type.

class Format[source]

Bases: Enum

A JSON Schema string type’s format.

DATE = 'date'
DATE_TIME = 'date-time'
DURATION = 'duration'
EMAIL = 'email'
HOSTNAME = 'hostname'
IDN_EMAIL = 'idn-email'
IDN_HOSTNAME = 'idn-hostname'
IPV4 = 'ipv4'
IPV6 = 'ipv6'
IRI = 'iri'
IRI_REFERENCE = 'iri-reference'
JSON_POINTER = 'json-pointer'
REGEX = 'regex'
RELATIVE_JSON_POINTER = 'relative-json-pointer'
TIME = 'time'
URI = 'uri'
URI_REFERENCE = 'uri-reference'
URI_TEMPLATE = 'uri-template'
UUID = 'uuid'
__init__(*, def_name: str | None = None, title: str | None = None, description: str | None = None, min_length: int | None = None, max_length: int | None = None, pattern: str | None = None, format: Format | None = None)[source]