Python SDK Reference
This is the API reference for the modal
Python SDK, which allows you to programmatically interact with Modal.
Application construction
|
|
App |
The main unit of deployment for code on Modal |
App.function |
Decorator for registering a function with an App |
App.cls |
Decorator for registering a class with an App |
App.server |
Decorator for registering a server with an App |
Serverless execution
|
|
Function |
A serverless function backed by an autoscaling container pool |
Cls |
A serverless class supporting parametrization and lifecycle hooks |
Server |
A serverless HTTP application with low-latency request routing |
Extended Function configuration
Class parametrization
|
|
parameter |
Used to define class parameters, akin to a Dataclass field |
Lifecycle hooks
|
|
enter |
Decorator for a method that will be executed during container startup |
exit |
Decorator for a method that will be executed during container shutdown |
method |
Decorator for exposing a method as an invokable function |
Web integrations
|
|
fastapi_endpoint |
Decorator for exposing a simple FastAPI-based endpoint |
asgi_app |
Decorator for functions that construct an ASGI web application |
wsgi_app |
Decorator for functions that construct a WSGI web application |
web_server |
Decorator for functions that construct an HTTP web server |
Function semantics
Scheduling
|
|
Cron |
A schedule that runs based on cron syntax |
Period |
A schedule that runs at a fixed interval |
Exception handling
|
|
Retries |
Function retry policy for input failures |
Sandboxed execution
|
|
Sandbox |
An interface for restricted code execution |
ContainerProcess |
An object representing a sandboxed process |
FileIO |
A handle for a file in the Sandbox filesystem |
Container configuration
|
|
Image |
An API for specifying container images |
Secret |
A pointer to secrets that will be exposed as environment variables |
Data primitives
Persistent storage
|
|
Volume |
Distributed storage supporting highly performant parallel reads |
CloudBucketMount |
Storage backed by a third-party cloud bucket (S3, etc.) |
In-memory storage
|
|
Dict |
A distributed key-value store |
Queue |
A distributed FIFO queue |
Account configuration
Networking
|
|
Proxy |
An object that provides a static outbound IP address for containers |
forward |
A context manager for publicly exposing a port from a container |