Skip to main content

Fractal Processes

Fractal Processes is a small workflow engine: processes assembled from actions and run against a shared context, so a workflow is data rather than code.

PyPI Version Build Status

Installation

pip install fractal-processes

Background

A Process is an ordered list of Actions, run against a ProcessContext that carries state from one to the next. Actions cover the ordinary things a workflow does — set a value, fetch or store an entity, dispatch a command, publish an event — and control flow is itself made of actions, so branching, loops and sub-processes live inside the process rather than in Python around it.

That is the whole point. A workflow assembled from data can be stored, inspected, and changed without a deploy; a workflow written as a function cannot. The cost is that you give up Python's syntax for the parts that become actions, which is why this is worth reaching for when a workflow is configuration and not worth it when it is just code.

Self-contained by design: this package imports no other Fractal library except fractal-specifications, which it uses to express conditions.

Usage

from fractal_processes import (
    IfElseAction,
    Process,
    ProcessContext,
    SetContextVariableAction,
    SetValueAction,
    field_gt,
)

process = Process([
    SetContextVariableAction(discount=0),
    IfElseAction(
        field_gt("order.total", 100),
        [SetValueAction("discount", 10)],
        [SetValueAction("discount", 0)],
    ),
])

ctx = ProcessContext({"order": {"total": 250}})
process.run(ctx)

ctx["discount"]      # 10
ctx.order.total      # 250 — attribute access works too

ProcessContext supports dotted keys ("order.total") and attribute access, and merges nested dicts rather than replacing them.

Actions

StateSetContextVariableAction, SetValueAction, GetValueAction, ApplyToValueAction, IncreaseValueAction

EntitiesAddEntityAction, UpdateEntityAction, FetchEntityAction, FindEntitiesAction, DeleteEntityAction

MessagingCommandAction, QueryAction, PublishEventAction

Control flowIfElseAction, WhileAction, ForEachAction, TryExceptAction, SubProcessAction, ParallelAction

DiagnosticsPrintAction, PrintValueAction, RaiseExceptionAction, CreateSpecificationAction

Conditions

Conditions are specifications, built with helpers that read the context:

from fractal_processes import field_equals, field_gt, field_in, has_field, on_field

field_equals("user.role", "admin")
field_gt("order.total", 100)
field_in("status", ["draft", "review"])
has_field("user.email")
on_field("order.lines", lambda lines: len(lines) > 3)

CallableSpecification wraps any callable, for the cases the helpers do not cover.

Async

AsyncProcess and AsyncAction are the awaitable equivalents. Both provide a synchronous wrapper, so an async process can be run from sync code.

Development

make dev-install
make test
make lint
make format

Download files

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

Source Distribution

fractal_processes-1.1.0.tar.gz (48.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fractal_processes-1.1.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file fractal_processes-1.1.0.tar.gz.

File metadata

  • Download URL: fractal_processes-1.1.0.tar.gz
  • Upload date:
  • Size: 48.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.34.2

File hashes

Hashes for fractal_processes-1.1.0.tar.gz
Algorithm Hash digest
SHA256 357bc6d5df62bca5a5df1a17137237a300487c0fca627d81e31541bb366b658f
MD5 b483206db9fa35eec3473e6aa4936034
BLAKE2b-256 b66e1d8c76ee72e58289eaa413d31a4d0e4fd065861814fba55559029e7b604e

See more details on using hashes here.

File details

Details for the file fractal_processes-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fractal_processes-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b1b21660ec829757ce288a1bac1473eea329a92800eec287f84f402800006da
MD5 75d996dfb20564b0398cd6ad180ef6a0
BLAKE2b-256 b0ff840332c2a73b9aa1ef36a58e47883e99b0c3befa6141e8264d15526143f3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.0

2 files

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