Skip to main content

dags

PyPI PyPI - Python Version Conda Version Conda Platform PyPI - License Documentation Status GitHub Workflow Status codecov pre-commit.ci status

About

dags provides tools to combine several interrelated functions into one function. The order in which the functions are called is determined by a topological sort on a dag that is constructed from the function signatures. You can specify which of the function results will be returned in the combined function.

dags is a tiny library, all the hard work is done by the great NetworkX.

Example

To understand what dags does, let's look at a very simple example of a few functions that do simple calculations.

def f(x, y):
    return x**2 + y**2


def g(y, z):
    return 0.5 * y * z


def h(f, g):
    return g / f

Assume that we are interested in a function that calculates h, given x, y and z.

We could hardcode this function as:

def hardcoded_combined(x, y, z):
    _f = f(x, y)
    _g = g(y, z)
    return h(_f, _g)


hardcoded_combined(x=1, y=2, z=3)
0.6

Instead, we can use dags to construct the same function:

from dags import concatenate_functions

combined = concatenate_functions([h, f, g], targets="h")

combined(x=1, y=2, z=3)
0.6

More examples can be found in the documentation

Notable features

  • The dag is constructed while the combined function is created and does not cause too much overhead when the function is called.
  • If all individual functions are jax compatible, the combined function is jax compatible.
  • When jitted or vmapped with jax, we have not seen any performance loss compared to hard coding the combined function.
  • When there is more than one target, you can determine whether the result is returned as tuple, list or dict or pass in an aggregator to combine the multiple outputs.
  • Since the relationships are discovered from function signatures, dags provides decorators to rename arguments in order to make it easy to wrap functions you do not control yourself.

Installation

dags is available on PyPI and conda-forge. Install it with

$ pip install dags

# or

$ pixi add dags

# or

$ conda install -c conda-forge dags

Documentation

The documentation is hosted on Read the Docs.

Metadata

Release files for dags 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dags 0.7.0
File Size Uploaded Provenance Actions
dags-0.7.0.tar.gz 23.1 kB Without provenance Details for dags-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dags 0.7.0
File Interpreter ABI Platform Actions
dags-0.7.0-py3-none-any.whl Python 3 none any Details for dags-0.7.0-py3-none-any.whl

Total release size: 49.5 kB

Release files / dags-0.7.0.tar.gz

Download URL dags-0.7.0.tar.gz
Size 23.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e6207466a616e5461843654b2000ad67b2e8e0c020f37d3c359541ddb0797a4b
BLAKE2b-256 checksum
How to use checksums
c4d479c17ad37f0031114a73bbfc703f08f5570c02e367079480d8e066a69ff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / dags-0.7.0-py3-none-any.whl

Download URL dags-0.7.0-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7803dc57d7a9cd8f28586b9d499636ff7d236a1e7a48aaf7d8b9e7c89e3faa0
BLAKE2b-256 checksum
How to use checksums
719cefce6243311b24b9e8faf71442808e1d302b2c20f253ebde1a26d3d1b11a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for dags 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page