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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68e7d20d6c8b2f9825da16647ef1ba51a36812a57273dd4beae178532c47cc55
|
|
| MD5 |
17300e621266247acb1eea3c32a150f7
|
|
| BLAKE2b-256 |
37aba4365f4a30019bf4032bba9a2b9369ebef93a67f01a61f9fcd18f0724e57
|
Provenance
The following attestation bundles were made for andaction-1.0.0.tar.gz:
Publisher:
release.yml on tolstovdmit/andaction
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
andaction-1.0.0.tar.gz -
Subject digest:
68e7d20d6c8b2f9825da16647ef1ba51a36812a57273dd4beae178532c47cc55 - Sigstore transparency entry: 1162831825
- Sigstore integration time:
-
Permalink:
tolstovdmit/andaction@a3398076e1287bf4b670df1c118fc7da8996138a -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/tolstovdmit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3398076e1287bf4b670df1c118fc7da8996138a -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d26378a6c36acc66c6e0d6243faad4a2541a14d9e7f54f49be8bb1f8e99a4c60
|
|
| MD5 |
3ed46c9ef9698a53633e78718fb7ee13
|
|
| BLAKE2b-256 |
f23c88f5abe945cb8abb2fec0032d256ff43f01eefdcb6b73d003575abfa4080
|
Provenance
The following attestation bundles were made for andaction-1.0.0-py3-none-any.whl:
Publisher:
release.yml on tolstovdmit/andaction
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
andaction-1.0.0-py3-none-any.whl -
Subject digest:
d26378a6c36acc66c6e0d6243faad4a2541a14d9e7f54f49be8bb1f8e99a4c60 - Sigstore transparency entry: 1162831949
- Sigstore integration time:
-
Permalink:
tolstovdmit/andaction@a3398076e1287bf4b670df1c118fc7da8996138a -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/tolstovdmit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a3398076e1287bf4b670df1c118fc7da8996138a -
Trigger Event:
push
-
Statement type: