Skip to main content

No project description provided

Project description

pydantic-jsonld

CI codecov Python 3.11 uv Ruff mypy MkDocs License: MIT

pydantic-jsonld is a light-weight Python package that aims to make use of pydantic for JSON-LD data.

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

Installation

pip install pydantic-jsonld

Documentation

See Pydantic JSON-LD Docs.

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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_jsonld-0.1.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_jsonld-0.1.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_jsonld-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_jsonld-0.1.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydantic_jsonld-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dcb029a8ef03d4d76147de2a34a37b22abe35b46bc6ab25c486b937da70b61e7
MD5 060d46f780a4a331d55e362aadfc5ed6
BLAKE2b-256 b49278725c4c5e91f8843c0ba5a90364e90d3129788339099b060716e2fdaa8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_jsonld-0.1.0.tar.gz:

Publisher: publish.yml on Moritz72/pydantic-jsonld

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pydantic_jsonld-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_jsonld-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pydantic_jsonld-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 578c6af0662e0f3532bb04f0ca8416c6a83bf5bc7f6aaed7da61263c55930d92
MD5 67ac762f75b996ad80f853634612b970
BLAKE2b-256 738f80c7b04321644a2e8b8291da9e673eb7284b3829c3f726e976d2cfa04f14

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_jsonld-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Moritz72/pydantic-jsonld

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page