Skip to main content

Cowait is a framework for creating containerized workflows with asynchronous Python.

Project description

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. However, Cowait can be used to easily build many types of distributed applications.

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

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. Or things might straight up break occasionally.

Getting Started

Requirements

  • docker
  • python 3.6+

Installation

$ pip install cowait

Task Development

First Task

  1. Write a task class.
# hello.py
from cowait import task

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

All files within the current directory is bundled into a task 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 containing the task to cowait run. In the same folder as hello.py, run:

$ cowait run hello

Notes

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

Subtasks, Arguments & Return Values

Tasks can create subtasks, by importing and calling other tasks as if they were asynchronous python functions. Subtasks accept arguments and return results. Arguments and results must be JSON serializable.

from cowait import task
from some_subtask import SomeSubtask

@task
async def MainTask(some_input: int = 5):
    subtask_result = await SomeSubtask(custom_argument = 'hello')
    print('Subtask finished with result', subtask_result)
    return 'ok'

Task Contexts

Tasks belong to a Task Context. If you have not explicitly defined one by creating a cowait.yml file, the enclosing folder will be used along with sensible defaults. Everything in the task context directory will be bundled into the final task image. A task context can be used to package multiple tasks into a single image, customize dockerfiles, and to add extra pip requirements.

Pushing Task Images

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

version: 1
cowait:
    image: cowait/task-test

Once the image url has been configured, you can push the image:

$ 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 to apply some RBAC rules to allow pods to interact with other pods. A sample configuration is provided in k8setup.yml, which will allow pods owned by the default service account to create, list and destroy other pods.

Tasks will run on your default configured cluster (the one returned by $ kubectl config current-context).

Running Tasks

Once the cluster has been configured, simply run a task with the kubernetes cluster provider:

$ cowait run hello --cluster kubernetes

Development

Requirements

  • docker
  • python 3.6+
  • pipenv/virtualenv (optional)

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

If you have access to cowait on Docker Hub you can also push it automatically:

$ ./build.sh --push

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

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

cowait-0.3.0.tar.gz (60.7 kB view hashes)

Uploaded Source

Built Distribution

cowait-0.3.0-py3-none-any.whl (116.8 kB view hashes)

Uploaded Python 3

Supported by

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