This package provides a simple graph implementation for Python.
Project description
Graph
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 https://gitlab.com/jlvandenhout/graph.git
cd graph
pip install .
2. Basic usage
from jlvandenhout.graph import Graph
graph = Graph()
graph.nodes.add("Alice")
graph.edges.update("Bob", "Alice", 42)
graph.edges.update("Alice", "Charlie", 20)
for node in graph.nodes:
print("name:", node)
print(" transactions from:", ", ".join(graph.nodes.preceding(node)))
print(" transactions to:", ", ".join(graph.nodes.succeeding(node)))
for node in graph.nodes:
balance = 0
for preceding in graph.nodes.preceding(node):
balance += graph.edges.value(preceding, node)
for succeeding in graph.nodes.succeeding(node):
balance -= graph.edges.value(node, succeeding)
print("name:", node)
print(" balance:", balance)
graph.nodes.remove("Charlie")
print("names:", ", ".join(graph.nodes))
print("transactions:", ", ".join(f"{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
Refer to CONTRIBUTING.
5. License
Refer to GNU General Public License v3 (GPLv3).
6. Changelog
Refer to CHANGELOG.
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 Distribution
Close
Hashes for jlvandenhout_graph-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5407a4300d60956c1d1fbb87e1ca2b8b64501c66d0c110e524e8cfa6463b5ddb |
|
MD5 | 70cc1109749029c102fa7a45dd815beb |
|
BLAKE2b-256 | 4aac1dd71ac2686d6f98e61b5079256043d1f21e153777544de5c464897ca759 |