Creating an app
Every Modal project starts with anApp object:
Writing functions
Decorate any Python function with@app.function() to run it on Modal:
Running locally
To run a Modal app locally, use themodal run command:
Calling functions
There are several ways to invoke Modal functions:Remote execution
Call.remote() to execute the function in a Modal container:
Local execution
Call.local() to run the function locally:
Map over inputs
Process multiple inputs in parallel using.map():
Using custom images
Specify the container environment with theimage parameter:
Working with context
Modal provides utilities to check execution context:Accessing runtime information
Get information about the current function execution:Using secrets
Securely pass credentials to your functions:Mounting volumes
Persist data across function invocations:GPU functions
Request GPU resources for compute-intensive tasks:Retry policies
Configure automatic retries for transient failures:Timeouts
Set execution time limits:Local entrypoints
Define code that runs locally when the script is executed:Complete example
Here’s a complete example combining multiple concepts:Next steps
Async support
Learn how to use async/await patterns
Web endpoints
Create HTTP endpoints for your functions
Scheduled jobs
Run functions on schedules
CLI reference
Explore all CLI commands