Skip to main content

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.backend_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hymir-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

hymir-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file hymir-0.1.0.tar.gz.

File metadata

  • Download URL: hymir-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 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

Hashes for hymir-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a06b9c714e0d8b0bc66d12a986d190c2b0cf9c8dd01f397e6fa035565cf95f29
MD5 7c6cdc878d3b58dbc079e5fc27244fb1
BLAKE2b-256 127b77b6834a4c97c4648486a7807cb9ba5c8dafcbb867abea6f96a51c246002

See more details on using hashes here.

File details

Details for the file hymir-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hymir-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 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

Hashes for hymir-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2afa9708d2dab5c272cbf94ba5d094810d53bcae7f5d77221b58ef5b7aae0cb
MD5 cd42e87503c765c1e2703c5872f3f2d2
BLAKE2b-256 54644687c69badc9d00e7fd88f1ba1e55b7d7d057d0e46bc468e2876de5265eb

See more details on using hashes here.

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