Registries

class schemashift.Registry[source]

Bases: ABC

Abstract base registry for FormatConfig objects.

abstractmethod delete(name)[source]

Remove the config with the given name.

Returns True if the config existed and was removed, False otherwise.

Return type:

bool

abstractmethod get(name)[source]

Return the config with the given name, or None if not found.

Return type:

FormatConfig | None

abstractmethod list_configs()[source]

Return all registered configs.

Return type:

list[FormatConfig]

load_schema(name=None)[source]

Load a target schema associated with this registry, if supported.

Return type:

TargetSchema | None

abstractmethod register(config)[source]

Store a config, replacing any existing config with the same name.

Return type:

None

class schemashift.DictRegistry[source]

Bases: Registry

In-memory registry suitable for testing and embedded use.

delete(name)[source]

Remove the config with the given name.

Returns True if the config existed and was removed, False otherwise.

Return type:

bool

get(name)[source]

Return the config with the given name, or None if not found.

Return type:

FormatConfig | None

list_configs()[source]

Return all registered configs.

Return type:

list[FormatConfig]

load_schema(name=None)

Load a target schema associated with this registry, if supported.

Return type:

TargetSchema | None

register(config)[source]

Store a config, replacing any existing config with the same name.

Return type:

None

class schemashift.FileSystemRegistry(path)[source]

Bases: Registry

Stores configs as JSON files under a directory.

Each config is persisted as {directory}/{name}.json.

delete(name)[source]

Remove the config with the given name.

Returns True if the config existed and was removed, False otherwise.

Return type:

bool

get(name)[source]

Return the config with the given name, or None if not found.

Return type:

FormatConfig | None

list_configs()[source]

Return all registered configs.

Return type:

list[FormatConfig]

load_schema(name=None)[source]

Load a TargetSchema from the schemas/ subdirectory.

If name is provided, loads {schemas_dir}/{name}.yaml (falling back to .yml). If name is None and exactly one schema file exists, returns it. Returns None if the schemas/ directory does not exist, is empty, or the named file is not found.

Raises:

ValueError – If multiple schemas exist and no explicit name is given.

Return type:

TargetSchema | None

register(config)[source]

Store a config, replacing any existing config with the same name.

Return type:

None