Skip to main content

No project description provided

Project description

and-action

A lightweight Python workflow engine built around persistent state machines. Business logic lives in stage methods on a Process class; the framework handles persistence, scheduling, and state transitions.

Overview

Each process is a class with stage methods. Stages return outcomes that tell the engine what to do next: advance to another stage, sleep until a time, wait for an external event, or end. Process state is persisted to a database between stages, so processes survive restarts and can run across distributed workers.

Installation

pip install and-action

Quick Start

1. Define your process

from datetime import timedelta
from andaction import Process, WaitOn, Event, Timeout

class GreetingProcess(Process):

    def on_start(self):
        print(f"Hello, {self.pinfo.vars['name']}!")
        return self.sleep("on_followup", timedelta(seconds=5))

    def on_followup(self):
        print("Hope you are well.")
        return self.end()

2. Set up the app

import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
from andaction import App
from andaction.db import ProcessRepo

engine = create_async_engine("sqlite+aiosqlite:///myapp.db")
repo = ProcessRepo(engine)

app = App(repo)
app.reg(GreetingProcess)

3. Start a process and run

async def main():
    await repo.initialize()
    await app.start("greeting", vars={"name": "Alice"})
    await app.run()  # starts the scheduler loop

asyncio.run(main())

4. Custom factory (when a process needs dependencies)

import httpx

http = httpx.AsyncClient()

@app.process_factory
def greeting(pinfo) -> GreetingProcess:
    return GreetingProcess(pinfo, http)

Outcomes

Outcome Method Behavior
NextStage self.next("stage_name") Advance to another stage immediately
Sleep self.sleep("stage_name", timedelta) Pause until a timer fires, then resume
WaitOn return WaitOn(Event(...), Timeout(...)) Wait for an external event or timeout
End self.end() Terminate the process

Persistence

ProcessRepo is a SQLAlchemy-backed implementation of the ProcessStorage interface. Pass any custom implementation to App to use a different backend.

class MyStorage(ProcessStorage):
    async def create(self, pinfo): ...
    async def update(self, pinfo): ...
    async def acquire_ready_procs(self, limit=10): ...
    async def acquire_event_proc(self, process_id, event_type): ...
    async def get_by_correlation_id(self, correlation_id): ...

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

andaction-1.0.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

andaction-1.0.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file andaction-1.0.0.tar.gz.

File metadata

  • Download URL: andaction-1.0.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for andaction-1.0.0.tar.gz
Algorithm Hash digest
SHA256 68e7d20d6c8b2f9825da16647ef1ba51a36812a57273dd4beae178532c47cc55
MD5 17300e621266247acb1eea3c32a150f7
BLAKE2b-256 37aba4365f4a30019bf4032bba9a2b9369ebef93a67f01a61f9fcd18f0724e57

See more details on using hashes here.

Provenance

The following attestation bundles were made for andaction-1.0.0.tar.gz:

Publisher: release.yml on tolstovdmit/andaction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file andaction-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: andaction-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for andaction-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d26378a6c36acc66c6e0d6243faad4a2541a14d9e7f54f49be8bb1f8e99a4c60
MD5 3ed46c9ef9698a53633e78718fb7ee13
BLAKE2b-256 f23c88f5abe945cb8abb2fec0032d256ff43f01eefdcb6b73d003575abfa4080

See more details on using hashes here.

Provenance

The following attestation bundles were made for andaction-1.0.0-py3-none-any.whl:

Publisher: release.yml on tolstovdmit/andaction

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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