Weblate Schemas
A collection of JSON schemas used by Weblate for various objects and APIs. This library provides a programmatic way to access and retrieve these schemas as Python dictionaries, often used in conjunction with the `jsonschema` library for validation. It follows a calendar versioning scheme (YYYY.M) with regular monthly releases.
Common errors
-
KeyError: 'non_existent_schema.json'
cause You attempted to retrieve a schema using `get_schema('non_existent_schema.json')` with a name that either does not exist or has a typo (case sensitivity matters).fixFirst, list all available schemas using `from weblate_schemas import list_schemas; print(list_schemas())` to verify the correct schema name. Then, call `get_schema()` with the exact, correct name. -
ModuleNotFoundError: No module named 'weblate_schemas'
cause The `weblate-schemas` package has not been installed in your current Python environment, or the environment is not activated.fixInstall the package using pip: `pip install weblate-schemas`. If using virtual environments, ensure your environment is activated before running your Python script.
Warnings
- breaking The *structure* of specific schemas (e.g., fields, types, required properties) can change between versions. While the `get_schema` Python API remains stable, applications validating against older schema definitions may break with new schema versions.
- gotcha Schema names are case-sensitive and must exactly match the internal registry (e.g., 'component.json' vs 'Component.json'). Requesting a non-existent schema will raise a `KeyError`.
- gotcha This library uses calendar versioning (YYYY.M), meaning new versions are released monthly. This implies frequent updates to schema definitions, which can introduce changes to existing schemas or add new ones.
Install
-
pip install weblate-schemas
Imports
- get_schema
from weblate_schemas import get_schema
- list_schemas
from weblate_schemas import list_schemas
Quickstart
from weblate_schemas import get_schema, list_schemas
import json
# List available schemas
available_schemas = list_schemas()
print(f"Available schemas: {available_schemas[:3]}...")
# Retrieve a specific schema (e.g., component.json)
try:
component_schema = get_schema('component.json')
print(f"\nSuccessfully loaded 'component.json' schema. First 100 chars:\n{json.dumps(component_schema, indent=2)[:100]}...")
except KeyError:
print("\n'component.json' not found. Please check available schemas.")
# Example of how you might use it with jsonschema (requires pip install jsonschema)
# from jsonschema import validate, ValidationError
# data_to_validate = {"name": "My Component", "slug": "my-component"}
# try:
# validate(instance=data_to_validate, schema=component_schema)
# print("\nData is valid against 'component.json' schema.")
# except ValidationError as e:
# print(f"\nData validation failed: {e.message}")