Another Python Graph Library is a simple, fast and easy to use graph library. The main characteristics are as follows:
See https://github.com/charanpald/APGL for the changelog.
Download for Windows, Linux or Mac OS using:
To use this library, you must have Python, NumPy and SciPy. The code has been verified on Python 2.7.2, Numpy 1.5.1 and Scipy 0.9.0, but should work with other versions. The automatic testing routine requires Python 2.7 or later, or the unittest2 testing framework for Python 2.3-2.6 .
The source code repository is available here for those that want the bleeding edge, or are interested in development.
Ensure that pip is installed, and then install apgl in the following way:
pip install apgl
If installing from source unzip the apgl-x.y.z.tar.gz file and then run setup.py as follows:
python setup.py install
In order to test the library (recommended), use the following commands in python
import apgl apgl.test()
and check that all tested pass.
A short introduction to the main features of the library is available in the PDF document “An Introduction to APGL”. This is the best way to learn the key features of APGL. In the meanwhile, here is small example of how to create a graph using the SparseGraph class which is based on scipy.sparse matrices.
>>> from apgl.graph import GeneralVertexList, SparseGraph >>> import numpy >>> numVertices = 5 >>> graph = SparseGraph(numVertices) >>> graph[0,1] = 1 >>> graph[0,2] = 3 >>> graph[1,2] = 0.1 >>> graph[3,4] = 2 >>> graph.setVertex(0, "abc") >>> graph.setVertex(1, 123) >>> graph.findConnectedComponents() [[0, 1, 2], [3, 4]] >>> graph.getWeightMatrix() array([[ 0. , 1. , 3. , 0. , 0. ], [ 1. , 0. , 0.1, 0. , 0. ], [ 3. , 0.1, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 2. ], [ 0. , 0. , 0. , 2. , 0. ]]) >>> graph.degreeDistribution() array([0, 2, 3]) >>> graph.neighbours(0) array([2, 1], dtype=int32) >>> print(graph) SparseGraph: vertices 5, edges 4, undirected, vertex list type: GeneralVertexList
The SparseGraph is initialised as an undirected graph with 5 vertices of which the labels are stored in GeneralVertexList. Edges are added between vertices (0, 1), (0, 2), (1, 2) and (3, 4). Following, the first and second vertices (indexed by 0 and 1 respectively) are initialised with “abc” and 123 respectively, and we then compute some properties over the resulting graph.
To learn more consult the reference documentation:
There is also a PDF version.