docs/v3/api-ref/python/prefect-client-base.mdx
prefect.client.baseapp_lifespan_context <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L64" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>app_lifespan_context(app: ASGIApp) -> AsyncGenerator[None, None]
A context manager that calls startup/shutdown hooks for the given application.
Lifespan contexts are cached per application to avoid calling the lifespan hooks more than once if the context is entered in nested code. A no-op context will be returned if the context for the given application is already being managed.
This manager is robust to concurrent access within the event loop. For example, if you have concurrent contexts for the same application, it is guaranteed that startup hooks will be called before their context starts and shutdown hooks will only be called after their context exits.
A reference count is used to support nested use of clients without running lifespan hooks excessively. The first client context entered will create and enter a lifespan context. Each subsequent client will increment a reference count but will not create a new lifespan context. When each client context exits, the reference count is decremented. When the last client context exits, the lifespan will be closed.
In simple nested cases, the first client context will be the one to exit the lifespan. However, if client contexts are entered concurrently they may not exit in a consistent order. If the first client context was responsible for closing the lifespan, it would have to wait until all other client contexts to exit to avoid firing shutdown hooks while the application is in use. Waiting for the other clients to exit can introduce deadlocks, so, instead, the first client will exit without closing the lifespan context and reference counts will be used to ensure the lifespan is closed once all of the clients are done.
determine_server_type <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L727" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>determine_server_type() -> ServerType
Determine the server type based on the current settings.
Returns:
ServerType.EPHEMERAL if the ephemeral server is enabledServerType.SERVER if a API URL is configured and it is not a cloud URLServerType.CLOUD if an API URL is configured and it is a cloud URLServerType.UNCONFIGURED if no API URL is configured and ephemeral mode is
not enabledASGIApp <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L59" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>PrefectResponse <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>A Prefect wrapper for the httpx.Response class.
Provides more informative error messages.
Methods:
from_httpx_response <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L167" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>from_httpx_response(cls: type[Self], response: httpx.Response) -> Response
Create a PrefectResponse from an httpx.Response.
By changing the __class__ attribute of the Response, we change the method
resolution order to look for methods defined in PrefectResponse, while leaving
everything else about the original Response instance intact.
raise_for_status <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L154" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>raise_for_status(self) -> Response
Raise an exception if the response contains an HTTPStatusError.
The PrefectHTTPStatusError contains useful additional information that
is not contained in the HTTPStatusError.
PrefectHttpxAsyncClient <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L180" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>A Prefect wrapper for the async httpx client with support for retry-after headers for the provided status codes (typically 429, 502 and 503).
Additionally, this client will always call raise_for_status on responses.
For more details on rate limit headers, see: Configuring Cloudflare Rate Limiting
Methods:
send <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L349" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>send(self, request: Request, *args: Any, **kwargs: Any) -> Response
Send a request with automatic retry behavior for the following status codes:
PREFECT_CLIENT_RETRY_EXTRA_CODESPrefectHttpxSyncClient <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L450" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>A Prefect wrapper for the async httpx client with support for retry-after headers for the provided status codes (typically 429, 502 and 503).
Additionally, this client will always call raise_for_status on responses.
For more details on rate limit headers, see: Configuring Cloudflare Rate Limiting
Methods:
send <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L619" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>send(self, request: Request, *args: Any, **kwargs: Any) -> Response
Send a request with automatic retry behavior for the following status codes:
PREFECT_CLIENT_RETRY_EXTRA_CODESServerType <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/client/base.py#L720" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Methods:
auto <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/utilities/collections.py#L70" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>auto() -> str
Exposes enum.auto() to avoid requiring a second import to use AutoEnum