- Reuse existing code: Leverage your existing Python modules and libraries
- Organize your codebase: Split your application logic into multiple files for better maintainability
- Use external dependencies: Integrate with third-party packages or libraries not included in the base environment
- Share code across projects: Import common utilities or models from shared repositories
Requirements
App Files
Theapp_files attribute allows you to include local files and directories from your local machine in your fal application, making them available in the serverless environment exactly as they appear locally.
Use this to bring your local code, configs, weights, or any other files from your local filesystem to the fal serverless environment. Files and imports work the same way they do on your local machine.
Basic Usage
Add files or directories to your application by listing their local paths in theapp_files attribute:
How App Files Work
When you include files inapp_files, they are transferred to the serverless environment and made available relative to your fal app file location, exactly as they exist on your local machine.
Key Points:
- Files maintain their relative structure to your app file
- Imports work naturally - no special prefixes needed
- File paths work with standard relative paths (
./,../) - The serverless environment mirrors your local file layout
Setting the Context Directory
By default, all file paths are resolved relative to the directory containing your fal app file. You can customize this base directory using theapp_files_context_dir attribute:
- Absolute paths are not allowed and will be rejected
- All paths must be within the context directory
- Paths attempting to escape the context directory (e.g.,
../../outside) will be rejected. To access these, setapp_files_context_dirto a higher directory. - All included files are read-only in the serverless environment
- Files are included on a per-app basis - files uploaded for one app will not be available in another app unless specified in its
app_files
Ignoring Files
Useapp_files_ignore to exclude unwanted files using regex patterns:
Best Practices
- Keep it organized: Use meaningful directory names and structure
- Minimize deployment size: Only include the files you actually need
- Use
app_files_context_dir: Set a common base directory for multi-app projects - Use relative paths: Better portability across different environments
- Ignore unnecessary files: Use
app_files_ignoreto exclude development and testing files - Never use absolute paths: They will be rejected
- Think local-first: Your serverless environment will mirror your local file structure
Local Python Modules
You can import local Python modules by adding them to thelocal_python_modules attribute of your fal application.
Git Repositories
You can clone Git repositories directly into your fal application using theclone_repository function.
This is particularly useful for incorporating external libraries, model implementations, or shared code from Git repositories.