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

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.

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.2.tar.gz (374.8 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.2-cp39-abi3-win_amd64.whl (2.8 MB view details)

Uploaded CPython 3.9+Windows x86-64

rete_graph-0.2.2-cp39-abi3-pyemscripten_2026_0_wasm32.whl (926.0 kB view details)

Uploaded CPython 3.9+PyEmscripten 2026.0 wasm32

rete_graph-0.2.2-cp39-abi3-pyemscripten_2025_0_wasm32.whl (974.1 kB view details)

Uploaded CPython 3.9+PyEmscripten 2025.0 wasm32

rete_graph-0.2.2-cp39-abi3-manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

rete_graph-0.2.2-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.2.2-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (5.3 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.2.tar.gz.

File metadata

  • Download URL: rete_graph-0.2.2.tar.gz
  • Upload date:
  • Size: 374.8 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.2.tar.gz
Algorithm Hash digest
SHA256 d71b6fd798e1ff298b0c3c8b547047097a926b54192cd1a70c2e01c8fe338641
MD5 9c880b17a20306e746bdbf2293c3070e
BLAKE2b-256 ca02b759f470989334e1363811ac37b79d01b4dc2cdae09cea896cb74c1bb718

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-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.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.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3ede7857c9d99e620e7b9dd7bc3636c371c601c92bf7040ecacb4bac18b67cf3
MD5 5b50f8e942ef5b17d7f3c35faac24b53
BLAKE2b-256 21de4f49d34868d98aeb8f427b597997a7607faf4c95a9aebb8e70b7abc9d307

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-cp39-abi3-pyemscripten_2026_0_wasm32.whl
  • Upload date:
  • Size: 926.0 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.2-cp39-abi3-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 400af328b76bdab33670b371626f1e02f6859716a3b13157ca11c38c5a769ff9
MD5 b5e804a7fbac13704c113fd009606712
BLAKE2b-256 1952e9e35895f7ea5837bf7b61b0fd63e16070200000383f4666f3a301257ecb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-cp39-abi3-pyemscripten_2025_0_wasm32.whl
  • Upload date:
  • Size: 974.1 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.2-cp39-abi3-pyemscripten_2025_0_wasm32.whl
Algorithm Hash digest
SHA256 2a6c5480fca828a4fff7f3d7d9a9aec8ca95fd1ac2774648b8624fedaf0dbb40
MD5 24cbf07607d2785c31da0ccc0fedf062
BLAKE2b-256 ba390bebaa8205afbbc28b038c351cbee7d9a50d38c9da2910ad0da546e6cacd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-cp39-abi3-manylinux_2_28_aarch64.whl
  • Upload date:
  • Size: 2.7 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.2-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ca06be9479ddaa937870f8cc071eb11d60d32dc52fd883d382b296d6fe70677b
MD5 6231159fc1e2b6a111ce72e10cc5632f
BLAKE2b-256 2cbc5f7017848327f2e5fcee3eb162bb3c251ecc742dc6e61dbdd86b944d5971

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-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.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.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c298a4c3ce580af5c2380aa411718cf63b070b6a59e03a246d1289ef88da9c43
MD5 bdbfb3bb1aed8fec267164555385f0b9
BLAKE2b-256 9515722073988ac77f3e391b33906a7f3850fb48b1b666fe6bcb943cd4a7b44d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.2.2-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
  • Upload date:
  • Size: 5.3 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.2-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 070ad01294e03faefac4b99c7ee2028690af46be105f66f20fbced1c11b9966d
MD5 ebf01ef4e6b4632ae2b83bf4e575969f
BLAKE2b-256 44443d7449f68850b0484584943ce75f316db36c0c45edd6a17ebd8434d1fe79

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