Skip to main content

Lightweight computation graphs for Python

Project description

# Graphtik

![Supported Python versions of latest release in PyPi](https://img.shields.io/pypi/pyversions/graphtik.svg?label=Python) ![Latest version in PyPI](https://img.shields.io/pypi/v/graphtik.svg?label=PyPi%20version) ![Latest version in GitHub](https://img.shields.io/github/v/release/pygraphkit/graphtik.svg?label=GitHub%20release&include_prereleases) ![Build Status](https://travis-ci.org/pygraphkit/graphtik.svg?branch=master) ![Doc Status](https://img.shields.io/readthedocs/graphtik.svg?branch=master) ![codecov](https://codecov.io/gh/pygraphkit/graphtik/branch/master/graph/badge.svg) ![License](https://img.shields.io/pypi/l/graphtik.svg)

![Github watchers](https://img.shields.io/github/watchers/pygraphkit/graphtik.svg?style=social) ![Github stargazers](https://img.shields.io/github/stars/pygraphkit/graphtik.svg?style=social) ![Github forks](https://img.shields.io/github/forks/pygraphkit/graphtik.svg?style=social) ![Issues count](http://img.shields.io/github/issues/pygraphkit/graphtik.svg?style=social)

> It’s a DAG all the way down

<img src=”docs/source/images/barebone_2ops.svg” width=100 alt=”simple graphtik computation”>

## Lightweight computation graphs for Python

Graphtik is an an understandable and lightweight Python module for building and running ordered graphs of computations. The API posits a fair compromise between features and complexity without precluding any. It might be of use in computer vision, machine learning and other data science domains, or become the core of a custom ETL pipelne.

Graphtik is a temporary fork of [Graphkit](https://github.com/yahoo/graphkit) to experiment with Python 3.6+ features.

## Quick start

Here’s how to install:

pip install graphtik

OR with dependencies for plotting support (and you need to install [Graphviz](https://graphviz.org) program separately with your OS tools):

pip install graphtik[plot]

Here’s a Python script with an example Graphtik computation graph that produces multiple outputs (a * b, a - a * b, and abs(a - a * b) ** 3):

>>> from operator import mul, sub
>>> from graphtik import compose, operation
>>> # Computes |a|^p.
>>> def abspow(a, p):
...     c = abs(a) ** p
...     return c
>>> # Compose the mul, sub, and abspow operations into a computation graph.
>>> graphop = compose(name="graphop")(
...     operation(name="mul1", needs=["a", "b"], provides=["ab"])(mul),
...     operation(name="sub1", needs=["a", "ab"], provides=["a_minus_ab"])(sub),
...     operation(name="abspow1", needs=["a_minus_ab"], provides=["abs_a_minus_ab_cubed"], params={"p": 3})(abspow)
... )

<img src=”docs/source/images/barebone_3ops.svg” width=100 alt=”simple graphtik computation”>

>>> # Run the graph and request all of the outputs.
>>> out = graphop({'a': 2, 'b': 5})
>>> print(out)
{'a': 2, 'b': 5, 'ab': 10, 'a_minus_ab': -8, 'abs_a_minus_ab_cubed': 512}
>>> # Run the graph and request a subset of the outputs.
>>> out = graphop({'a': 2, 'b': 5}, outputs=["a_minus_ab"])
>>> print(out)
{'a_minus_ab': -8}
<img src=”docs/source/images/executed_3ops.svg” width=120

alt=”simple graphtik computation”>

As you can see, any function can be used as an operation in Graphtik, even ones imported from system modules!

## Plotting

For debugging the above graph-operation you may plot either the newly omposed graph or the execution plan of the last computation executed, using these methods:

`python graphop.plot(show=True) # open a matplotlib window graphop.plot("graphop.svg") # other supported formats: png, jpg, pdf, ... graphop.plot() # without arguments return a pydot.DOT object graphop.plot(solution=out) # annotate graph with solution values `

![Graphtik Legend](docs/source/images/GraphtikLegend.svg “Graphtik Legend”)

> TIP: The pydot.Dot instances returned by plot() are rendered as SVG in Jupyter/IPython.

# License

Code licensed under the Apache License, Version 2.0 license. See LICENSE file for terms.

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

graphtik-2.0.0b1.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

graphtik-2.0.0b1-py2.py3-none-any.whl (30.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file graphtik-2.0.0b1.tar.gz.

File metadata

  • Download URL: graphtik-2.0.0b1.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5rc1

File hashes

Hashes for graphtik-2.0.0b1.tar.gz
Algorithm Hash digest
SHA256 f47f3eb08ff25b94d2087fc454b8a4d6330724bb3327c0114b35aa878ef038e0
MD5 42b8fb89ca1f83f7ea2b402782f53e1b
BLAKE2b-256 ac9b713e4d6d71bc0735b46f6549e9bc9f6611e9cb66a8f6f47bee27f781b9e6

See more details on using hashes here.

File details

Details for the file graphtik-2.0.0b1-py2.py3-none-any.whl.

File metadata

  • Download URL: graphtik-2.0.0b1-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5rc1

File hashes

Hashes for graphtik-2.0.0b1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f0f97cae6e2cc82cab2be2537bc62aec739befc397816774417767d8fb3c72d8
MD5 b7d29ed1eaa82ed9c61f2544462cb8bc
BLAKE2b-256 3b1ca7418d919322a641a9bb64d350b07ebbc06150e5bafa27afd63bc47a84d7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page