Getting Started: Python
The Python package wraps the same native Rust engine — not a reimplementation — so parsing, serialization, SPARQL, and validation behave identically to the Rust, JavaScript, and C surfaces.
pip install purrdf
Parsing
import purrdf
quads = purrdf.parse(
'<https://example.org/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .',
purrdf.RdfFormat.TURTLE,
)
Validation: SHACL and ShEx
The native validation engines are exposed from the purrdf_native extension
module:
from purrdf_native import shacl, shex
report = shacl.validate(shapes_ttl=my_shapes, data_nt=my_data)
print(report["conforms"])
result = shex.validate(my_schema_shexc, my_data_ttl,
[("https://example.org/alice", "https://example.org/PersonShape")])
print(result["conforms"])
SHACL result dicts keep the stable keys focus, path, value, severity,
component, source_shape, and message. See SHACL
and ShEx for what the engines cover.
rdflib compatibility
The package ships an rdflib compatibility layer:
from purrdf.compat.rdflib import Graph
For a literal, zero-change import rdflib, there is an opt-in extra:
pip install purrdf[rdflib]
This pulls in the separate purrdf-rdflib distribution, whose top-level
rdflib package re-exports the compat surface, so existing third-party code
doing import rdflib / from rdflib.namespace import RDF transparently runs
on purrdf. Caveat: that shadow claims the rdflib import name and must
never be installed alongside the genuine
rdflib — the two cannot co-inhabit one
environment. It is a separate distribution (never bundled into the main
purrdf wheel) precisely so environments that need the real rdflib simply
omit it.
The compat layer is gated in CI against rdflib 7.6’s own vendored test suite plus a first-party differential parity suite — see rdflib Compatibility for details and the known, ledgered divergences.
GTS relational exports
The Python package also ships GTS relational exports for analytics pipelines:
from purrdf import gts_to_sqlite, gts_to_duckdb, gts_to_parquet
These project a GTS container into SQLite, DuckDB, or Parquet tables.
Next steps
- rdflib Compatibility — the drop-in story in depth.
- Validation — SHACL and ShEx from Python.
- GTS Graph Transport — the container format the exports read.