Python bindings for the HypergraphZ hypergraph library
Project description
HypergraphZ - A Hypergraph Implementation in Zig
HypergraphZ is a directed hypergraph implementation in Zig (https://en.wikipedia.org/wiki/Hypergraph):
- Each hyperedge can contain zero, one (unary) or multiple vertices.
- Each hyperedge can contain vertices directed to themselves one or more times.
For Python users
Installation
pip install hypergraphz
# or with uv
uv add hypergraphz
Pre-built wheels are available for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64).
Quick start
from hypergraphz import Hypergraph
g = Hypergraph()
# Add vertices and hyperedges
alice = g.add_vertex({"name": "alice", "age": 30})
bob = g.add_vertex({"name": "bob", "age": 25})
carol = g.add_vertex({"name": "carol", "age": 35})
collab = g.add_hyperedge({"type": "project"})
g.connect(collab, [alice, bob, carol])
# Build the reverse index before querying
g.build()
# Shortest path
path = g.shortest_path(alice, carol)
# Fluent query builders
active = (
g.vertices()
.where(lambda d: d["age"] > 28)
.data()
)
# Structural algorithms
scores, _, _ = g.page_rank()
centrality = g.centrality()
components = g.connected_components()
# Sub-graph operations return independent Hypergraph objects
sub = g.vertex_induced_subgraph([alice, bob])
dual = g.dual()
API summary
| Category | Methods |
|---|---|
| Lifecycle | build(), clear(), save(), load(), clone() |
| Vertices | add_vertex(), get_vertex(), update_vertex(), delete_vertex(), vertex_count(), all_vertex_ids() |
| Hyperedges | add_hyperedge(), get_hyperedge(), update_hyperedge(), delete_hyperedge(), hyperedge_count(), all_hyperedge_ids() |
| Relations | connect(), prepend(), insert_vertex(), insert_many(), disconnect(), disconnect_at() |
| Degree | vertex_indegree(), vertex_outdegree() |
| Queries | hyperedge_vertices(), vertex_hyperedges(), neighborhood(), intersections(), hyperedges_connecting(), endpoints(), orphan_vertices(), orphan_hyperedges() |
| Boolean | is_connected(), is_reachable(), has_cycle(), is_k_uniform() |
| Traversal | shortest_path(), all_paths(), bfs(), dfs(), random_walk() |
| Algorithms | connected_components(), topological_sort(), cut_vertices(), centrality(), page_rank(), inclusions(), nestedness_profile() |
| Matrices | incidence_matrix(), incidence_matrix_coo(), laplacian() |
| Sub-graphs | dual(), k_skeleton(), vertex_induced_subgraph(), edge_induced_subgraph(), core(), expand_to_graph(), expand_to_star(), line_graph(), transitive_closure() |
| Fluent builders | vertices() → VertexQuery, hyperedges() → HyperedgeQuery |
Exceptions
All errors map to typed exceptions from hypergraphz:
| Exception | When raised |
|---|---|
NotBuiltError |
Query requires build() first |
VertexNotFoundError |
Vertex ID does not exist |
HyperedgeNotFoundError |
Hyperedge ID does not exist |
CycleDetectedError |
Operation requires a DAG |
NoPathError |
No directed path exists |
IndexOutOfBoundsError |
Insertion index out of range |
NotEnoughVerticesError |
Operation needs more vertices |
For Zig users
Zig version
HypergraphZ currently requires Zig 0.17.0-dev.242+5d55999d2.
Usage
Add hypergraphz as a dependency to your build.zig.zon:
zig fetch --save https://github.com/yamafaktory/hypergraphz/archive/v0.1.0.tar.gz
Add hypergraphz as a dependency to your build.zig:
const hypergraphz = b.dependency("hypergraphz", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("hypergraphz", hypergraphz.module("hypergraphz"));
Example
examples/coauthorship.zig models a small research community as a directed hypergraph
where vertices are researchers and hyperedges are papers. The first listed author is
treated as the corresponding author, giving each hyperedge a natural direction.
zig build example
It walks through seventeen features of the library in sequence:
| Section | API | What it shows |
|---|---|---|
| Papers per researcher | getVertexHyperedges |
reverse-index query |
| Research communities | getConnectedComponents |
two isolated groups with no cross-group papers |
| Betweenness centrality | computeCentrality |
which researchers bridge the most collaboration paths |
| Degrees of separation | findShortestPath |
1–3 hops within a community; unreachable across communities |
| Dual: paper-centric view | getDual |
swap vertices ↔ hyperedges to see each researcher's papers |
| Shared authorship | getIntersections |
researchers present on every paper in a given set |
| Seniority ordering | topologicalSort |
hierarchy implied by the authorship direction |
| Pairwise expansion | expandToGraph |
6 papers encode 11 directed pairs in a regular graph |
| Spectral view | toLaplacian |
normalized Laplacian; block-diagonal under disjoint groups |
| PageRank | computePageRank |
citation-weighted stationary distribution; sums to 1 |
| Random walk | randomWalk |
seeded weighted walk; stays inside the start's component |
| Star expansion | expandToStar |
bipartite (researcher ↔ paper) projection; 2-uniform |
| Line graph | getLineGraph |
papers as vertices, linked when they share an author |
| K-core decomposition | getCore |
(s, t)-core peeling; trims the lone-paper researcher |
| Nestedness | getInclusions |
strict-subset pairs across hyperedges; sized profile |
| Co-author neighborhoods | getVertexNeighborhood |
undirected co-occurrence neighbors across all hyperedges |
Documentation
The latest online documentation can be found here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hypergraphz-0.1.5.tar.gz.
File metadata
- Download URL: hypergraphz-0.1.5.tar.gz
- Upload date:
- Size: 52.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1e3a0584d22927b1c40c3ce763f38b3816b738172179a7eb240f772bd783681
|
|
| MD5 |
82d70cfd35ab3e42bcf2ba21ee78d291
|
|
| BLAKE2b-256 |
1705b7d5aeeee4f897bbd6c762ef0bf69d9c2d1bceca3a54f6a623125084d866
|
Provenance
The following attestation bundles were made for hypergraphz-0.1.5.tar.gz:
Publisher:
release.yml on yamafaktory/hypergraphz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypergraphz-0.1.5.tar.gz -
Subject digest:
e1e3a0584d22927b1c40c3ce763f38b3816b738172179a7eb240f772bd783681 - Sigstore transparency entry: 1563489563
- Sigstore integration time:
-
Permalink:
yamafaktory/hypergraphz@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/yamafaktory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypergraphz-0.1.5-py3-none-win_amd64.whl.
File metadata
- Download URL: hypergraphz-0.1.5-py3-none-win_amd64.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3c7ebbe89e2a6bdfd9cfab41de1b598b3f0ff12563cfae5b1bd61fa98e7e296
|
|
| MD5 |
e7536eb115e3c9dee22f9580bf71d18c
|
|
| BLAKE2b-256 |
88deed353a07ae31ffeea4147391d8bc605558223104bd922ed7fe3e9e488a39
|
Provenance
The following attestation bundles were made for hypergraphz-0.1.5-py3-none-win_amd64.whl:
Publisher:
release.yml on yamafaktory/hypergraphz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypergraphz-0.1.5-py3-none-win_amd64.whl -
Subject digest:
f3c7ebbe89e2a6bdfd9cfab41de1b598b3f0ff12563cfae5b1bd61fa98e7e296 - Sigstore transparency entry: 1563489639
- Sigstore integration time:
-
Permalink:
yamafaktory/hypergraphz@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/yamafaktory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypergraphz-0.1.5-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: hypergraphz-0.1.5-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f631be63b7854bded85debe249266ed963dc18be3ecbaf624ca9b0d9947f618
|
|
| MD5 |
532c71bd3a13a29e8d36c688d35902e6
|
|
| BLAKE2b-256 |
986704ea31e2dd9df6515e65e440b8845df4f850948d05df5f545fb40204801f
|
Provenance
The following attestation bundles were made for hypergraphz-0.1.5-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:
Publisher:
release.yml on yamafaktory/hypergraphz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypergraphz-0.1.5-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl -
Subject digest:
0f631be63b7854bded85debe249266ed963dc18be3ecbaf624ca9b0d9947f618 - Sigstore transparency entry: 1563489666
- Sigstore integration time:
-
Permalink:
yamafaktory/hypergraphz@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/yamafaktory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypergraphz-0.1.5-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.
File metadata
- Download URL: hypergraphz-0.1.5-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a3583e4bc6d1e790f7458082826fe0aab679f9a22e4e003fbb8a9a0a3c20c5f
|
|
| MD5 |
0ba18a53b48b59c34b61611e2d1624e3
|
|
| BLAKE2b-256 |
ea538d167196fec9f0eca0776d7ec6f67c77b108451c1f87baf6010192e7bdb2
|
Provenance
The following attestation bundles were made for hypergraphz-0.1.5-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:
Publisher:
release.yml on yamafaktory/hypergraphz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypergraphz-0.1.5-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl -
Subject digest:
5a3583e4bc6d1e790f7458082826fe0aab679f9a22e4e003fbb8a9a0a3c20c5f - Sigstore transparency entry: 1563489590
- Sigstore integration time:
-
Permalink:
yamafaktory/hypergraphz@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/yamafaktory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypergraphz-0.1.5-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: hypergraphz-0.1.5-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 248.6 kB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5aa827409be1c963257f0743afb1a2edb2579fb9dea56b9f2dbe43d85feeb4fc
|
|
| MD5 |
0cc3ee0b15112bf2f83f2dbe52abc8fb
|
|
| BLAKE2b-256 |
88d05337819050f1089661886f3fec2ae55be5595783fc1391401e8fe53110b2
|
Provenance
The following attestation bundles were made for hypergraphz-0.1.5-py3-none-macosx_11_0_arm64.whl:
Publisher:
release.yml on yamafaktory/hypergraphz
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypergraphz-0.1.5-py3-none-macosx_11_0_arm64.whl -
Subject digest:
5aa827409be1c963257f0743afb1a2edb2579fb9dea56b9f2dbe43d85feeb4fc - Sigstore transparency entry: 1563489620
- Sigstore integration time:
-
Permalink:
yamafaktory/hypergraphz@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/yamafaktory
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@72a89b78fb0c3a0a095afb2bc06b87093be73535 -
Trigger Event:
push
-
Statement type: