Lightweight computation graphs for Python
Project description
It’s a DAG all the way down!
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:
>>> graphop.compute({'a': 2, 'b': 5}, outputs=["a_minus_ab"]) {'a_minus_ab': -8}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file graphtik-4.0.1.tar.gz
.
File metadata
- Download URL: graphtik-4.0.1.tar.gz
- Upload date:
- Size: 55.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2506fc388eab4c01a9a958a6053c78152b75e609fb465872d18aa5dffa77c846 |
|
MD5 | d1e77754ce8104d179a0a323f45e1c32 |
|
BLAKE2b-256 | 77f43b5a93795378b88d31af3d84d8f8e00b85a5c09fda4e105d3654e147d2ef |
File details
Details for the file graphtik-4.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: graphtik-4.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 37.9 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/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6355e7d71cad5f5f35fb48bdbdf323b38df338ef12083db07c4de67af087bf29 |
|
MD5 | fb22ebfc6ab97f0962407ba04a01d4c5 |
|
BLAKE2b-256 | d1ac87ab5eae1ea9320b84a8f72e5669c54a7d69047706bf3c17a3e3256590c6 |