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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

heterograph-0.2.0.tar.gz (57.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heterograph-0.2.0-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

Details for the file heterograph-0.2.0.tar.gz.

File metadata

  • Download URL: heterograph-0.2.0.tar.gz
  • Upload date:
  • Size: 57.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for heterograph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 31b8d2b9dde46ed11bd050354ecf9b6d398cc6dd60f4c399374bd0d35c9fd581
MD5 46e37f66996a394cdd16cd240f858b12
BLAKE2b-256 8a074250309263747f0ee646237b3bd2582dc0c68ccf3c5f1c0fe3b4e37501ec

See more details on using hashes here.

File details

Details for the file heterograph-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: heterograph-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 61.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for heterograph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8a41cdd200e08d433a6c9d50208cdc9a4f549f25a6a77e2e7c10c9057f23c9
MD5 6368717f90acbe3fcbbae5f670e0c584
BLAKE2b-256 e7b4e1172a91ded846cbccbb6534cc1ea293e12cf73adbaa1de799e2e98c6200

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 Sentry Error logging StatusPage Status page