Skip to main content

prefect.server.api.server

Defines the Prefect REST API FastAPI app.

Functions

validation_exception_handler

Provide a detailed message for request validation errors.

integrity_exception_handler

Capture database integrity errors.

is_client_retryable_exception

replace_placeholder_string_in_files

Recursively loops through all files in the given directory and replaces a placeholder string.

copy_directory

custom_internal_exception_handler

Log a detailed exception for internal server errors before returning. Send 503 for errors clients can retry on.

prefect_object_not_found_exception_handler

Return 404 status code on object not found exceptions.

create_api_app

Create a FastAPI app that includes the Prefect REST API Args:
  • dependencies: a list of global dependencies to add to each Prefect REST API router
  • health_check_path: the health check route path
  • fast_api_app_kwargs: kwargs to pass to the FastAPI constructor
  • final: whether this will be the last instance of the Prefect server to be created in this process, so that additional optimizations may be applied
  • ignore_cache: if set, a new app will be created even if the settings and fast_api_app_kwargs match an existing app in the cache
Returns:
  • a FastAPI app that serves the Prefect REST API

create_ui_app

create_app

Create a FastAPI app that includes the Prefect REST API and UI Args:
  • settings: The settings to use to create the app. If not set, settings are pulled from the context.
  • ephemeral: If set, the application will be treated as ephemeral. The UI and services will be disabled.
  • webserver_only: If set, the webserver and UI will be available but all background services will be disabled.
  • final: whether this will be the last instance of the Prefect server to be created in this process, so that additional optimizations may be applied
  • ignore_cache: If set, a new application will be created even if the settings match. Otherwise, an application is returned from the cache.

Classes

RequestLimitMiddleware

A middleware that limits the number of concurrent requests handled by the API. This is a blunt tool for limiting SQLite concurrent writes which will cause failures at high volume. Ideally, we would only apply the limit to routes that perform writes.

SubprocessASGIServer

Methods:

address

api_url

find_available_port

is_port_available

start

Start the server in a separate process. Safe to call multiple times; only starts the server once. Args:
  • timeout: The maximum time to wait for the server to start

stop