A Python library that bridges Pydantic V2 models and RDF graphs, enabling seamless bidirectional conversion between typed data models and semantic web data. PydanticRDF combines Pydantic's powerful validation with RDFLib's graph capabilities to simplify working with linked data.
Features
- ✅ Type Safety: Define data models with Pydantic V2 and map them to RDF graphs
- 🔄 Serialization: Convert Pydantic models to RDF triples with customizable predicates
- 📥 Deserialization: Parse RDF data into validated Pydantic models
- 🧩 Complex Structures: Support for nested models, lists, and circular references
- 📊 JSON Schema: Generate valid JSON schemas from RDF models with proper URI handling
Installation
pip install pydantic-rdf
Quick Example
from rdflib import Namespace
from pydantic_rdf import BaseRdfModel, WithPredicate
from typing import Annotated
# Define a model
EX = Namespace("http://example.org/")
class Person(BaseRdfModel):
rdf_type = EX.Person
_rdf_namespace = EX
name: str
age: int
email: Annotated[str, WithPredicate(EX.emailAddress)]
# Create and serialize
person = Person(uri=EX.person1, name="John Doe", age=30, email="john@example.com")
graph = person.model_dump_rdf()
# The resulting RDF graph looks like this:
# @prefix ex: <http://example.org/> .
# @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
#
# ex:person1 a ex:Person ;
# ex:age 30 ;
# ex:emailAddress "john@example.com" ;
# ex:name "John Doe" .
# Deserialize
loaded_person = Person.parse_graph(graph, EX.person1)
Requirements
- Python 3.11+
- pydantic >= 2.11.3
- rdflib >= 7.1.4
Documentation
For complete documentation, visit https://omegaice.github.io/pydantic-rdf/
License
MIT
Metadata
Release files for pydantic-rdf 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_rdf-0.2.0.tar.gz | 67.4 kB | Without provenance | Details for pydantic_rdf-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_rdf-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pydantic_rdf-0.2.0-py3-none-any.whl |
Total release size: 76.2 kB
Release files / pydantic_rdf-0.2.0.tar.gz
| Download URL | pydantic_rdf-0.2.0.tar.gz |
|---|---|
| Size | 67.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1d9055cb6957f85957af6855fe7d99ded59025e2ac4fa35a5ca8e922ec9117f
|
|
BLAKE2b-256 checksum How to use checksums |
9a5a1231b6e90cff4ddb6fa44c159593af737b45dc1d4738c63faa33ebe0e0be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.2
|
Release files / pydantic_rdf-0.2.0-py3-none-any.whl
| Download URL | pydantic_rdf-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
603b3b62b00970655c87bc4b7b3fa415679ffb585d4b8605127ecb4d20f1ad5c
|
|
BLAKE2b-256 checksum How to use checksums |
51e4ad85698626ec4d6d8ee3cd569a78191ef7ab1d6d729a346dadd6d445429f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.7.2
|
Security for pydantic-rdf 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.