Skip to main content

This package provides a simple graph implementation for Python.

Project description


This package provides a simple graph implementation for Python.

1. Installation

1.1. Using pip

Simply run the usual installation command for pip:

pip install jlvandenhout-graph

1.2. From source

To install from the latest source code, clone this repository and install from the repository:

git clone
cd graph
pip install .

2. Basic usage

from jlvandenhout.graph import Graph

graph = Graph()
graph.edges.update("Bob", "Alice", 42)
graph.edges.update("Alice", "Charlie", 20)

for node in graph.nodes:
    print("name:", node)
    print("  from:", ", ".join(graph.nodes.preceding(node)))
    print("  to:", ", ".join(graph.nodes.succeeding(node)))

print("\nChecking balances...")
for node in graph.nodes:
    balance = 0
    for edge in graph.edges.preceding(node):
        balance += edge.value
    for edge in graph.edges.succeeding(node):
        balance -= edge.value
    print("name:", node)
    print("  balance:", balance)

print("\nRemoving Charlie from history...")

print("names:", ", ".join(graph.nodes))
print("transactions:", ", ".join(f"From {f} to {t}" for f, t in graph.edges))

3. Support

If you have any questions, suggestions or found a bug, please open an issue in the issue tracker.

4. Contributing


5. License

Refer to GNU General Public License v3 (GPLv3).

6. Changelog


Project details

Download files

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

Files for jlvandenhout-graph, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size jlvandenhout_graph-0.4.0-py3-none-any.whl (17.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size jlvandenhout-graph-0.4.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page