betty.json.linked_data module

Provide JSON-LD utilities.

class betty.json.linked_data.JsonLdObject[source]

Bases: Object

A JSON Schema for an object with JSON-LD.

__init__(json_ld_schema: JsonLdSchema, *, def_name: str | None = None, title: str | None = None, description: str | None = None)[source]
final class betty.json.linked_data.JsonLdSchema[source]

Bases: FileBasedSchema

A JSON-LD JSON Schema reference.

async classmethod new() Self[source]

Create a new instance.

class betty.json.linked_data.LinkedDataDumpable[source]

Bases: Generic[_SchemaTypeT, _DumpT]

Describe an object that can be dumped to linked data.

abstractmethod async dump_linked_data(project: Project) _DumpT[source]

Dump this instance to JSON-LD.

abstractmethod async classmethod linked_data_schema(project: Project) _SchemaTypeT[source]

Define the JSON Schema for betty.json.linked_data.LinkedDataDumpable.dump_linked_data().

class betty.json.linked_data.LinkedDataDumpableJsonLdObject[source]

Bases: LinkedDataDumpable[JsonLdObject, MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]], ABC

A betty.json.linked_data.LinkedDataDumpable implementation for object/mapping data.

This is helpful when working with diamond class hierarchies where parent classes that may not be the root class want to make changes to the linked data, and expect an :py:class`betty.json.schema.Object` schema and a betty.serde.dump.DumpMapping dump.

async dump_linked_data(project: Project) DumpMapping[Dump][source]

Dump this instance to JSON-LD.

async classmethod linked_data_schema(project: Project) JsonLdObject[source]

Define the JSON Schema for betty.json.linked_data.LinkedDataDumpable.dump_linked_data().

class betty.json.linked_data.LinkedDataDumpableProvider[source]

Bases: Generic[_T, _SchemaTypeT, _DumpT], ABC

Provide linked data for instances of a target type.

abstractmethod async dump_linked_data_for(project: Project, target: _T) _DumpT[source]

Dump the given target to JSON-LD.

abstractmethod async linked_data_schema_for(project: Project) _SchemaTypeT[source]

Define the JSON Schema for betty.json.linked_data.LinkedDataDumpableProvider.dump_linked_data_for().

betty.json.linked_data.dump_context(dump: 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]]], **context_definitions: str) None[source]

Add one or more contexts to a dump.

Add one or more links to a dump.

async betty.json.linked_data.dump_schema(project: Project, dump: DumpMapping[Dump], linked_data_dumpable: LinkedDataDumpable[Object, DumpMapping[Dump]]) None[source]

Add the $schema item to a JSON-LD dump.