API Reference

This is the API reference for the modal Python package, which allows you to run distributed applications on Modal.

The reference is intended to be limited to low-level descriptions of various programmatic functionality. If you’re just getting started with Modal, we would instead recommend looking at the guide first or to get started quickly with an example.

Application construction

AppThe main unit of deployment for code on Modal
App.functionDecorator for registering a function with an App
App.clsDecorator for registering a class with an App

Serverless execution

FunctionA serverless function backed by an autoscaling container pool
ClsA serverless class supporting parametrization and lifecycle hooks

Extended Function configuration

Class parametrization

parameterUsed to define class parameters, akin to a Dataclass field

Lifecycle hooks

enterDecorator for a method that will be executed during container startup
exitDecorator for a method that will be executed during container shutdown
methodDecorator for exposing a method as an invokable function

Web integrations

fastapi_endpointDecorator for exposing a simple FastAPI-based endpoint
asgi_appDecorator for functions that construct an ASGI web application
wsgi_appDecorator for functions that construct a WSGI web application
web_serverDecorator for functions that construct an HTTP web server

Function semantics

batchedDecorator that enables dynamic input batching
concurrentDecorator that enables input concurrency

Scheduling

CronA schedule that runs based on cron syntax
PeriodA schedule that runs at a fixed interval

Exception handling

RetriesFunction retry policy for input failures

Sandboxed execution

SandboxAn interface for restricted code execution
ContainerProcessAn object representing a sandboxed process
FileIOA handle for a file in the Sandbox filesystem

Container configuration

ImageAn API for specifying container images
SecretA pointer to secrets that will be exposed as environment variables

Data primitives

Persistent storage

VolumeDistributed storage supporting highly performant parallel reads
CloudBucketMountStorage backed by a third-party cloud bucket (S3, etc.)
NetworkFileSystemShared, writeable cloud storage (superseded by modal.Volume)

In-memory storage

DictA distributed key-value store
QueueA distributed FIFO queue

Networking

ProxyAn object that provides a static outbound IP address for containers
forwardA context manager for publicly exposing a port from a container