Skip to main content

A lightweight Python-3.6+ lib for solving & executing graphs of functions

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.

Quick start

Here’s how to install:

pip install graphtik

OR with various “extras” dependencies, such as, for plotting:

pip install graphtik[plot]
. Tip::

Supported extras:

plot

for plotting with Graphviz,

matplot

for plotting in maplotlib windows

sphinx

for embedding plots in sphinx-generated sites,

test

for running pytests,

dill

may help for pickling parallel tasks - see marshalling term and set_marshal_tasks() configuration.

all

all of the above, plus development libraries, eg black formatter.

Let’s build a graphtik computation graph that produces x3 outputs out of 2 inputs a and b:

  • a x b

  • a - a x b

  • |a - a x 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.4.0.tar.gz (76.2 kB view details)

Uploaded Source

Built Distribution

graphtik-5.4.0-py2.py3-none-any.whl (49.2 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: graphtik-5.4.0.tar.gz
  • Upload date:
  • Size: 76.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for graphtik-5.4.0.tar.gz
Algorithm Hash digest
SHA256 1b3eda2fe33416f1067994978468ed806bf014fb39e745b96aaa6e23eff3757a
MD5 7d975db00e35483526be924ca1638dcb
BLAKE2b-256 353318f6079af6025f0f1be8d3d9d9bcd91affed9473e106c374a03013ac181e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: graphtik-5.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 49.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.8.0

File hashes

Hashes for graphtik-5.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8d6bb6cb78ec9ef3afcc36ae234de740010c6ae31eb0dafe80134a1411501b06
MD5 91abb9e44a83cc04dc68eec510ac2655
BLAKE2b-256 e48be78205a3659082abe83138fe4c876c424b7671c7eafbb9ef1451a3b42d30

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