Skip to main content

Lightweight computation graphs for Python

Project description

Supported Python versions of latest release in PyPi Development Status Latest release in GitHub Latest version in PyPI Travis continuous integration testing ok? (Linux) ReadTheDocs ok? cover-status Code Style Apache License, version 2.0

Github watchers Github stargazers Github forks Issues count

It’s a DAG all the way down!

sample graphtik plot

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 can be used as is to build machine learning pipelines for data science projects. It should be extendable to act as the core for a custom ETL engine or a workflow-processor for interdependent files and processes.

Graphtik sprang from 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 suite 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 functools import partial
>>> from graphtik import compose, operation

>>> # Computes |a|^p.
>>> def abspow(a, p):
...     c = abs(a) ** p
...     return c

Compose the mul, sub, and abspow functions into a computation graph:

>>> graphop = compose(
...     "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"])
...     (partial(abspow, p=3))
... )

Run the graph and request all of the outputs:

>>> graphop(a=2, b=5)
{'a': 2, 'b': 5, 'ab': 10, 'a_minus_ab': -8, 'abs_a_minus_ab_cubed': 512}

… or request a subset of outputs:

>>> solution = graphop.compute({'a': 2, 'b': 5}, outputs=["a_minus_ab"])
>>> solution
{'a_minus_ab': -8}

… and plot the results (if in jupyter, no need to create the file):

>>> solution.plot('graphop.svg')    # doctest: +SKIP

sample graphtik plot graphtik legend

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-5.0.0.tar.gz (68.8 kB view details)

Uploaded Source

Built Distribution

graphtik-5.0.0-py2.py3-none-any.whl (45.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file graphtik-5.0.0.tar.gz.

File metadata

  • Download URL: graphtik-5.0.0.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.1

File hashes

Hashes for graphtik-5.0.0.tar.gz
Algorithm Hash digest
SHA256 76533fc91c236cd9d2930998cdb7a6962e41c4326b4aad23a52269a660499c27
MD5 e7205e27b0844db9cc90e2bf29802c88
BLAKE2b-256 0ad2e70f8a2822dbd370de1ca7f16fd0f4210a80b5bb0f4cb40c32fd6cdd57d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: graphtik-5.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 45.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/43.0.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.1

File hashes

Hashes for graphtik-5.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 46e5573c9767b35d9aa68803ffa07cbeaf86522d4414662069dd6dbe7c57eab7
MD5 3f8e2c96abc58a9123f2f5b9ef0e0f77
BLAKE2b-256 cb01a49336ce50a638e5eaed1303af01d18483fd17b29fc06e9ab7dd8a392a1d

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