fal: Serverless Python Framework

1.72.1 · active · verified Wed Apr 15

fal is an easy-to-use Serverless Python Framework that enables developers to build, test, and deploy serverless applications and machine learning models on GPU-accelerated infrastructure. It offers a Python SDK for defining applications and a CLI for deployment and management. The library is actively maintained, with frequent releases, and is currently at version 1.72.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining a simple 'Hello World' serverless application using `fal.App` and the `@fal.endpoint` decorator. It highlights the basic structure for a deployable application. Local testing and deployment are typically handled via the `fal` CLI after installing the `fal` package and authenticating.

import fal
import os

# Ensure FAL_KEY is set as an environment variable (e.g., export FAL_KEY="YOUR_API_KEY")
# or authenticate via 'fal auth login' CLI command.
fal_key = os.environ.get('FAL_KEY', '')
if not fal_key:
    print("Warning: FAL_KEY environment variable not set. Please authenticate via 'fal auth login' or set FAL_KEY.")

class HelloApp(fal.App):
    @fal.endpoint("/")
    def run(self) -> dict:
        print("Processing Hello World request...")
        return {"message": "Hello, World!"}

# To run locally for testing (requires fal CLI and authentication):
# fal run your_app_file.py::HelloApp

# To deploy to a persistent endpoint:
# fal deploy your_app_file.py::HelloApp

view raw JSON →