Skip to main content

rete-graph — Python client for .rete files

Query local and remote .rete graph files with SPARQL from Python. A .rete file is a single, immutable, range-queryable RDF graph file (rete): drop it on any HTTP host that supports Range requests and query it in place — the client fetches only the byte ranges a query touches, never the whole file.

These are native bindings (PyO3) to the same Rust engine that powers the rete CLI and the browser playground.

Install

uv pip install rete-graph        # or: pip install rete-graph

Wheels cover Linux (x86_64/aarch64), macOS, Windows — and, from 0.2.0, browser Python: in JupyterLite or marimo's WASM playground, %pip install rete-graph resolves a Pyodide (PyEmscripten) wheel and remote graphs are queried over sync-XHR range requests, no server anywhere.

A runnable tour with captured outputs lives in examples/tutorial.ipynb, and examples/agents/ turns a graph into agent tools for LangChain and Pydantic AI.

Use

import rete_graph as rete

# Remote: lazy HTTP range reads — a selective query over a multi-GB file
# fetches KBs. Any S3/R2/CDN/GitHub URL with Range + CORS works.
g = rete.open("https://data.graphplaza.com/boe/boe.rete")

rows = g.query("""
    SELECT ?s ?label WHERE {
        ?s <http://www.w3.org/2000/01/rdf-schema#label> ?label
    } LIMIT 10
""")
for row in rows:
    print(row["s"].value, "→", row["label"].to_python())

print(g.stats())   # {'fileLength': ..., 'bytes': ..., 'requests': ...}

query() returns {variable: Term} rows for SELECT, a bool for ASK, and (s, p, o) triples for CONSTRUCT/DESCRIBE. A Term carries .kind / .value / .datatype / .lang, plus .to_python() (int/float/bool for common XSD types) and .n3.

More:

g = rete.open("data/example.rete")            # local file, opened lazily too
g = rete.open(rete.build(nt_text))            # build a graph in memory ("nt"/"nq"/"ttl"/"trig"/"rdfxml")
g = rete.open(rete.build(rdflib_graph))       # or straight from an rdflib Graph/Dataset
g = rete.open(url, headers={"Authorization": "Bearer ..."})   # authed hosts

g.examples()                                  # SPARQL examples embedded in the file — run as-is
g.query(q, reason=True)                       # OWL 2 QL entailment (query rewriting)
g.query_df("SELECT ...")                      # pandas DataFrame (pip install rete-graph[pandas])
g.schema()                                    # class/predicate profile
g.prefix_search("Berl")                       # label autocomplete
g.text_search("volcano eruption")             # full-text (files built with --text-index)
g.info(), g.quads, g.content_hash()

SPARQL 1.1 SERVICE federation works out of the box — join a .rete file against any public SPARQL endpoint in one query.

Stream every quad out

iter_quads() is a generator over the whole dataset — default graph first, then each named graph — walked in batches, so peak memory is bounded by one batch no matter how big the file is:

for s, p, o, graph in g.iter_quads():        # N-Triples term tokens; graph is
    ...                                      # None for the default graph

to_nquads() serializes the same walk to a path or any open stream, which is what makes handing a .rete to another RDF toolchain a three-liner:

g.to_nquads("out.nq")                        # or a StringIO / gzip.open(...) / sys.stdout
store = pyoxigraph.Store()
store.bulk_load(path="out.nq", format=pyoxigraph.RdfFormat.N_QUADS)

Measured on figshare.rete (221 MB, 15.9 M quads): to_nquads streams the whole file in 941 MiB peak RSS in 25 s, of which only ~20 MiB is the batch — the rest is the engine's faulted index/dictionary, and it is flat in the quad count. list(g.iter_quads()) on the same file needs many GB, and rete export needs > 1.1 GiB. Pass batch_size= to trade: a small batch makes a peek at a remote graph much cheaper (5 quads for 1.1 MB of range reads at batch_size=1, versus 44 MB at the default 10 000), a large one speeds up a full walk. Scope with graph=: rete.DEFAULT_GRAPH for the unnamed default graph alone, or an IRI for one named graph.

RDF 1.2 and quoted triples

The same --quoted-triple-syntax vocabulary and defaults as the CLI, in both directions:

# Reading: what Turtle/TriG `<< s p o >>` means. "rdf-star" (default) = a quoted
# triple, as before; "rdf12" = RDF 1.2 (`<<( s p o )>>` triple terms, `<< … >>`
# reifiers, `{| … |}` annotations). N-Triples/N-Quads/RDF-XML ignore it.
g = rete.open(rete.build(ttl_text, "ttl", quoted_triple_syntax="rdf12"))
rete.Builder().add_file("data.trig", quoted_triple_syntax="rdf12")

# Writing: to_nquads spells a quoted triple as the RDF 1.2 triple term
# `<<( s p o )>>` by default, which pyoxigraph / Oxigraph 0.5 and Jena 5 read;
# "rdf-star" writes rete's stored `<<s p o>>`. RDF 1.2 has no subject-position
# triple term, so such a statement raises ValueError under "rdf12".
g.to_nquads("out.nq")                                    # rdf12
g.to_nquads("out.nq", quoted_triple_syntax="rdf-star")

# The card says whether a file holds any, from its header (so old files answer):
g.card()["signals"]["quoted_triples"]
# {"present": True, "export_surfaces": ["rdf12", "rdf-star"], "export_default": "rdf12"}

The Pyodide wheel has no RDF 1.2 Turtle/TriG reader and refuses quoted_triple_syntax="rdf12" for those formats by name.

Prepare a .rete step by step

The lazy Builder configures a build — sources, embedded Dataset Card, pyramid, full-text index — then run() / export():

builder = (
    rete.Builder()
    .add_file("people.ttl")                    # or .add(text) / .add(rdflib_graph)
    .card(title="People", license="CC0-1.0", created="2026-07-16")
    .pyramid(algo="louvain")                   # or "types", or .pyramid(False)
    .text_index()
)
builder.run()                                  # bytes; counts in builder.stats
builder.export("people.rete")                  # immutable, host-anywhere file
builder.graph().card()                         # read the embedded card back

See the "Python: build a .rete" tutorial in the docs for the full walkthrough.

Custom storage (fsspec, S3, GCS, …)

Anything that can serve byte ranges can back a graph — pass an object with read_at(offset, length) -> bytes and len():

import fsspec, rete_graph as rete

class FsspecReader:
    def __init__(self, url, **kw):
        self.f = fsspec.open(url, "rb", **kw).open()
        self.size = self.f.size
    def len(self):
        return self.size
    def read_at(self, offset, length):
        self.f.seek(offset)
        return self.f.read(length)

g = rete.open(reader=FsspecReader("s3://my-bucket/data.rete", anon=False))

Building from source

The package is a maturin project; the repo convention is to build in Docker (nothing on the host):

# from the repository root
docker run --rm -v "$PWD":/io ghcr.io/pyo3/maturin build \
    --release -m clients/python/Cargo.toml --out clients/python/dist

uv pip install clients/python/dist/*.whl

Tests: uv pip install pytest && pytest clients/python/tests.

Wheels are abi3 (>= 3.9): one wheel per platform covers every CPython. Releases are published to PyPI by .github/workflows/python-client-publish.yml on a py-v* tag.

Metadata

Release files for rete-graph 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rete-graph 0.3.5
File Size Uploaded Provenance Actions
rete_graph-0.3.5.tar.gz 675.4 kB Without provenance Details for rete_graph-0.3.5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for rete-graph 0.3.5
File Actions
rete_graph-0.3.5-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for rete_graph-0.3.5-cp39-abi3-win_amd64.whl
rete_graph-0.3.5-cp39-abi3-pyemscripten_2026_0_wasm32.whl CPython 3.9 abi3 PyEmscripten 2026.0+ WebAssembly Details for rete_graph-0.3.5-cp39-abi3-pyemscripten_2026_0_wasm32.whl
rete_graph-0.3.5-cp39-abi3-pyemscripten_2025_0_wasm32.whl CPython 3.9 abi3 PyEmscripten 2025.0+ WebAssembly Details for rete_graph-0.3.5-cp39-abi3-pyemscripten_2025_0_wasm32.whl
rete_graph-0.3.5-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details for rete_graph-0.3.5-cp39-abi3-manylinux_2_28_aarch64.whl
rete_graph-0.3.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for rete_graph-0.3.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
rete_graph-0.3.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.9 abi3 macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) Details for rete_graph-0.3.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 18.4 MB

Release files / rete_graph-0.3.5.tar.gz

Download URL rete_graph-0.3.5.tar.gz
Size 675.4 kB
Tags Source
SHA-256 checksum
How to use checksums
96b3497be973d2c30590dd86de8a1fbc0417cb914793f2f1bf3b942ed6e4120d
BLAKE2b-256 checksum
How to use checksums
3f8bbebb7a5c4546d11084cf33622c6cfc9a654c106ed198cf075b880290ec1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-win_amd64.whl

Download URL rete_graph-0.3.5-cp39-abi3-win_amd64.whl
Size 3.0 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
31f116c0f6d8b2b56060cfc5760f52516b38b6e5a246941cd1ddecb804e38350
BLAKE2b-256 checksum
How to use checksums
202c93cd8d770bfcee9801be2f0dba58f04a5ecd663e299d88e77a81ba5b7ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-pyemscripten_2026_0_wasm32.whl

Download URL rete_graph-0.3.5-cp39-abi3-pyemscripten_2026_0_wasm32.whl
Size 1.0 MB
Tags CPython 3.9 PyEmscripten 2026.0+ WebAssembly abi3
SHA-256 checksum
How to use checksums
6e1afff45cb78da52bd7bbb0b9a7d82e7207655ab682c23d49d63180a9d21318
BLAKE2b-256 checksum
How to use checksums
35138aa5275ef2c71a4e8aee05cf1db2621bdf1d32a0d5fa96e56d8f986b4752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-pyemscripten_2025_0_wasm32.whl

Download URL rete_graph-0.3.5-cp39-abi3-pyemscripten_2025_0_wasm32.whl
Size 1.1 MB
Tags CPython 3.9 PyEmscripten 2025.0+ WebAssembly abi3
SHA-256 checksum
How to use checksums
4ec50321b1a1cfe714cee11c9d2141ea599d1ecbeb0ecc63d1a0f64c72029551
BLAKE2b-256 checksum
How to use checksums
2f7cd657729a1d4d4ae1bc61461511464926c6869f11b332cc6f5bd6fd7be944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL rete_graph-0.3.5-cp39-abi3-manylinux_2_28_aarch64.whl
Size 3.1 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
516ab7c98eacf71b9d8f9804a9624c6a77697bcb41e0c60b056bfb4d922201d6
BLAKE2b-256 checksum
How to use checksums
78262467b755e1a3c11e7f89f767a6779f7f8ce48ae0510f6cdaf0475a3e7f15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rete_graph-0.3.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
6a921e2a85df6e077c3fc139ed96c0b6845a47acef2d3036a46be151cda31c8b
BLAKE2b-256 checksum
How to use checksums
238270759e3745a1491a533e43c1d3ca46782e6e056f7d025c9cb559ba0c0a92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / rete_graph-0.3.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL rete_graph-0.3.5-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 6.1 MB
Tags CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e1b8211c3830511b1b86271c75e37acfe38cf04c97aa6fe18e65e17f1a1845eb
BLAKE2b-256 checksum
How to use checksums
c61d8ee0addbccc9622aef98aa9435972a90c273d34d2fef7f7d5d812454f2f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for rete-graph 0.3.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page