fair_data_schema Python Package#

fair_data_schema — Python tooling for the FAIR Data JSON Schema dialect.

CLI entry point: fair-data-schema (see cli.py)

Schema URI registry.

Maps canonical https://highvaluedata.net/fair-data-schema/ URIs to local file-system paths so that cross-schema $ref resolution works during development without network access, and so that tests are fully offline.

fair_data_schema.registry.all_schemas()[source]#

Return a dict mapping full URIs to parsed schema dicts.

Return type:

dict[str, Any]

fair_data_schema.registry.resolve_uri(uri)[source]#

Resolve a canonical schema URI to a local Path.

Return type:

Path

fair_data_schema.registry.schema_uris()[source]#

Return all registered canonical schema URIs.

Return type:

list[str]

Schema validator.

Wraps jsonschema’s Draft202012Validator with a local referencing.Registry so that cross-schema $ref resolution works offline using the local file mappings defined in registry.py.

fair_data_schema.validator.is_valid_json(path)[source]#

Return True if path contains valid JSON, False otherwise.

Return type:

bool

fair_data_schema.validator.validate(instance, schema)[source]#

Validate instance against schema using the FAIR dialect-aware validator.

Returns a (possibly empty) list of ValidationError objects. Raises nothing — all errors are collected and returned.

Return type:

list[ValidationError]

fair_data_schema.validator.validate_file(schema_path, instance_path=None)[source]#

Validate a schema file (optionally against an instance file).

If instance_path is None, validates the schema itself against the standard JSON Schema 2020-12 meta-schema (i.e. checks the schema is a valid schema document).

Return type:

list[ValidationError]

CLI entry point for fair-data-schema.

Commands:

validate – validate a JSON instance against a schema (or a schema against the meta-schema) lint – check all schema files for JSON syntax validity info – show registered schema URIs

fair_data_schema.cli.info()[source]#

Show registered schema URIs and their local file mappings.

Return type:

None

fair_data_schema.cli.lint(directory=PosixPath('.'))[source]#

Check all JSON files in schemas/ and examples/ for syntax validity.

Return type:

None

fair_data_schema.cli.validate(schema, instance=None)[source]#

Validate a JSON instance against a schema, or a schema against the meta-schema.

Return type:

None

fair_data_schema.cli.version()[source]#

Print the package version.

Return type:

None

FAIR Pydantic Models (Standalone)#

FAIR Data Schema — Pydantic models (auto-generated).

class models.DatasetRelation(**data)[source]#

One relationship entry within fair:datasetRelations.

class models.DatasetSchema(**data)[source]#

Root-level FAIR dataset schema.

Extends SchemaNode with a $schema declaration that defaults to the FAIR dialect URI for version dev.

classmethod from_dict(data)[source]#

Parse a FAIR schema from a plain dictionary.

Return type:

DatasetSchema

classmethod from_file(path)[source]#

Load and parse a FAIR schema from a JSON file.

Return type:

DatasetSchema

classmethod from_json(text)[source]#

Parse a FAIR schema from a JSON string.

Return type:

DatasetSchema

to_file(path, indent=2)[source]#

Write this schema to a JSON file.

Return type:

None

models.I18nString = str | dict[str, str]#

“Âge”}.

Type:

A string or a BCP-47 language-mapped dict, e.g. {“en”

Type:

“Age”, “fr”

models.I18nText = str | dict[str, str]#

A Markdown-formatted string or a language-mapped dict of Markdown strings.

models.JsonType#

Valid JSON Schema type values.

alias of Literal[‘string’, ‘integer’, ‘number’, ‘boolean’, ‘array’, ‘object’, ‘null’]

class models.SchemaNode(**data)[source]#

A node in a FAIR-extended JSON Schema document.

Covers the full JSON Schema Draft 2020-12 vocabulary (all seven vocabularies declared in the FAIR dialect) plus FAIR annotation extensions.

All FAIR extension fields use the fair_ prefix to mirror the fair: JSON prefix and to prevent any naming collision with standard JSON Schema keywords, both present and future.

to_dict()[source]#

Serialise to a FAIR JSON Schema dict (fair: prefixed keys, no nulls).

Return type:

dict[str, Any]

to_json(indent=2)[source]#

Serialise to a FAIR JSON Schema string.

Return type:

str

class models.TemporalCoverage(**data)[source]#

Time period covered by the dataset (fair:temporalCoverage).