Simple workflows.
Project description
Hymir
Hymir is a python library for creating and running simple workflows by composing together Chains (which run sequentially) and Groups (which run in parallel) of jobs.
Hymir is built on top of redis for intermediate storage and tracking workflow state, and comes with an Executor for running the workflows using Celery.
Installation
pip install hymir
Usage
Using the @job
decorator is the simplest way to define a job. The decorated
function should return a Success
, Failure
, Retry
, or CheckLater
object.
The only limitations are:
- The decorated function must be importable from other files
(
from mymodule import myjob
should work) - The outputs and inputs of a job must be JSON-safe.
When jobs depend on the output of other jobs, you can specify the inputs of the
job using the inputs
parameter of the @job
decorator and the output of the
job using the output
parameter.
from hymir.job import Success
from hymir.config import Config, set_configuration
from hymir.executors.celery import CeleryExecutor
from hymir.workflow import (
Workflow,
job,
Group,
Chain,
)
@set_configuration
def set_config(config: Config):
config.redis_url = "redis://localhost:6379/0"
@job(output="words")
def uppercase_word(word: str):
return Success(word.upper())
@job(inputs=["words"], output="count")
def count_uppercase_words(words: list[str]):
count = sum(1 for word in words if word.isupper())
return Success(count)
workflow = Workflow(
Chain(
Group(
uppercase_word("hello"),
uppercase_word("world"),
),
count_uppercase_words()
)
)
# This assumes you've already setup & configured a celery app before you
# get here.
executor = CeleryExecutor()
workflow_id = executor.run(workflow)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hymir-0.1.3.tar.gz
.
File metadata
- Download URL: hymir-0.1.3.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | edfd2fc71de2637f73a82faa062b72ba1d4a081ccf25c48df3e7d42836abeff7 |
|
MD5 | f046d2a8d7fa2f1cd316f33bd0211d8d |
|
BLAKE2b-256 | 278c4d60cabf264b27a907c90d1ece09e2884dc66d73a9de9585e3f19e7f726b |
File details
Details for the file hymir-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: hymir-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.11.8 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bee5c9a974932d2b9021a55a1a905622d1fe659e05c6240f12ce7d4c4c52ff41 |
|
MD5 | 3e40fd75e4a904c3beadc20c16a3c330 |
|
BLAKE2b-256 | 18b9b33061eccd9a537a782932006e94af4a3bee6f04e3ce200eb896f40121b6 |