Skip to main content

Heterograph

heterograph is a Python library for building, querying, and visualizing heterogeneous directed graphs ("heterographs"). It provides a convenient, Pythonic API for managing vertices, edges, and their properties, supports common graph traversals, and includes rich visualization tools for notebooks and the web.

The project is designed for exploratory graph modeling and analysis, especially when you need structured metadata on vertices and edges and interactive inspection of graph topology.


Key Features

  • Heterogeneous directed graphs

    • Vertices and edges with arbitrary, typed properties
    • Explicit in-/out-neighbour management
  • Graph algorithms

    • Depth-first search (DFS) traversal utilities
    • Topology and neighbourhood queries
  • Visualization

    • Interactive web-based viewer (Flask + D3)
    • Notebook-friendly display helpers
    • Optional Graphviz export for static diagrams
  • Extensible design

    • Custom initialization hooks for graphs, vertices, and edges
    • Property system (HGraphProps) for clean metadata handling

Project Structure

heterograph/
├── heterograph/
│   ├── hgraph.py          # Core HGraph implementation
│   ├── hgraph_props.py    # Property handling for graphs, vertices, edges
│   ├── webview.py         # Flask-based interactive web viewer
│   ├── utils/             # Notebook & display helpers
│   └── assets/            # Static JS/CSS assets for visualization
├── tests/                 # Pytest test suite
├── environment.yml        # Conda environment definition
├── pyproject.toml         # Build & packaging configuration
├── LICENSE
└── README.md

Installation

Create the Conda environment (recommended)

conda env create -f environment.yml
conda activate heterograph

Quick Start

Creating a graph

from heterograph import *

# Create an empty heterograph
g = HGraph()

# Add vertices
v1 = g.add_vx()
v2 = g.add_vx()

# Add an edge
e = g.add_edge(v1, v2)

Working with properties

# Set vertex properties
g.pmap[v1]["label"] = "Source"
g.pmap[v2]["label"] = "Target"

# Set edge properties
g.pmap[e]["weight"] = 1.0

# set graph properties
g['name'] = 'my graph'

Visualization

Web-based viewer

from heterograph import *

g = HGraph()

# Add vertices
v1 = g.add_vx()
v2 = g.add_vx()
g.add_edge(v1, v2)
g.view()

This launches a local Flask server with an interactive graph UI (pan, zoom, inspect vertices/edges).


Testing

Run the full test suite with:

pytest

Tests cover:

  • Vertex and edge creation
  • Neighbour queries
  • DFS traversal
  • Graph initialization and topology

See environment.yml for the full dependency list.


License

This project is licensed under the terms of the Apache License 2.0. See LICENSE for details.


Acknowledgements

  • Built on top of the excellent graph-tool library
  • Visualization powered by Flask and D3.js

Metadata

Release files for heterograph 0.2.5

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

Source distribution (sdist)

Source distribution for heterograph 0.2.5
File Size Uploaded
heterograph-0.2.5.tar.gz 59.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for heterograph 0.2.5
File Interpreter ABI Platform
heterograph-0.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 123.0 kB

Release files / heterograph-0.2.5.tar.gz

Download URL heterograph-0.2.5.tar.gz
Size 59.2 kB
Tags Source
SHA-256 checksum
How to use checksums
018d94e18198893a6240cbb4195b040752ae51393a234d96180888a7bd986b1e
BLAKE2b-256 checksum
How to use checksums
c30a0dc2875cfff496561e4812dad43989c7bc263d93ebbde29fd9d0d85d987c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / heterograph-0.2.5-py3-none-any.whl

Download URL heterograph-0.2.5-py3-none-any.whl
Size 63.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d67ec06716bc4bb961210a65fbedf6803ee83e83934a63dd8e7fa6ad54043fb1
BLAKE2b-256 checksum
How to use checksums
5a8089fc6001a51620099dc56afded54b55222022b6fd64e0cc563b7e9074996
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.2.5 This release

2 release files

0.2.0

2 release files

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