Skip to main content

Overview

PyWorkflow configuration determines how workflows execute: which runtime to use, where to store state, and default behaviors. Configuration can come from multiple sources with a clear priority order.

Config File

Zero-code configuration via pyworkflow.config.yaml

Programmatic

Configure in Python code with pyworkflow.configure()

Per-Call Override

Override settings per start() call

Environment Variables

Configure via environment for deployment flexibility

Configuration Priority

When you call pyworkflow.start(), configuration is resolved in this order:
When you use Celery runtime in the config file (runtime: celery), PyWorkflow automatically sets durable=True since Celery requires durable mode.

The simplest way to configure PyWorkflow is with a pyworkflow.config.yaml file in your project directory:

Automatic Loading

The config file is automatically loaded when:
  1. CLI commands - pyworkflow worker run, pyworkflow workflows list, etc.
  2. Python code - When you call pyworkflow.start() or pyworkflow.get_config()

Config File Location

PyWorkflow looks for pyworkflow.config.yaml in the current working directory (where you run your Python script or CLI command from).
Always run your scripts from the directory containing pyworkflow.config.yaml, or use programmatic configuration if you need more control.

Project Structure

PyWorkflow supports two ways to organize your workflow code. The module field in your config file tells PyWorkflow where to find and import your workflows.

Option 1: Single File

For simple projects, define all workflows in a single file:
For larger projects, organize workflows into a package with multiple files:

How Discovery Works

When PyWorkflow imports your module:
  1. Module Import: Python imports the specified module (e.g., workflows or workflows/__init__.py)
  2. Decorator Registration: The @workflow and @step decorators automatically register functions in the global registry
  3. Explicit Exports: For package directories, __init__.py imports trigger the decorators
The key is that importing your module must trigger the @workflow decorators to run. With a package directory, make sure __init__.py imports all workflow functions.

Nested Packages

For large applications, you can nest packages deeper:
Each nested __init__.py should re-export workflows from its submodules to ensure they are discovered when the top-level module is imported.

Programmatic Configuration

For more control, configure PyWorkflow in your Python code:

Configuration Options

Event limit settings should not be modified unless you fully understand the implications. See Limitations for details.

Storage Backends


Per-Call Overrides

Override configuration for individual start() calls:

Parameter Priority Example


Environment Variables

Environment variables provide deployment flexibility:

Configuration Patterns

Development vs Production

Testing Configuration

Conditional Configuration


Fault Tolerance Settings

Configure auto recovery behavior for workflows that experience worker crashes.

Recovery Options

For durable workflows, recovery replays events to restore state. For transient workflows, recovery restarts from the beginning. See Fault Tolerance for details.

Reading Current Configuration

Access the current configuration programmatically:

Worker Configuration

When running Celery workers, you can configure worker behavior through CLI options. See the CLI Guide for all available options including:
  • Autoscaling: Automatically scale worker processes based on load
  • Task limits: Control tasks per child and prefetch multiplier
  • Time limits: Set hard and soft time limits for tasks
  • Celery passthrough: Forward arbitrary arguments to Celery

Next Steps

CLI Guide

Learn CLI commands and options.

Celery Brokers

Configure message brokers for distributed execution.

Storage Backends

Choose the right storage backend.

Fault Tolerance

Learn about automatic recovery.