Skip to main content

cowait

cowait

Actions Status PyPI version Website shields.io

Cowait is a framework for creating containerized distributed applications with asynchronous Python. Containerized functions, called Tasks, can run locally in Docker or on remote Kubernetes clusters. The intention is to build a novel type of workflow engine that offers maximum flexibility while also requiring minimal setup and configuration. Because of the loose definition of what a Task could be, and the integration with Docker & Kubernetes, Cowait can be used to easily build many types of distributed applications.

Check out the documentation at https://cowait.io/docs/quick-start/

Notice

Cowait is still in fairly early development. We invite you to try it out and gladly accept your feedback and contributions, but please be aware that breaking API changes may be introduced.

Community

Join the Cowait development Slack channel!

Get your invite at https://slack.cowait.io

Getting Started

Requirements

  • docker
  • python 3.6+

Installation

$ pip install cowait

Task Development

First Task

  1. Write a task.

Tasks can be written as decorated functions or subclasses of cowait.Task. The easiest way is to write a decorated function:

# hello.py
from cowait import task

@task
async def Hello():
    print('Hello World')
  1. Build a task image

All files within the current directory is bundled into a docker image.

In the same folder as hello.py, run:

$ cowait build
  1. Run it locally

To run a task, pass the name of the module import name to cowait run. Since our task code lives in hello.py, the module name will be hello. In the same folder as hello.py, run:

$ cowait run hello

Notes

  • hello supplied to cowait run is the python module name. This module should contain exactly one task class. Modules can be single python files or subdirectories with __init__.py files.
  • The actual function/class name of the task does not matter when running from the CLI, only when importing and executing tasks from python.

Subtasks, Arguments & Return Values

Tasks can execute subtasks by importing and calling asynchronously using the await keyword. Subtasks accept named arguments and return results, much like regular functions.

Suppose we have a Square task that squares an integer.

# square.py
from cowait import task

@task
async def Square(number: int) -> int:
    return number ** 2

We can import it to another task and execute it:

# main.py
from cowait import task
from square import Square

@task
async def MainTask():
    value = 22
    squared = await Square(number=22)
    print(f'{value} squared is {squared}!')

Task Contexts

A task context is a directory containing a cowait.yml configuration file. This directory will act as the root of a project, and everything within this folder is copied into the resulting docker image during the build step. If you have not created a cowait.yml file, the current working directory (when executing cowait build) will be used.

** Example Task Context **

 /var/stuff/my_cowait_project
   src/
     library.py
   cowait.yml
   requirements.txt
   task1.py
   task2.py

In this case, /var/stuff/my_cowait_project will be the context directory.

Pushing Task Images

Before you can run tasks on a Kubernetes cluster, they must be pushed to a docker registry that is accessible from the cluster. To do this, you must define a proper image name in the context configuration file.

version: 1
cowait:
  image: docker.io/username/cowait-task

Once the full image name has been configured, you can push the image using cowait push:

$ cowait push

Cluster Deployment

Requiurements

  • Configured kubernetes cluster context.
  • Docker registry accessible from the cluster.

First, ensure that the image has been pushed to your docker registry.

$ cowait push

Kubernetes Configuration

Before you can run tasks on a kubernetes cluster, you need a service account with permissions to create/list pods. A sample configuration is provided in k8setup.yml, which will allow any pods owned by the default service account to create, list and destroy other pods.

For detailed information about running on Kubernetes, see the documentation.

Running Tasks

To run tasks on a remote cluster, pass the cluster name using the --cluster option to cowait run.

Cowait comes with a predefined cluster called kubernetes which always refers to your default configured cluster (the one returned by $ kubectl config current-context).

$ cowait run docker.io/username/cowait-task --cluster kubernetes

Development

Requirements

  • docker
  • python 3.6+
  • poetry (recommended)

Installation

  1. Clone repository
  2. $ python3 -m pip install -e .

Changes to the cowait/ directory require a rebuild of the base image. You can do this with the provided helper script in the root of the repository:

$ ./build.sh

Note: Tasks will have to rebuilt with cowait build for the changes to take effect.

Generate Documentation You can generate documentation (from docstrings) for Cowait to the /docs folder using pdoc3 (defined in Poetry as a dev dependency):

$ pdoc3 --skip-errors --html --output-dir docs/html cowait

Metadata

Release files for cowait 0.5.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 cowait 0.5.0
File Size Uploaded Provenance Actions
cowait-0.5.0.tar.gz 77.8 kB Without provenance Details for cowait-0.5.0.tar.gz

Built distribution (wheel)

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

Total release size: 193.2 kB

Release files / cowait-0.5.0.tar.gz

Download URL cowait-0.5.0.tar.gz
Size 77.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a452e22dc4d6bd368093d5b2903c6f8383e3ff954ec045e37429c5ae63f5528e
BLAKE2b-256 checksum
How to use checksums
7a3d066c1a4ad5550cb63e720cbe2490fc26dbf3258c6a07fa3bb6b4e4dff350
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / cowait-0.5.0-py3-none-any.whl

Download URL cowait-0.5.0-py3-none-any.whl
Size 115.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0bfe0d3ffd7da9790d4a0378457f6ae0eeb9710bd68fb40c92eaea555999f07
BLAKE2b-256 checksum
How to use checksums
636184c8a01820624f237590467bc45a383b1049a82622080e80cd6c22662d5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Security for cowait 0.5.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.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files No provenance

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