Server-less Python Web Services for AWS Lambda and API Gateway
npx @tessl/cli install tessl/pypi-zappa@0.60.0Zappa is a comprehensive serverless deployment tool that enables developers to build and deploy event-driven Python applications (including WSGI web apps like Django and Flask) on AWS Lambda + API Gateway without any permanent infrastructure. It provides infinite scaling, zero downtime, and zero maintenance at a fraction of traditional hosting costs by leveraging AWS's serverless architecture where each request gets its own virtual HTTP server with a 40-millisecond lifecycle.
pip install zappa# Core deployment management
from zappa.core import Zappa
# Command line interface
from zappa.cli import ZappaCLI
# Lambda handler entry point
from zappa.handler import lambda_handler, LambdaHandler
# Async task decorators and execution
from zappa.asynchronous import task, task_sns, run, get_async_response
# WSGI utilities
from zappa.wsgi import create_wsgi_request, ZappaWSGIMiddleware
# SSL certificate management
from zappa.letsencrypt import get_cert_and_update_domain
# Utility functions
from zappa.utilities import (
detect_django_settings,
detect_flask_apps,
parse_s3_url,
human_size
)
# Package-level utilities
from zappa import running_in_docker, __version__# Initialize a new Zappa project
from zappa.cli import ZappaCLI
cli = ZappaCLI()
cli.init()
# Deploy to AWS
cli.deploy()
# Update existing deployment
cli.update()
# Check deployment status
cli.status()
# Remove deployment
cli.undeploy()from zappa.core import Zappa
# Create Zappa instance
z = Zappa(
boto_session=None,
profile_name='default',
aws_region='us-east-1',
load_credentials=True
)
# Create Lambda function
z.create_lambda_function(
bucket='my-deployment-bucket',
s3_key='my-app.zip',
function_name='my-app',
handler='app.lambda_handler'
)
# Deploy API Gateway
z.deploy_api_gateway(
api_id='abc123',
stage_name='prod'
)Zappa's architecture consists of several key components:
Zappa class provides deployment and AWS resource managementZappaCLI class handles command-line operations and user interactionThis design enables seamless deployment of existing Python web applications to serverless infrastructure with minimal code changes.
Primary AWS resource management including Lambda function creation, updates, configuration changes, API Gateway deployment, and rollback operations. These functions form the foundation of Zappa's serverless deployment capabilities.
class Zappa:
def create_lambda_function(self, **kwargs): ...
def update_lambda_function(self, **kwargs): ...
def update_lambda_configuration(self, **kwargs): ...
def delete_lambda_function(self, function_name): ...
def deploy_api_gateway(self, **kwargs): ...
def undeploy_api_gateway(self, **kwargs): ...Complete CLI operations for deployment lifecycle management including project initialization, deployment, updates, status monitoring, log streaming, and cleanup operations.
class ZappaCLI:
def deploy(self): ...
def update(self): ...
def undeploy(self): ...
def status(self): ...
def tail(self): ...
def rollback(self): ...
def init(self): ...
def shell(self): ...Lambda function handler and WSGI request processing for converting AWS Lambda events into standard HTTP requests that can be processed by web applications like Django and Flask.
def lambda_handler(event, context): ...
class LambdaHandler:
@classmethod
def lambda_handler(cls, event, context): ...
def handler(self, event, context): ...
def run_function(self, event, context): ...Background task processing using AWS Lambda and SNS for executing long-running operations asynchronously outside of HTTP request/response cycle.
def task(func): ...
def task_sns(func): ...
def run(func, *args, **kwargs): ...
def get_async_response(response_id): ...
class LambdaAsyncResponse: ...
class SnsAsyncResponse: ...AWS integration helpers, framework detection, file operations, and various utility functions for S3 operations, environment management, and deployment assistance.
def detect_django_settings(): ...
def detect_flask_apps(): ...
def parse_s3_url(url): ...
def is_valid_bucket_name(bucket): ...
def get_runtime_from_python_version(version): ...
def human_size(bytes): ...Automated SSL certificate provisioning using Let's Encrypt ACME protocol for securing deployed applications with HTTPS.
def get_cert_and_update_domain(**kwargs): ...
def get_cert(**kwargs): ...
def create_domain_key(): ...
def create_domain_csr(**kwargs): ...
def verify_challenge(**kwargs): ...WSGI utilities for converting Lambda events to standard HTTP requests and middleware for AWS-specific processing requirements.
def create_wsgi_request(event, script_name=None, base_path=None, trailing_slash=True): ...
def process_lambda_payload_v1(event): ...
def process_lambda_payload_v2(event): ...
class ZappaWSGIMiddleware:
def __init__(self, application): ...
def __call__(self, environ, start_response): ...Core package functions and constants available at the top level for environment detection and version management.
def running_in_docker() -> bool: ...
__version__: str
SUPPORTED_VERSIONS: list
MINIMUM_SUPPORTED_MINOR_VERSION: int# Core configuration types
class Zappa:
def __init__(
self,
boto_session=None,
profile_name=None,
aws_region=None,
load_credentials=True,
desired_role_name=None,
desired_role_arn=None,
runtime="python3.13",
tags=(),
endpoint_urls={},
xray_tracing=False,
architecture=None
): ...
class ZappaCLI:
def __init__(self): ...
# Handler types
class LambdaHandler:
def __init__(self): ...
# Async response types
class LambdaAsyncResponse:
def __init__(self, **kwargs): ...
class SnsAsyncResponse(LambdaAsyncResponse):
def __init__(self, **kwargs): ...
# Exception types
class AsyncException(Exception): ...