Overview
Pure PyPI environments use only packages from the Python Package Index (PyPI), resolved using the standardpip tool. This mode is ideal when:
- You only need Python packages
- You want faster resolution times compared to mixed environments
- You’re familiar with requirements.txt format
- Your packages are available as wheels on PyPI
Using the @pypi Decorator
The@pypi decorator provides a straightforward way to specify PyPI-only dependencies:
simplecondaflow-pypi.py
Decorator Parameters
The@pypi and @pypi_base decorators accept:
packages: Dictionary of package names to version constraints- Simple version:
{"pandas": "1.4.0"} - Complex constraints:
{"numpy": ">=1.20,<2.0"} - Floating version:
{"requests": ""}(latest compatible version)
- Simple version:
python: Python version constraint- Simple:
"3.8.17" - Range:
">=3.8,<3.9"
- Simple:
extra_indices: List of additional PyPI indicesdisabled: Boolean to disable the environment for a step
Using requirements.txt
For more complex dependency specifications, use a requirements.txt file:req_numpy.txt
Supported Options
Metaflow supports a subset of requirements.txt syntax:- Package Specifications
- Options
- Extensions
Standard package syntax:
Non-Wheel Packages
Building from Source
When a package isn’t available as a wheel, Metaflow will automatically build it:requirements-build.txt
Building packages requires that you’re resolving on the same architecture as the target. Cross-platform builds are not supported due to potential compilation issues.
Architecture Restrictions
Non-wheel packages have important limitations:Same Architecture Requirement
You cannot resolve on your Mac laptop for Batch execution if the package requires building. The architectures must match.
Supported Sources
Source builds work for:
- Git repositories
- Local directories
- Source tarballs (
.tar.gz,.zip)
Combining with Non-Python Packages
Use the--conda-pkg extension to add system tools:
requirements-ffmpeg.txt
pip, while still including the ffmpeg binary from Conda.
This approach is useful when you want the speed and simplicity of pip resolution but need system utilities like
git-lfs, ffmpeg, or other non-Python tools.Performance Tips
Use Wheels When Possible
Packages available as wheels resolve faster and work cross-platform.
Pin Versions
Exact versions (
==) resolve faster than ranges and ensure reproducibility.Minimize Extras
Only include package extras you actually need (e.g.,
boto3[s3] not boto3[all]).Cache Built Wheels
Let Metaflow cache built wheels in S3/Azure/GS to avoid rebuilding.
Example: Complete Requirements File
Here’s a comprehensive example showing various features:requirements-complete.txt
