Skip to main content

lightweight flow-control framework (sync + async support)

Project description

Freactor

Freactor is a lightweight flow-control framework for Python. It provides a simple way to define task pipelines using reducers and step transitions, supporting both synchronous and asynchronous (asyncio) execution.

Features

Task orchestration with clear step transitions (SUCCESS, FAILURE, RETRY, ABORT).

Reducer decorators with automatic retry/delay logic.

Async support: AsyncFreactor + async_freducer for coroutine-based workflows.

Logging with task IDs for easy observability.

High performance:

~20–35k async tasks/sec per process (I/O bound).

Supports 1M+ reducer steps per process in a single event loop.

Minimal dependencies, works with Python 3.8+.

Installation

pip install freactor

Or install in development mode:

git clone https://github.com/Pro-YY/freactor.git
cd freactor
pip install -e .

Quick Start

1. Define Reducers

import asyncio
import logging
from freactor import StatusCode, async_freducer

log = logging.getLogger(__name__)

SUCCESS = StatusCode.SUCCESS

@async_freducer(retry=3, delay=1)
async def step1(data):
    log.info(f"[task {data['_task_id']}] step1 running...")
    await asyncio.sleep(1)  # simulate async workload
    return SUCCESS, {"step1": True}, "done"

2. Configure Task Flow

TASK_CONFIG = {
    "example_task": {
        "init_step": ("example_reducers", "step1"),
        "table": {
            ("example_reducers", "step1"): {SUCCESS: None}
        },
    }
}

3. Run Tasks with AsyncFreactor

import asyncio
from freactor import AsyncFreactor

async def main():
    f = AsyncFreactor(
        {"task_config": TASK_CONFIG, "import_reducer_prefix": "example_reducers."},
        num_actors=8,
    )
    await f.run_task("example_task", {"param": "demo"})
    await f.run_forever()

asyncio.run(main())

Benchmarks

AsyncFreactor:

100k tasks in ~4.3s (≈22k tasks/s).

1M tasks in ~45s on a 10-core machine.

Multiprocessing scaling: Combine multiple processes (each with its own actors) or connect pods via Redis Streams / RabbitMQ for horizontal scalability.

License

[MIT] This project is licensed under the MIT License.

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

freactor-1.0.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

freactor-1.0.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file freactor-1.0.1.tar.gz.

File metadata

  • Download URL: freactor-1.0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for freactor-1.0.1.tar.gz
Algorithm Hash digest
SHA256 52b55374c58dfc8b5c8b2b5c69c465f196ee5277c3a373ffcea7895582e77a8f
MD5 30a1a53dd897d26b996f0e1a61c90fb0
BLAKE2b-256 1bffd30f347e7ff093635bfd6b617ccb825dd0acda7e2fe76e4e0a0d4fc62b07

See more details on using hashes here.

File details

Details for the file freactor-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: freactor-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for freactor-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62bb350581502a7918d0f95c026744d3908ec79a67642ab2fb5f23373f5eb65c
MD5 5d363a214e2202023d3019d432f96a53
BLAKE2b-256 e439a4b5f978a005efd59a79c6d7349dea62e4d127578dce7b7b327a5b348680

See more details on using hashes here.

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