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

Uploaded CPython 3.9+Windows x86-64

rete_graph-0.1.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.1.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.1.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.1.0.tar.gz.

File metadata

  • Download URL: rete_graph-0.1.0.tar.gz
  • Upload date:
  • Size: 341.7 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.1.0.tar.gz
Algorithm Hash digest
SHA256 32da3360f12e664ed636d49c5ddee58e007bd737a19c32438a0fca2ad314e71a
MD5 ded704b63955d1f5a18afcf06c4fe777
BLAKE2b-256 1024f13b1e681c1fadf872af243046dae826a59f3ea66af82e36d5d20709d525

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.1.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.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b7dbf1600222098bdf4f8970e753470bf74fe4da1178fb75afdd0be672f750b7
MD5 6239a01617980ccb6d42837eace24e4f
BLAKE2b-256 4cf396d1fa84163d093120b9089387543ad9fda65cbe30c1ce8db70f06562910

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.1.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.1.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e3038613f45d81c692d3767ea0ccf6ffdb678e43287ba164e8bdfa1ed34cf8f4
MD5 eb04d3dddcd4ef1dc5b8afe25bad9782
BLAKE2b-256 4360dd8b8644a35a08ef0c7b53f021724beea67f1c60abd37202ebdddba892fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.1.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.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7bfac29fd8ad1e3fd5306e91f2d84d2ebd78fd6222ebbd84d7e9eb0ca0a2e12f
MD5 fe8ec632409c81f840b014ac563850d3
BLAKE2b-256 ffa93e7a99387273ff276492bcbf7aaa6e329c3dd7109adbba3b9b64fb3fa0b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rete_graph-0.1.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.1.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 27c9dfcb63414ef43ef9bdfc08398238fa131d09db4892f283e7d46c156c6c0a
MD5 b2361f65ef54413ed638744e69a74ee8
BLAKE2b-256 dde10c53ee042b4b37fc2c84ba1be65fe3f22a159646305f831fa557342b3186

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