Metadata-Version: 2.4
Name: pydantic-jsonld
Version: 0.1.0
Author-email: Moritz Eckert <MoritzEckert@web.de>
License: MIT
Project-URL: Homepage, https://github.com/Moritz72/pydantic-jsonld
Project-URL: Repository, https://github.com/Moritz72/pydantic-jsonld
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: annotated-types>=0.6.0
Requires-Dist: pydantic>=2.0
Requires-Dist: typing-extensions>=4.15.0
Provides-Extra: dev
Requires-Dist: mkdocs>=1.5; extra == "dev"
Requires-Dist: mkdocs-material>=9.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: pymdown-extensions>=10.0; extra == "dev"
Requires-Dist: pytest>=7.2; extra == "dev"
Requires-Dist: pytest-cov>=7.0; extra == "dev"
Requires-Dist: ruff>=0.14; extra == "dev"
Dynamic: license-file

# pydantic-jsonld

[![CI](https://github.com/Moritz72/pydantic-jsonld/actions/workflows/ci.yml/badge.svg)](https://github.com/Moritz72/pydantic-jsonld/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/Moritz72/pydantic-jsonld/branch/main/graph/badge.svg)](https://codecov.io/gh/Moritz72/pydantic-jsonld)
[![Python 3.11](https://img.shields.io/badge/python-3.11+-blue)](https://img.shields.io/badge/python-3.11+-blue)
[![uv](https://img.shields.io/badge/dependency%20manager-uv-blue)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/badge/linting-ruff-blue)](https://github.com/astral-sh/ruff)
[![mypy](https://img.shields.io/badge/types-mypy-blue)](https://github.com/python/mypy)
[![MkDocs](https://img.shields.io/badge/docs-mkdocs-blue)](https://www.mkdocs.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

`pydantic-jsonld` is a light-weight Python package that aims to make use of
[pydantic](https://pydantic.dev/docs/validation/latest/get-started/)
for [JSON-LD](https://json-ld.org) data.

**What this is not**:
This package offers no functionality for compaction or expansion.
Neither does it parse any given context.

## Installation

```bash
pip install pydantic-jsonld
```

## Documentation

See [Pydantic JSON-LD Docs](https://moritz72.github.io/pydantic-jsonld/).

## Structure

This package offers two `BaseModel` implementations derived from pydantic.
One for working with compacted JSON-LD data and one for expanded JSON-LD data.

Since there is no implementation of context parsing,
the compacted model includes several limitations.

This is, however, a design choice as to avoid the necessity of fetching external contexts
as well as the heavy computation that comes with validating JSON-LD data.

## Usage

For the most basic usage, see the following example

```python
from pydantic_jsonld.compact import BaseModel, Value


# Define a model
class MyModel(BaseModel):
    height: Value[float]
    length: Value[float]


# Build an instance from JSON-LD data
data = {
    "@context": {"@vocab": "http://www.example.org/"},
    "height": 20.0,
    "length": 10.0,
}
model = MyModel.model_validate(data)

# Access via model properties
assert model.height.value == 20.0
assert model.length.value == 10.0

# Recover the original data
dumped = model.model_dump(by_alias=True, exclude_none=True)
assert dumped == data
```

## License

This project is licensed under the [MIT License](LICENSE).
