π‘οΈ Introducing Falyx: A Resilient CLI Framework for Modern Workflows
In the ever-evolving landscape of software development, tools that offer resilience, clarity, and introspection are invaluable.
Enter Falyxβa robust, asynchronous command-line interface (CLI) framework designed to streamline and fortify your workflows.
βοΈ What is Falyx?
Falyx is a Python-based CLI framework that empowers developers to build modular, fault-tolerant command-line applications. Inspired by the discipline and strength of a phalanx, Falyx ensures that each component of your workflow stands firm β even in the face of failure.
π Key Features
- Modular Action Chaining Compose complex workflows by chaining together discrete actions, each with its own context and lifecycle.
- Built-in Retry Mechanism β Handle flaky or transient failures with configurable retry policies, including exponential backoff.
- Lifecycle Hooks β Inject logic at every stage:
before,after,on_success,on_error, andon_teardown. - Execution Tracing β Built-in logging, result tracking, and timing for complete visibility.
- Async-First Design β Built on
asyncio, with optional multiprocessing viaProcessAction. - Extensible CLI Menus β Create interactive or headless menus using
prompt_toolkitandrich, with support for history, tags, toggle states, and more.
π§ͺ Getting Started
Here’s a simple example to illustrate how Falyx can be used to build a resilient CLI application:
import asyncio
import random
from falyx import Falyx, Action, ChainedAction
# Define a flaky asynchronous step
async def flaky_step():
await asyncio.sleep(0.2)
if random.random() < 0.5:
raise RuntimeError("Random failure!")
return "ok"
# Create actions with retry enabled
step1 = Action(name="step_1", action=flaky_step, retry=True)
step2 = Action(name="step_2", action=flaky_step, retry=True)
# Chain the actions together
chain = ChainedAction(name="my_pipeline", actions=[step1, step2])
# Set up the CLI menu
falyx = Falyx("π Falyx Demo")
falyx.add_command(
key="R",
description="Run My Pipeline",
action=chain,
logging_hooks=True,
preview_before_confirm=True,
confirm=True,
)
# Entry point
if __name__ == "__main__":
asyncio.run(falyx.run())
When run, this script presents an interactive CLI menu with built-in preview, confirmation, and retry handling.
β― python simple.py
π Falyx Demo
[R] Run My Pipeline
[Y] History [Q] Exit
>
Or run headlessly using intuitive CLI arguments:
β― python simple.py run R
Command: 'R' β Run My Pipeline
βββ β ChainedAction 'my_pipeline'
βββ β Action 'step_1'
β β» Retries: 3x, delay 1.0s, backoff 2.0x
βββ β Action 'step_2'
β» Retries: 3x, delay 1.0s, backoff 2.0x
Confirm execution of R β Run My Pipeline (calls `my_pipeline`) [Y/n] y
[2025-04-15 22:03:57] WARNING β οΈ Retry attempt 1/3 failed due to 'Random failure!'.
β
Result: ['ok', 'ok']
π Real-World Applications
Falyx is particularly well-suited for:
- Automation Script: Build resilient tools that self-heal from transient errors.
- Data Pipelines: Orchestrate complex data flows with retry logic and full observability.
- Deployment Tooling: Create safe deploys with preview, rollback, and confirmation baked in.
π Learn More
Falyx was designed for developers who donβt just want CLI tools to run β they want them to recover, report, and adapt.
If that sounds like you, give it a spin and start building resilient command flows today.
“Like a phalanx: organized, resilient, and reliable.” βοΈ