requirements attribute and fal builds an optimized, cached environment for you. This approach handles CUDA setup, PyTorch index URLs, and environment isolation automatically based on your chosen machine type.
If you need system-level packages, a specific base image, or a non-Python runtime, use a custom container instead. If you need to include local Python modules or clone external repositories, see Import Code. For an overview of when to use which approach, see Environment and Runtime.
Defining Requirements
Therequirements attribute in your fal.App class is where you specify the Python packages your model needs. fal ensures these are installed in the runner’s environment before setup() is called.
torch==2.4.0) to ensure reproducible builds. Use the requirements attribute instead of running pip install inside setup(), since packages in requirements are installed during the container build and cached across deploys. Only include the packages your app actually needs to keep startup times short.
When you deploy, fal creates an isolated environment based on your machine_type, installs your listed packages, and caches the resulting container image. On subsequent deploys, unchanged requirements are served from cache. Your setup() method then runs on the provisioned runner to load the model into memory.
Using Prebuilt Wheels
You can install packages directly from wheel URLs. This is useful for custom-built packages or packages not available on PyPI.Direct URL
Provide the full URL to a wheel file:Package @ URL (PEP 440)
Use thepackage@url syntax to give the package a name for dependency resolution:
mypackage, as pip can properly track the dependency.
Alternative Package Indexes
Use--extra-index-url or --find-links to install packages from alternative sources.
Extra Index URL
Install packages from an additional PyPI-compatible index:Find Links
Use--find-links to search for packages in a directory or URL containing wheel files:
Multiple Indexes
Combine multiple index sources when needed:Private Packages
Private Git Repositories
Install directly from a private GitHub repository using a personal access token:Private PyPI Index
Install from a private PyPI server with authentication:Pre-signed URLs
For private storage (S3, GCS, etc.), generate a pre-signed URL with an expiration time:Dynamic Wheel Selection
When you need different wheels for different Python versions or platforms, use a helper function:Helper functions are evaluated at deploy time on your local machine, so they have access to local environment variables and can make decisions based on the target Python version.
Importing Local Code
Learn how to bring your local Python modules and files into the fal runtime.