Skip to main content

Python library for creating and drawing graphs and taking advantage of graph properties

Project description

Abstract

Abstract is a Python library for creating and drawing graphs and taking advantage of graph properties.

Installation

pip install abstract

or

pip install git+https://github.com/idin/abstract.git

Graph

In computer science, a graph is an abstract data type that is meant to implement the undirected graph and directed graph concepts from mathematics; specifically, the field of graph theory. [1]

A graph data structure consists of a finite (and possibly mutable) set of vertices or nodes or points, together with a set of unordered pairs of these vertices for an undirected graph or a set of ordered pairs for a directed graph. These pairs are known as edges, arcs, or lines for an undirected graph and as arrows, directed edges, directed arcs, or directed lines for a directed graph. The vertices may be part of the graph structure, or may be external entities represented by integer indices or references. [1]

Usage

The Graph class allows you to create nodes and edges and visualize the resulting graph. Edges can have direction which indicates parent-child relationship.

Graph: Constructing a New Graph

from abstract import Graph

graph = Graph()

add_node: Adding a New Node

The add_node method returns a GraphNode object.

node_order = [
    'scissors', 'paper', 'rock', 'lizard', 'Spock', 'scissors',
    'lizard', 'paper', 'Spock', 'rock', 'scissors'
]

# add nodes (avoid duplicates)
for node in set(node_order):
    node = graph.add_node(name=node)

connect: Adding Edges

The connect method creates an edge from a start node to an end node.

for index in range(len(node_order)-1):
    edge = graph.connect(start=node_order[index], end=node_order[index+1])

get_node

To retrieve a node from the graph you can use the get_node method.

rock = graph.get_node('rock')

draw (render)

The render method visualizes the graph and if a path is provided it saves it to an image file that can be a pdf or png. The file format is infered from the path argument. The draw method is just an alias for render.

# just visualize the graph
graph.draw()

https://raw.githubusercontent.com/greyli/flask-share/master/images/demo.png image of the graph

# save as a png file and view the file
graph.draw(path='my_graph.png', view=True)

Future Features

  • Create a graph from:
    • list of dictionaries
    • dataframe
  • Create a new graph by filtering a graph

Project details


Download files

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

Source Distribution

abstract-0.1.4.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

abstract-0.1.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file abstract-0.1.4.tar.gz.

File metadata

  • Download URL: abstract-0.1.4.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for abstract-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b8b60c45076ab6af67ce3536c874a26d50a272c11ae6f45c5247352bd7a27675
MD5 3db3bc87fa8ff470f92ef459a60719b3
BLAKE2b-256 314442e313e5b448016e7c6b8b3554c74dc38df0415e6e6c8378c09ad408b2a3

See more details on using hashes here.

File details

Details for the file abstract-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: abstract-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for abstract-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f85dc8d8b56da3052a960debc52678214b4c32771a3e43f196d1d9d136149164
MD5 8748be64f46d704f548b341089959bfd
BLAKE2b-256 515de8782961602e028f7dc8515ccd10b36035da6819d345a7828dd1ce1dca33

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