Library of Graph Algorithms for Python
Project description
Library of Graph Algorithms for Python
Introduction
Library of Graph Algorithms for Python is a simple Python library providing implementations of various graph algorithms. It is more or less an educational/experimental project serving me as Python sandbox. The current version of the library provides the following algorithms:
- topological sort
- shortest path search for unweighted graphs
- shortest path search for weighted graphs (Dijkstra's algorithm)
- Prim's minimum spanning tree algorithm (limited to connected graphs)
- Kruskal's minimum spanning tree algorithm (applicable to both connected and disconnected graphs)
Runtime Environment, Source Code Organization etc.
Python Version and Dependencies
When implementing the library, I used Python 3.8. Slightly older versions of Python might work as well, but there is no guarantee as I have never tested the library with them. The library code uses only the Python Standard Library. In other words, it does not depend on any other modules. Unit tests depend on PyTest 5.4.3. If you want to measure the code coverage, you will also need PyTest Coverage 2.10.0 (i.e. optional test dependency). Similarly, if you want to generate test reports in HTML format, PyTest HTML plugin is needed.
Library Code
The library code is divided to five modules:
- graphlib.graph module provides two graph implementations (adjacency matrix, adjacency set), plus an abstract base class prescribing the public API of any graph implementation.
- graphlib.algorithms provides implementations of various graph algorithms like topological sort, shortest path search, minimum spanning tree search etc.
- graphlib.util module provides functionalities that support the implementation of the algorithms, for instance a priority queue.
- graphlib.dump module provides dump-functions that can pretty-print various structures like graph, result of shortest path search, result of minimum spanning tree search etc. These functions can write their output to a file, to stdout, or to an instance of io.StringIO.
- graphlib.jsondef module provides functions that can build a graph accorging to a JSON definition.
Test Code
The test code is concentrated in the tests directory, which is just a flat structure of modules with test code. For each of the library modules listed in the Library Code section, there is a corresponding test module. The names of all test modules start with the prefix test_, so that PyTest can recognize them as test modules. Within each test module, test methods are grouped to test suite classes. A test suite class is a simple class serving as collection (grouping) of test methods exercising the same functionality. All test dependencies are captured in the test dependencies file. Visualizations of the graphs used by the test code can be found in the test-graphs directory.
API Documentation and Examples of Usage
The source code of the library involves docstring, so the API documentation is available in the usual way. Examples of usage can be found in the unit tests, no other examples are provided.
Creation of Distribution Package
In order to build the distribution package, execute the following command in the root directory of the project:
python setup.py sdist bdist_wheel
The command above creates both source archive in .tar.gz format and distribution in wheel format.
Execution of Unit Tests
In order to execute the unit tests, execute the following command in the root directory of the project:
python -m pytest -v tests
The following command triggers the execution of the unit tests, and it also generates code coverage report in HTML format. The command also generates detailed test results in HTML format to the file test-results.html.
python -m pytest --cov=graphlib --cov-branch --cov-report html --html=test-results.html tests
The command above will only work if you have installed the corresponding PyTest plug-ins (see test dependencies).
Pylint Analysis
In order to perform analysis of the library code with Pylint, execute the following command in the root directory of the project:
python -m pylint graphlib
The command above will only work if you have installed Pylint.
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
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 python-graph-alg-lib-1.0.0.tar.gz.
File metadata
- Download URL: python-graph-alg-lib-1.0.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f77e3cf266c7a10d750de2a7cefa3c4d1533dc32a4eb36c793809fea3f2fd2b9
|
|
| MD5 |
ca4d70a3f0506ea684dd0db6e717d2f8
|
|
| BLAKE2b-256 |
3ccd301e4d3cf7000352f3229b06e06f2cde1ab4c2aed509b2e5dabe9cef0368
|
File details
Details for the file python_graph_alg_lib-1.0.0-py3-none-any.whl.
File metadata
- Download URL: python_graph_alg_lib-1.0.0-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a36c0ba4e8b3b40b72ec7f10e145a04992ac1026d5d3cfb30a24073faa7de899
|
|
| MD5 |
36b9d71e816074eb611d805bdbd482b2
|
|
| BLAKE2b-256 |
e0cfe95aedb883217203570bb3451b85e98dbf87e2dd0fcfe105e41bb54a108b
|