Pydantic v2 models for parsing, validating, and serializing CodeMeta JSON-LD metadata, with typed Python APIs and round-trip preservation of unknown properties.
The package provides a typed representation of common CodeMeta and schema.org terms while preserving unknown JSON-LD properties during round trips.
- Typed CodeMeta and schema.org models built on Pydantic v2
- JSON-LD aliases such as
@context,@type, andcodeRepository - Preservation of unknown JSON-compatible properties
- Explicit legacy CodeMeta migration without implicit document rewriting
- Typed CodeMeta 3.0 models with strict @context validation
- Python 3.11 or newer
- Pydantic 2.x
python -m pip install pydantic-codemetaParse a CodeMeta document into a validated model and serialize it back to JSON-LD:
from pydantic_codemeta import CodeMeta
document = {
"@context": "https://w3id.org/codemeta/3.0",
"@type": "SoftwareSourceCode",
"name": "Example",
"codeRepository": "https://example.org/repository",
}
metadata = CodeMeta.from_jsonld(document)
assert metadata.code_repository == "https://example.org/repository"
assert metadata.to_jsonld()["codeRepository"] == document["codeRepository"]Python attributes use snake_case names. to_jsonld() emits the corresponding
CodeMeta and schema.org aliases.
CodeMeta.from_jsonld()validates canonical CodeMeta 3.0 without rewriting it.CodeMeta.from_legacy_jsonld()explicitly migrates supported legacy forms.- Unknown JSON-compatible properties survive parse and serialization round trips.
See the model specification for the complete field, context, migration, date, collision, and round-trip contracts.
Install uv, then create the development environment and run the test suite:
uv sync
uv run python -m pytest -q -sBuild and validate the distribution artifacts:
uv build
uv run twine check dist/*Docker-based checks are also available:
make docker-test
make docker-packageA full TestPyPI rehearsal builds, validates, and uploads the package without
touching production PyPI. Configure ~/.pypirc with TestPyPI credentials:
[testpypi]
username = __token__
password = pypi-<your-testpypi-token>Then run:
make release-testThis runs clean, test, package, check, and publish-test (uploads to
TestPyPI). After uploading, verify the package installs from TestPyPI:
make smoke-testProduction PyPI releases are published by the GitHub Actions release workflow
using PyPI Trusted Publishing. Do not use make publish for production
releases.
Contributions are welcome. See CONTRIBUTING.md for development setup, testing, formatting, pull request guidelines, and the release process.
pydantic-codemeta is distributed under the
MIT License.