@conda decorator allows you to specify Conda packages required for a specific step in your Metaflow flow. This decorator augments any attributes set in the flow-level @conda_base decorator.
Overview
Use@conda to declare step-specific Conda dependencies. The decorator resolves packages from the Conda ecosystem (conda-forge by default) and creates an isolated environment for step execution.
When to Use
- Step-level dependencies: When only specific steps need certain Conda packages
- Version overrides: Override flow-level versions from
@conda_basefor specific steps - Mixed dependencies: Combine with
@pypifor hybrid Conda/PyPI environments - Different versions: Use different package versions across steps
Parameters
Dictionary of Conda libraries to include. 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 the environment. 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 the Conda environment for this step and uses the external environment instead.Deprecated Parameters
DEPRECATED - Use
@pypi(packages=...) instead.Dictionary of PyPI packages. Superseded by the dedicated @pypi decorator.DEPRECATED - Use
@pypi(extra_indices=...) instead.Additional PyPI package sources. Use @pypi decorator instead.DEPRECATED - Use
@named_env(name=...) instead.Reference to a named environment. Superseded by @named_env decorator.DEPRECATED - Use
@named_env(pathspec=...) instead.Reference to a pathspec of an existing step. Use @named_env decorator instead.DEPRECATED - Use
@named_env(fetch_at_exec=...) instead.Fetch environment at execution time. Use @named_env decorator instead.Usage Examples
Basic Usage
Specify a simple Conda dependency:Multiple Packages with Version Constraints
Different Versions Across Steps
Test compatibility with multiple package versions:Using Custom Channels
Combining with Flow-Level Decorator
Override base dependencies with step-specific versions:Disabling Conda for Specific Steps
Interaction with Other Decorators
With @pypi
Combine Conda and PyPI packages for mixed dependencies:With @named_env
Extend a named environment with additional packages:Merge Behavior
When combining@conda with @conda_base:
- Step-level overrides flow-level: Package versions in
@condaoverride those in@conda_base - Python version is overridden: Step-level
pythonparameter overrides flow-level - Channels are merged: Channels from both decorators are combined
- Disabled takes precedence: Setting
disabled=Trueat step level disables Conda entirely
Environment Resolution
Environments are resolved:- Locally: On the machine launching the flow
- Before execution: Prior to flow run or deployment
- Cached: Resolved environments are cached in S3/GS/Azure
- Shared: Cached environments are reused across runs
Related Decorators
@conda_base- Flow-level Conda dependencies@pypi- Step-level PyPI dependencies@pypi_base- Flow-level PyPI dependencies@named_env- Reference named environments@named_env_base- Flow-level named environment references
Requirements
- Must use
--environment=condawhen running the flow - Requires Conda/Mamba/Micromamba installed
- Remote execution (AWS Batch, Kubernetes) automatically handles environment creation
Notes
- Environments are hermetic and reproducible
- All transitive dependencies are locked for reproducibility
- Environments are reused when requirements don’t change
- Compatible with remote execution (AWS Batch, Kubernetes)
- Can mix with PyPI packages using
@pypidecorator
