Skip to main content

Query local and remote .rete graph files with SPARQL — Python bindings for the rete engine.

Project description

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

A runnable tour with captured outputs lives in examples/tutorial.ipynb.

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.

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.

Project details


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.2.0.tar.gz (343.3 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.2.0-cp39-abi3-win_amd64.whl (2.6 MB view details)

Uploaded CPython 3.9+Windows x86-64

rete_graph-0.2.0-cp39-abi3-pyemscripten_2026_0_wasm32.whl (978.4 kB view details)

Uploaded CPython 3.9+PyEmscripten 2026.0 wasm32

rete_graph-0.2.0-cp39-abi3-pyemscripten_2025_0_wasm32.whl (902.8 kB view details)

Uploaded CPython 3.9+PyEmscripten 2025.0 wasm32

rete_graph-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

rete_graph-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

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

rete_graph-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (5.1 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.2.0.tar.gz.

File metadata

  • Download URL: rete_graph-0.2.0.tar.gz
  • Upload date:
  • Size: 343.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0.tar.gz
Algorithm Hash digest
SHA256 59144e641c67f20a369703847188291fa7cc267e61baf9b1e026852f752aea9e
MD5 7546f3962b4524ea70187df6126da7a1
BLAKE2b-256 e7a618995099fb2db8ecefc32991259d2c2e1a69b4be3fe487533c2cd0b7c0e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f99ef07913482f9853034833ca56d72c8796ab36d8fc02fd2f9d516c67696122
MD5 7eaf260e343fc9a4b3ea5919fcdf0cbc
BLAKE2b-256 b7d1e00fccbd7c1f5f3081a2ce9bf1928582a6a7381a679259bdd4f502d7f53f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-pyemscripten_2026_0_wasm32.whl
  • Upload date:
  • Size: 978.4 kB
  • Tags: CPython 3.9+, PyEmscripten 2026.0 wasm32
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 73a57bd5bdf155fcae2650c01f8f1d951c676e5d42dcda33b20c0ab2905e86f1
MD5 31de65e3ee19ea1b1d8b6d26f231845b
BLAKE2b-256 3e3c786b26f5619bbd3082b7d914a603316c014b2c92f84efdfbfdcad14c59fb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-pyemscripten_2025_0_wasm32.whl
  • Upload date:
  • Size: 902.8 kB
  • Tags: CPython 3.9+, PyEmscripten 2025.0 wasm32
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-pyemscripten_2025_0_wasm32.whl
Algorithm Hash digest
SHA256 0b489179d6eee72bf1e7b52ccb7802424a7aa10cfdd5ea1c3f3e60069400d41c
MD5 5fdb740d8f9f567d83bddeea0eccbeba
BLAKE2b-256 bb6cba5f0b51cdaed8689cf40cea25697635fc820a99284704c0b9be5fa15ac8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 773ce0a7dce6f02f0c9b692361cc25668f0e9b87db425ccb785a5a43e2d23c84
MD5 7ecedb1a99e54f90e90421c17311c59f
BLAKE2b-256 b49200685cd2411557bbb0b3e10be83e5286ceb2726095f3f708df2fcafed8d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 82301d40c565db0d9224afb9f1ab93e991925002ca35e85c03265940f0bd3106
MD5 02f38a6de4f1be4ad337d4fa0805edde
BLAKE2b-256 825edaf5648d04ee69fafd81555bca4cb57c12738cba5012df67f0210e25a2d9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
  • Upload date:
  • Size: 5.1 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.11.29 {"installer":{"name":"uv","version":"0.11.29","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.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 17b5b6a5930e8b525204a88601976bb7a393bc269e6465c1310b100864ae64e5
MD5 aa0e22bf4a1d6aac92461d271285c53b
BLAKE2b-256 1408e0263ac7759ce4cbb87794083ae94dc2e918b0750b8c172cf000d1e77c90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page