Bridge between Pydantic V2 models and RDF graphs
Project description
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_rdf-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_rdf-0.1.0.tar.gz
- Upload date:
- Size: 63.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faf6983d8a4c6418c8555875d533e070d41542275711306acf4ccf9ebab3a01d
|
|
| MD5 |
62a91b7927a56015d82bca1d2ef0bc79
|
|
| BLAKE2b-256 |
2017a43597f58ac1cd7b539f11bc09666e9456b0ebec09d26699f08105567362
|
File details
Details for the file pydantic_rdf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_rdf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb6c8e48e93468dfa3fdd17e3c610aca8e0d8cc01af6d226b7bbb50b432cb2e3
|
|
| MD5 |
c72c17967696c8e1f881bb462a6c4c7c
|
|
| BLAKE2b-256 |
999322c28df5c8c6bc54ed3604dbf6394ea4db9f06b97e8ad70d8dc437d362e5
|