@conda_base decorator allows you to specify Conda packages that apply to all steps in your Metaflow flow by default. Individual steps can override or augment these dependencies using @conda.
Overview
Use@conda_base to declare flow-wide Conda dependencies. This decorator sets default packages and Python versions that all steps inherit, reducing repetition in your flow definition.
When to Use
- Common dependencies: When most/all steps need the same Conda packages
- Reduce repetition: Avoid specifying the same packages on every step
- Default Python version: Set a consistent Python version across the flow
- Base environment: Establish a foundation that steps can extend
Parameters
Dictionary of Conda libraries to include in all steps by default. Keys are package names, values are version constraints.Version constraints can be:
- Simple pinned versions:
"1.2.3" - Range constraints:
">=4.0,<6.0" - Channel-specific:
"conda-forge::package" - Empty string for floating versions:
""
Additional Conda channels to search for packages. By default, conda-forge is used.
Python version constraint for all steps by default. If not specified, the current Python version is used.Can be a specific version or a constraint expression:
"3.8.12"- Exact version">=3.8,<3.9"- Range constraint"<3.11"- Upper bound only
If set to
True, disables Conda environments for all steps by default. Individual steps can still enable Conda using @conda.Deprecated Parameters
DEPRECATED - Use
@pypi_base(packages=...) instead.Dictionary of PyPI packages. Superseded by the dedicated @pypi_base decorator.DEPRECATED - Use
@pypi_base(extra_indices=...) instead.Additional PyPI package sources. Use @pypi_base decorator instead.DEPRECATED - Use
@named_env_base(name=...) instead.Reference to a named environment. Superseded by @named_env_base decorator.DEPRECATED - Use
@named_env_base(pathspec=...) instead.Reference to a pathspec of an existing step. Use @named_env_base decorator instead.DEPRECATED - Use
@named_env_base(fetch_at_exec=...) instead.Fetch environment at execution time. Use @named_env_base decorator instead.Usage Examples
Basic Flow-Wide Dependencies
Set common packages for all steps:Extending Base with Step-Specific Packages
Add additional packages to specific steps:Overriding Base Versions
Step-level decorators override base versions:Combining Multiple Base Decorators
Use@conda_base with @pypi_base for mixed dependencies:
Disabling Conda by Default
Disable Conda for all steps except those that explicitly enable it:Custom Channels
Specify custom Conda channels for all steps:Merge Behavior
When combining@conda_base with step-level decorators:
Package Merging
Python Version Override
Channel Merging
Channels from both decorators are combined:Interaction with Other Decorators
With @pypi_base
Combine Conda and PyPI base dependencies:With @named_env_base
Cannot combine@conda_base with @named_env_base - they are mutually exclusive:
Multiple Flows in Same File
Each flow can have its own@conda_base configuration:
Related Decorators
@conda- Step-level Conda dependencies@pypi_base- Flow-level PyPI dependencies@pypi- Step-level PyPI dependencies@named_env_base- Flow-level named environment reference@named_env- Step-level named environment reference
Requirements
- Must use
--environment=condawhen running the flow - Requires Conda/Mamba/Micromamba installed
- Applied at the class level (before the flow class definition)
Notes
- Multiple
@conda_basedecorators are not allowed on the same flow - Step-level
@condaalways overrides conflicting@conda_basesettings - Environments are resolved once and cached for reuse
- Compatible with all Metaflow execution environments (local, AWS Batch, Kubernetes)
