Skip to main content

This library helps you execute a set of functions in a Directed Acyclic Graph (DAG) dependency structure in parallel in a production environment.

Project description

tawazi

Python 3.9 Checked with mypy CodeFactor Downloads

Tawazi GIF

Introduction

Tawazi facilitates parallel execution of functions using a DAG dependency structure.

Explanation

Consider the function f that depends on the function g and h:

def g():
    print("g")
    return "g"
def h():
    print("h")
    return "h"
def f(g_var, h_var):
    print("received", g_var, h_var)
    print("f")
    return "f"

def main():
    f(g(), h())

main()

The DAG described in main can be accelerated if g and h are executed in parallel. This is what Tawazi does by adding a decorator to the functions g, h, f, and main:

from tawazi import dag, xn
@xn
def g():
    print("g")
    return "g"
@xn
def h():
    print("h")
    return "h"
@xn
def f(g_var, h_var):
    print("received", g_var, h_var)
    print("f")
    return "f"
@dag(max_concurrency=2)
def main():
    f(g(), h())

main()

The total execution time of main() is 1 second instead of 2 which proves that the g and h have run in parallel, you can measure the speed up in the previous code:

from time import sleep, time
from tawazi import dag, xn
@xn
def g():
    sleep(1)
    print("g")
    return "g"
@xn
def h():
    sleep(1)
    print("h")
    return "h"
@xn
def f(g_var, h_var):
    print("received", g_var, h_var)
    print("f")
    return "f"

@dag(max_concurrency=2)
def main():
    f(g(), h())

start = time()
main()
end = time()
print("time taken", end - start)
# h
# g
# received g h
# f
# time taken 1.004307508468628

Features

This library satisfies the following:

  • robust, well tested
  • lightweight
  • Thread Safe
  • Few dependencies
  • Legacy Python versions support (in the future)
  • MyPy compatible
  • Many Python implementations support (in the future)

In Tawazi, a computation sequence is referred to as DAG. The functions invoked inside the computation sequence are referred to as ExecNodes.

Current features are:

  • Specifying the number of "Threads" that the DAG uses
  • setup ExecNodes: These nodes only run once per DAG instance
  • debug ExecNodes: These are nodes that run only if RUN_DEBUG_NODES environment variable is set
  • running a subgraph of the DAG instance
  • Excluding an ExecNode from running
  • caching the results of the execution of a DAG for faster subsequent execution
  • Priority Choice of each ExecNode for fine control of execution order
  • Per ExecNode choice of parallelization (i.e. An ExecNode is allowed to run in parallel with other ExecNodes or not)
  • and more!

Documentation

You can find the documentation here: Tawazi.

In this blog we also talk about the purpose of using Tawazi in more detail.

Note: The library is still at an advanced state of development. Breaking changes might happen on the minor version (v0.Minor.Patch). Please pin Tawazi to the Minor Version. Your contributions are highly welcomed.

Name explanation

The libraries name is inspired from the arabic word تَوَازٍ which means parallel.

Building the doc

Only the latest version's documentation is hosted.

If you want to check the documentation of a previous version please checkout the corresponding release, install the required packages and run: mkdocs serve

Developer mode

pip install --upgrade pip
pip install flit wheel

cd tawazi
flit install -s --deps develop

Future developments

This library is still in development. Breaking changes are expected.

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

tawazi-0.6.0.tar.gz (168.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tawazi-0.6.0-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file tawazi-0.6.0.tar.gz.

File metadata

  • Download URL: tawazi-0.6.0.tar.gz
  • Upload date:
  • Size: 168.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for tawazi-0.6.0.tar.gz
Algorithm Hash digest
SHA256 b72df7e3afc20d663ae37877757bef813a38522906d92819b783d5dea9982e97
MD5 b0ed937c3b09e9c3dd0715ea1a71f727
BLAKE2b-256 91ac1622da43a76c1793d34db3ae73d3b0ee91296c9019467b2d944947c1326a

See more details on using hashes here.

File details

Details for the file tawazi-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: tawazi-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for tawazi-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09eb768faa478a1cf0ed8e4e1b4a251725d4ebbf8f40c3effdbc0a1184dd196b
MD5 b118ea7067a2c3483687a253dc4b052e
BLAKE2b-256 da8cf55e5266b672cf762902e47c6434dabada40692ee62d9a635eb7bc4f164a

See more details on using hashes here.

Supported by

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