Including additional files
When your app needs additional files beyond the main script (like utility modules, configuration files, or data files), you can use the include parameter to specify which files to bundle with your app.
How include works
The include parameter takes a list of file paths (relative to the directory containing your app definition). These files are bundled together and made available in the app container at runtime.
include=["main.py", "utils.py", "config.yaml"]When to use include
Use include when:
- Your app spans multiple Python files (modules)
- You have configuration files that your app needs
- You have data files or templates your app uses
- You want to ensure specific files are available in the container
If you’re using specialized app environments like FastAPIAppEnvironment, Flyte automatically detects and includes the necessary files, so you may not need to specify include explicitly.
Examples
Multi-file Streamlit app
"""A custom Streamlit app with multiple files."""
import pathlib
import flyte
import flyte.app
image = flyte.Image.from_debian_base(python_version=(3, 12)).with_pip_packages(
"streamlit==1.41.1",
"pandas==2.2.3",
"numpy==2.2.3",
)
app_env = flyte.app.AppEnvironment(
name="streamlit-custom-app",
image=image,
args="streamlit run main.py --server.port 8080",
port=8080,
include=["main.py", "utils.py"], # Include your app files
resources=flyte.Resources(cpu="1", memory="1Gi"),
requires_auth=False,
)
if __name__ == "__main__":
flyte.init_from_config(root_dir=pathlib.Path(__file__).parent)
app = flyte.deploy(app_env)
print(f"App URL: {app[0].url}")
In this example:
main.pyis your main Streamlit app fileutils.pycontains helper functions used bymain.py- Both files are included in the app bundle
Multi-file FastAPI app
"""Multi-file FastAPI app example."""
from fastapi import FastAPI
from module import function # Import from another file
import pathlib
import flyte
from flyte.app.extras import FastAPIAppEnvironment
app = FastAPI(title="Multi-file FastAPI Demo")
app_env = FastAPIAppEnvironment(
name="fastapi-multi-file",
app=app,
image=flyte.Image.from_debian_base(python_version=(3, 12)).with_pip_packages(
"fastapi",
"uvicorn",
),
resources=flyte.Resources(cpu=1, memory="512Mi"),
requires_auth=False,
# FastAPIAppEnvironment automatically includes necessary files
# But you can also specify explicitly:
# include=["app.py", "module.py"],
)
@app.get("/")
async def root():
return function() # Uses function from module.py
if __name__ == "__main__":
flyte.init_from_config(root_dir=pathlib.Path(__file__).parent)
app_deployment = flyte.deploy(app_env)
print(f"Deployed: {app_deployment[0].url}")
App with configuration files
include=["app.py", "config.yaml", "templates/"]File discovery
When using specialized app environments like FastAPIAppEnvironment, Flyte uses code introspection to automatically discover and include the necessary files. This means you often don’t need to manually specify include.
However, if you have files that aren’t automatically detected (like configuration files, data files, or templates), you should explicitly list them in include.
Path resolution
Files in include are resolved relative to the directory containing your app definition file. For example:
project/
├── apps/
│ ├── app.py # Your app definition
│ ├── utils.py # Included file
│ └── config.yaml # Included fileIn app.py:
include=["utils.py", "config.yaml"] # Relative to apps/ directoryBest practices
- Only include what you need: Don’t include unnecessary files as it increases bundle size
- Use relative paths: Always use paths relative to your app definition file
- Include directories: You can include entire directories, but be mindful of size
- Test locally: Verify your includes work by testing locally before deploying
- Check automatic discovery: Specialized app environments may already include files automatically
Limitations
- Large files or directories can slow down deployment
- Binary files are supported but consider using data storage (S3, etc.) for very large files
- The bundle size is limited by your Flyte cluster configuration