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.yamlProgrammatic
Configure in Python code with
pyworkflow.configure()Per-Call Override
Override settings per
start() callEnvironment Variables
Configure via environment for deployment flexibility
Configuration Priority
When you callpyworkflow.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.Config File (Recommended)
The simplest way to configure PyWorkflow is with apyworkflow.config.yaml file in your
project directory:
Automatic Loading
The config file is automatically loaded when:- CLI commands -
pyworkflow worker run,pyworkflow workflows list, etc. - Python code - When you call
pyworkflow.start()orpyworkflow.get_config()
Config File Location
PyWorkflow looks forpyworkflow.config.yaml in the current working directory (where
you run your Python script or CLI command from).
Project Structure
PyWorkflow supports two ways to organize your workflow code. Themodule 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:Option 2: Package Directory (Recommended)
For larger projects, organize workflows into a package with multiple files:How Discovery Works
When PyWorkflow imports your module:- Module Import: Python imports the specified module (e.g.,
workflowsorworkflows/__init__.py) - Decorator Registration: The
@workflowand@stepdecorators automatically register functions in the global registry - Explicit Exports: For package directories,
__init__.pyimports 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:__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
Storage Backends
Per-Call Overrides
Override configuration for individualstart() calls:
Parameter Priority Example
Environment Variables
Environment variables provide deployment flexibility:Configuration Patterns
Development vs Production
- Development
- Production
Testing Configuration
Conditional Configuration
Fault Tolerance Settings
Configure auto recovery behavior for workflows that experience worker crashes.- Config File
- Programmatic
- Per-Workflow
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.