Skip to main content

ghost-graph

The name is a nod to The Ghost Map (Steven Johnson, 2006): in 1854 John Snow mapped the Broad Street cholera deaths and found the pump nobody could see. A ghost graph holds the shape of the connections, while the data stays in the systems that own it until a question asks for it. "Ghost" means the data is not here, not that the answer is not grounded: every value an answer shows is fetched from its source and cited.

Keys and edges of an ontology's relationships, held in compressed sparse rows and walked in memory. This is the topology tier of the Contextual Data Fabric (CDF ADR-0011, module M13).

It holds no property values. A walk returns canonical keys, and the caller fetches whatever values its answer shows from the sources that own them.

  • Named in the ontology. Every class and relationship is registered by IRI, and a built Topology carries the manifest contentHash it was built against.
  • One id per entity. Classes that share a canonical key share a key space. Class membership is a bitmap, and a superclass includes its subclasses' members.
  • SPARQL's two semantics. expand (fixed hops) returns one row per path; reachable (+ / *) returns each (start, end) pair once.
  • Refuses, never truncates. A walk over its limit raises TopologyLimitExceeded. A foreign key that points at nothing is dropped and counted in relationship_stats.

The CSR core is graph_builder, pinned exactly, and connected components are the same project's graph crate, pinned the same way; this crate owns the API above them. PageRank is ghost-graph's own, so its scores repeat exactly and match the usual PageRank.

Install

pip install ghost-graph

Wheels are built for Linux (x86_64, aarch64) and macOS (x86_64, arm64), for Python 3.11 and later; elsewhere pip builds from source, which needs Rust. Releases are described in RELEASE.md.

Use

from ghost_graph import TopologyBuilder

b = TopologyBuilder(manifest_hash, as_of)
b.add_class("urn:c#Account", "account", ["a1", "a2"])
b.add_class("urn:c#Contact", "contact", ["c1"])
b.add_relationship("urn:c#contactsToAccounts", "urn:c#Contact", "urn:c#Account", [("c1", "a1")])
t = b.build()
t.expand("urn:c#Contact", ["c1"], [("urn:c#contactsToAccounts", "out", None)], limit=1000)

# From every Contact, landing only on accounts a source has already filtered:
t.expand("urn:c#Contact", None, [("urn:c#contactsToAccounts", "out", None, ["a1"])], limit=1000)

None for the start keys walks from every member of the start class; an empty list matches nothing. A step's optional fourth element (and reachable's target_keys) narrows where the walk lands. Those keys are read in the landing class's key space, so a key from another key space matches nothing.

A walk's limit counts its starts as well as its rows (expand) or pairs (reachable), so a whole-class walk on a class larger than the limit is refused before it starts.

limit bounds what a walk returns and holds, not how much it reads: a hop reads every neighbour of the paths it extends, landing or not, and each start of reachable searches everything it can reach, whether or not it lands on target_keys. The keyword-only max_visits bounds that work: for expand and expand_columns, every neighbour a hop reads, over all hops; for reachable, every node a search visits (its start, then each node it reaches for the first time), over all starts. A walk that would make more visits raises TopologyLimitExceeded before it reads them. The default, None, sets no budget. A budget never changes an answer: the walk returns what it would without one, or is refused.

t.reachable("urn:c#Account", None, "urn:c#parentAccount",
            target_keys=["a3"], limit=1000, max_visits=1_000_000)

Classes and subclass links come before the first relationship, which makes class membership final; one added after it is refused. A relationship's pairs can then arrive in batches (extend_relationship) and build exactly as if added at once.

Analytics

PageRank, weakly connected components and shortest paths run over one class's members and the edges of one or more relationships between them (CDF M13 FR-8):

ranks, iterations, error = t.page_rank("urn:c#Account", ["urn:c#parentAccount"], limit=1_000_000)
components = t.connected_components("urn:c#Account", ["urn:c#parentAccount"], limit=1_000_000)
paths = t.shortest_paths("urn:c#Account", ["urn:c#parentAccount"], "a1", limit=1_000_000)
  • Nodes are every member of the class, including members no edge touches, so PageRank's node total and the components of one are right. Edges are the relationships' pairs with both ends members, so a subclass gets the subgraph its members induce. A pair held by two of the relationships is one edge; a pair (u, u) is a self-loop and is kept.
  • Every relationship must run from the class's key space to itself. Between two key spaces an id names two different entities, and one graph over both would join them; that is refused.
  • PageRank is directed: a relationship given as its IRI is followed from domain to range, or give (iri, "in") to reverse it. The defaults are damping=0.85, max_iterations=20, tolerance=1e-4. Scores come back as (key, score) in the class's id order, with the iterations run and the last iteration's total change, so a run that stopped at max_iterations before converging says so. They are the usual PageRank (networkx's): a node with no out-edge shares its score with every node, and the scores sum to 1.
  • Components are weak (edges followed either way): each is a list of keys in id order, components in the order of their first member.
  • Shortest paths count hops from one source (edges carry no weight; the tier holds no property values). Each member reached comes back as (key, distance, parent) in id order, parent being the member before it on a shortest path, the lowest-id one among equals, and None for the source. A source that is not a member of the class reaches nothing. Relationships are given as for PageRank.
  • Limits. PageRank and components return one row per member, so a class with more members than limit is refused before anything is built. Shortest paths refuse once more than limit members are reached.
  • Determinism. Keys and their order are fixed by the snapshot. Component membership is exact, and so are shortest paths. PageRank runs on one thread and adds in a fixed order, so the same snapshot and parameters give the same scores bit for bit, and a sort by score gives the same order every run.

All three release the GIL. PageRank and components build the graph they run over for the call and drop it after: at its peak, while it is built, up to about 24 bytes per edge. Shortest paths read the relationships as held and build nothing.

Develop

cargo test && cargo clippy --all-targets --features python
uv venv .venv && uv pip install --python .venv/bin/python maturin pytest
VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop --release
VIRTUAL_ENV=$PWD/.venv .venv/bin/python -m pytest tests
VIRTUAL_ENV=$PWD/.venv .venv/bin/python scripts/smoke_scale.py

Set VIRTUAL_ENV explicitly: maturin develop installs into whatever virtual environment is active, which in a shell opened for another project is that project's.

Metadata

Release files for ghost-graph 0.1.0

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

Source distribution (sdist)

Source distribution for ghost-graph 0.1.0
File Size Uploaded Provenance Actions
ghost_graph-0.1.0.tar.gz 52.8 kB With provenance Details for ghost_graph-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for ghost-graph 0.1.0
File Actions
ghost_graph-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for ghost_graph-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
ghost_graph-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for ghost_graph-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
ghost_graph-0.1.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for ghost_graph-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
ghost_graph-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for ghost_graph-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 2.1 MB

Release files / ghost_graph-0.1.0.tar.gz

Download URL ghost_graph-0.1.0.tar.gz
Size 52.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b43740aa51563eeb6b8ba583d66335ebec5bbc71df59ae0c2e0b107478ecb438
BLAKE2b-256 checksum
How to use checksums
e5bea83356f686611bc0cbb6d1380c53e316b071f79b569e5fec69c2052ae05e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / ghost_graph-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL ghost_graph-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 540.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b6694fcd063dc679c596155d44fa72b47c29743d30c25180cca9fd95dc9bd86e
BLAKE2b-256 checksum
How to use checksums
6b29b9ab2e863ec686b1eee336796d150957c736933dc829c574f257dd56eece
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / ghost_graph-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL ghost_graph-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 530.0 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5eab0b6afbfbce16c2bde7f321f0dd50d2139d6a3399e2692a30edf9e7e9e92f
BLAKE2b-256 checksum
How to use checksums
a571898f5b120578e46aedbde7a36536d34eaa0706f665aa8b137ab1e2738e7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / ghost_graph-0.1.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL ghost_graph-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 475.4 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e9fc0c2cb1176fb52d50ce40cda15d82fbc7e762eb9b7a64f637409c2643eb56
BLAKE2b-256 checksum
How to use checksums
9b54d1014a0a2b9728765cb09adcc8fbfbf3c756b652b7baddafdd7a44ee2cee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Release files / ghost_graph-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL ghost_graph-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 475.8 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
06685427173431e484dc1806e230bd970b6050002545d09bf1c9fc4dbbeddb73
BLAKE2b-256 checksum
How to use checksums
c3cdb23a6db82484f79a60ead2850cf48c66d1486c96f7a8657d45cc70705423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

Security for ghost-graph 0.1.0

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.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for ghost_graph-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

5 release files Full provenance

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