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")
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.

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.

Download files

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

Source Distribution

rete_graph-0.3.1.tar.gz (402.7 kB view details)

Uploaded Source

Built Distributions

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

rete_graph-0.3.1-cp39-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.9+Windows x86-64

rete_graph-0.3.1-cp39-abi3-pyemscripten_2026_0_wasm32.whl (925.5 kB view details)

Uploaded CPython 3.9+PyEmscripten 2026.0 wasm32

rete_graph-0.3.1-cp39-abi3-pyemscripten_2025_0_wasm32.whl (979.2 kB view details)

Uploaded CPython 3.9+PyEmscripten 2025.0 wasm32

rete_graph-0.3.1-cp39-abi3-manylinux_2_28_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

rete_graph-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

rete_graph-0.3.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (5.4 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file rete_graph-0.3.1.tar.gz.

File metadata

  • Download URL: rete_graph-0.3.1.tar.gz
  • Upload date:
  • Size: 402.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1.tar.gz
Algorithm Hash digest
SHA256 699a13ff23cba29492a4b88bc2fcd94a34028ebe78f86b599dc7d35ced214968
MD5 b2529ca5b80825d1d031a893b389177c
BLAKE2b-256 95c90ab1853b30002d8e7da7171e79ed7c51f97ea378cac6533129c7356ea7ab

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6509822d419d36fea387d46b83971cace0fce61ee80c29ddf6c1e3769950ebeb
MD5 e99b558ab412e81b54ae74e4cb17e1e8
BLAKE2b-256 269eb1cd8f89972853b4ee0d50448d4169e8fa87d82814dea8372e6b5b3a7975

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-pyemscripten_2026_0_wasm32.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-pyemscripten_2026_0_wasm32.whl
  • Upload date:
  • Size: 925.5 kB
  • Tags: CPython 3.9+, PyEmscripten 2026.0 wasm32
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 37e194f44bc415a4b0efba186461dbc5e5bb5e4f42bee75dd93bf5c7db224c2e
MD5 c6c46abb09fe70f03f173ad7bedef0eb
BLAKE2b-256 69c9559026816ae5d9055a7c0c2c9b26991c5471743f14b6c8730e7b8d55fdd1

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-pyemscripten_2025_0_wasm32.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-pyemscripten_2025_0_wasm32.whl
  • Upload date:
  • Size: 979.2 kB
  • Tags: CPython 3.9+, PyEmscripten 2025.0 wasm32
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-pyemscripten_2025_0_wasm32.whl
Algorithm Hash digest
SHA256 b9a8ca03c370aa93b386f63cdf7449e7f75114710973b5155b2ad047679a915c
MD5 5a7498493a97bf51033a2dc303dec706
BLAKE2b-256 a396870daf166e80c9302c22f4e3a4fb99e1003e231645d718de035acb8a516e

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 94b756cb2b270b0aa742f64e2c143d2b4dcf930cfc2546f14c999109e7b6057e
MD5 da5ec787909ded58a08d7d217f8b1f07
BLAKE2b-256 a7574a91edcdd5f258ee68e333dde25f94299f3b97406879eed86f3f5db3d9d9

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c9e92cb4872e3caece6803d92977c3672be5a9e624d369370fb58f743d0aabd4
MD5 3197dc00b0eaacda22e41d13546a2709
BLAKE2b-256 61194a5ede18712218551668d716f0c1a93a77fa3c3c2327b905587c12d7e587

See more details on using hashes here.

File details

Details for the file rete_graph-0.3.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

  • Download URL: rete_graph-0.3.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.9+, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.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}

File hashes

Hashes for rete_graph-0.3.1-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 60247d7763de99814705a198bc015e99ab6ececfdab781beec4ba57385cbd48f
MD5 f011a3521091efd2d09ca866a0b5b04e
BLAKE2b-256 32539eb8250f73bd8670d74efd9a5a3e45521761f144064031d812536c749e12

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.2

7 files

This release

0.3.1 This release

7 files

0.3.0

7 files

0.2.3

7 files

0.2.2

7 files

0.2.1

7 files

0.2.0

7 files

0.1.0

5 files

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