fal.api package

Submodules

fal.api.api module

class fal.api.api.BaseServable

Bases: object

collect_routes()
Return type:

dict[RouteSignature, Callable[..., Any]]

lifespan(app)
openapi()

Build the OpenAPI specification for the served function. Attach needed metadata for a better integration to fal.

Return type:

dict[str, Any]

serve()
Return type:

None

version: ClassVar[str] = 'unknown'
class fal.api.api.FalFastAPI(*, debug=False, routes=None, title='FastAPI', summary=None, description='', version='0.1.0', openapi_url='/openapi.json', openapi_tags=None, servers=None, dependencies=None, default_response_class=<fastapi.datastructures.DefaultPlaceholder object>, redirect_slashes=True, docs_url='/docs', redoc_url='/redoc', swagger_ui_oauth2_redirect_url='/docs/oauth2-redirect', swagger_ui_init_oauth=None, middleware=None, exception_handlers=None, on_startup=None, on_shutdown=None, lifespan=None, terms_of_service=None, contact=None, license_info=None, openapi_prefix='', root_path='', root_path_in_servers=True, responses=None, callbacks=None, webhooks=None, deprecated=None, include_in_schema=True, swagger_ui_parameters=None, generate_unique_id_function=<fastapi.datastructures.DefaultPlaceholder object>, separate_input_output_schemas=True, openapi_external_docs=None, **extra)

Bases: FastAPI

A subclass of FastAPI that adds some fal-specific functionality.

openapi()

Build the OpenAPI specification for the served function. Attach needed metadata for a better integration to fal.

Return type:

dict[str, Any]

exception fal.api.api.FalMissingDependencyError(message)

Bases: FalSerializationError

exception fal.api.api.FalSerializationError(message)

Bases: FalServerlessException

message: str
exception fal.api.api.FalServerlessError(message)

Bases: FalServerlessException

message: str
class fal.api.api.FalServerlessHost(url='api.alpha.fal.ai', local_file_path='', credentials=<factory>)

Bases: Host

credentials: Credentials
local_file_path: str = ''
register(func, options, *, application_name=None, application_auth_mode=None, metadata=None, deployment_strategy, scale=True)
Return type:

Optional[str]

run(func, options, args, kwargs)

Run the given function in the isolated environment.

Return type:

TypeVar(ReturnT, covariant=True)

spawn(func, options, args, kwargs)
Return type:

SpawnInfo

url: str = 'api.alpha.fal.ai'
class fal.api.api.Host

Bases: Generic[ArgsT, ReturnT]

The physical environment where the isolated code is executed.

classmethod parse_key(key, value)
Return type:

tuple[Any, Any]

classmethod parse_options(**config)

Split the given set of options into host and environment options.

Return type:

Options

run(func, options, args, kwargs)

Run the given function in the isolated environment.

Return type:

TypeVar(ReturnT, covariant=True)

spawn(func, options, args, kwargs)
Return type:

SpawnInfo

exception fal.api.api.InternalFalServerlessError(message)

Bases: FalServerlessException

message: str
class fal.api.api.IsolatedFunction(host, raw_func, options, executor=<factory>, reraise=True)

Bases: Generic[ArgsT, ReturnT]

executor: ThreadPoolExecutor
property func: Callable[[ArgsT], ReturnT]
host: Host[ParamSpec(ArgsT), TypeVar(ReturnT, covariant=True)]
on(host=None, **config)
options: Options
raw_func: Callable[[ParamSpec(ArgsT)], TypeVar(ReturnT, covariant=True)]
reraise: bool = True
spawn(*args, **kwargs)
submit(*args, **kwargs)
class fal.api.api.LocalHost(_AGENT_ENVIRONMENT=<factory>)

Bases: Host

run(func, options, args, kwargs)

Run the given function in the isolated environment.

Return type:

TypeVar(ReturnT, covariant=True)

class fal.api.api.Options(host=<factory>, environment=<factory>, gateway=<factory>)

Bases: object

add_requirements(requirements)
environment: Dict[str, Any]
gateway: Dict[str, Any]
get_exposed_port()
Return type:

int | None

host: Dict[str, Any]
class fal.api.api.RouteSignature(path, is_websocket, input_modal, buffering, session_timeout, max_batch_size, emit_timings)

Bases: NamedTuple

buffering: int | None

Alias for field number 3

emit_timings: bool

Alias for field number 6

input_modal: type | None

Alias for field number 2

is_websocket: bool

Alias for field number 1

max_batch_size: int

Alias for field number 5

path: str

Alias for field number 0

session_timeout: float | None

Alias for field number 4

class fal.api.api.ServeWrapper(func)

Bases: BaseServable

collect_routes()
Return type:

dict[RouteSignature, Callable[..., Any]]

class fal.api.api.ServedIsolatedFunction(host, raw_func, options, executor=<factory>, reraise=True)

Bases: Generic[ArgsT, ReturnT], IsolatedFunction[(), None]

on(**kwds)

Helper for @overload to raise when called.

class fal.api.api.Server(config)

Bases: Server

Server is a uvicorn.Server that actually plays nicely with signals. By default, uvicorn’s Server class overwrites the signal handler for SIGINT, swallowing the signal and preventing other tasks from cancelling. This class allows the task to be gracefully cancelled using asyncio’s built-in task cancellation or with an event, like aiohttp.

install_signal_handlers()
Return type:

None

class fal.api.api.SpawnInfo(future=None, logs=<factory>, _url_ready=<factory>, _url=None, stream=None)

Bases: object

future: Future | None = None
logs: Queue
property return_value
stream: Any = None
property url
exception fal.api.api.UserFunctionException

Bases: FalServerlessException

fal.api.api.cached(func)

Cache the result of the given function in-memory.

Return type:

Callable[[ParamSpec(ArgsT)], TypeVar(ReturnT, covariant=True)]

fal.api.api.find_missing_dependencies(func, env)
Return type:

Iterator[tuple[str, list[str]]]

fal.api.api.function(kind='virtualenv', *, host=None, local_python_modules=None, **config)

fal.api.apps module

fal.api.apps.apps_runners(client, app_name, *, since=None, state=None)
Return type:

List[RunnerInfo]

fal.api.apps.list_apps(client, *, filter=None)
Return type:

List[AliasInfo]

fal.api.apps.scale_app(client, app_name, *, keep_alive=None, max_multiplexing=None, max_concurrency=None, min_concurrency=None, concurrency_buffer=None, concurrency_buffer_perc=None, request_timeout=None, startup_timeout=None, machine_types=None, regions=None)
Return type:

AliasInfo

fal.api.client module

fal.api.deploy module

class fal.api.deploy.DeploymentResult(revision, app_name, urls)

Bases: object

app_name: str
revision: str
urls: dict[str, dict[str, str]]
class fal.api.deploy.User(user_id, username)

Bases: tuple

user_id

Alias for field number 0

username

Alias for field number 1

fal.api.deploy.deploy(client, app_ref=None, *, app_name=None, auth=None, strategy='rolling', reset_scale=False)
Return type:

DeploymentResult

fal.api.runners module

fal.api.runners.list_runners(client, *, since=None)
Return type:

List[RunnerInfo]

Module contents