Skip to content

About

Pydantic v2 models for parsing, validating, and serializing CodeMeta

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

pydantic-codemeta

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.

Features

  • Typed CodeMeta and schema.org models built on Pydantic v2
  • JSON-LD aliases such as @context, @type, and codeRepository
  • Preservation of unknown JSON-compatible properties
  • Explicit legacy CodeMeta migration without implicit document rewriting
  • Typed CodeMeta 3.0 models with strict @context validation

Requirements

  • Python 3.11 or newer
  • Pydantic 2.x

Installation

python -m pip install pydantic-codemeta

Usage

Parse 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.

Parsing Behavior

  • 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.

Development

Install uv, then create the development environment and run the test suite:

uv sync
uv run python -m pytest -q -s

Build and validate the distribution artifacts:

uv build
uv run twine check dist/*

Docker-based checks are also available:

make docker-test
make docker-package

TestPyPI rehearsal

A 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-test

This runs clean, test, package, check, and publish-test (uploads to TestPyPI). After uploading, verify the package installs from TestPyPI:

make smoke-test

Production PyPI releases are published by the GitHub Actions release workflow using PyPI Trusted Publishing. Do not use make publish for production releases.

Contributing

Contributions are welcome. See CONTRIBUTING.md for development setup, testing, formatting, pull request guidelines, and the release process.

License

pydantic-codemeta is distributed under the MIT License.

About

Pydantic v2 models for parsing, validating, and serializing CodeMeta

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages