Skip to main content

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.

Metadata

Release files for tawazi 0.6.2

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

Source distribution (sdist)

Source distribution for tawazi 0.6.2
File Size Uploaded Provenance
tawazi-0.6.2.tar.gz 169.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 219.5 kB

Release files / tawazi-0.6.2.tar.gz

Download URL tawazi-0.6.2.tar.gz
Size 169.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e1bb8e1b818008272b95d35d0f7fb92d9b3d95c155c934143bbc2342d32c664d
BLAKE2b-256 checksum
How to use checksums
e11435a8f31b3e27fbdbaa87ff186d34571de0de03820a063dfe59bb065f739f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / tawazi-0.6.2-py3-none-any.whl

Download URL tawazi-0.6.2-py3-none-any.whl
Size 50.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01f2a5c861d54333d64ed0f547cf15f424b176dd4a66fddfe7286b1bf8fe0678
BLAKE2b-256 checksum
How to use checksums
98afb87a57362a994ac1baa5c7b3c863f8285c0f4a7470ab48574d816436c6da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Security for tawazi 0.6.2

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.

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