__init__
prefect.client.orchestration
Functions
get_client
Retrieve a HTTP client for communicating with the Prefect REST API.
The client must be context managed; for example:
To return a synchronous client, pass sync_client=True:
Classes
PrefectClient
An asynchronous client for interacting with the Prefect REST API.
Args:
api
: the REST API URL or FastAPI application to connect toapi_key
: An optional API key for authentication.api_version
: The API version this client is compatible with.httpx_settings
: An optional dictionary of settings to pass to the underlyinghttpx.AsyncClient
Examples:
Say hello to a Prefect REST API
<div class=“terminal”>
</div>
Methods:
api_url
Get the base URL for the API.
client_version
loop
SyncPrefectClient
A synchronous client for interacting with the Prefect REST API.
Args:
api
: the REST API URL or FastAPI application to connect toapi_key
: An optional API key for authentication.api_version
: The API version this client is compatible with.httpx_settings
: An optional dictionary of settings to pass to the underlyinghttpx.Client
Examples:
Say hello to a Prefect REST API
<div class=“terminal”>
</div>
Methods:
api_url
Get the base URL for the API.
api_healthcheck
Attempts to connect to the API and returns the encountered exception if not successful.
If successful, returns None
.
hello
Send a GET request to /hello for testing purposes.
api_version
client_version
raise_for_api_version_mismatch
set_task_run_name
create_task_run
Create a task run
Args:
task
: The Task to runflow_run_id
: The flow run id with which to associate the task rundynamic_key
: A key unique to this particular run of a Task within the flowid
: An optional ID for the task run. If not provided, one will be generated server-side.name
: An optional name for the task runextra_tags
: an optional list of extra tags to apply to the task run in addition totask.tags
state
: The initial state for the run. If not provided, defaults toPending
for now. Should always be aScheduled
type.task_inputs
: the set of inputs passed to the task
Returns:
- The created task run.
read_task_run
Query the Prefect API for a task run by id.
Args:
task_run_id
: the task run ID of interest
Returns:
- a Task Run model representation of the task run
read_task_runs
Query the Prefect API for task runs. Only task runs matching all criteria will be returned.
Args:
flow_filter
: filter criteria for flowsflow_run_filter
: filter criteria for flow runstask_run_filter
: filter criteria for task runsdeployment_filter
: filter criteria for deploymentssort
: sort criteria for the task runslimit
: a limit for the task run queryoffset
: an offset for the task run query
Returns:
- a list of Task Run model representations of the task runs
set_task_run_state
Set the state of a task run.
Args:
task_run_id
: the id of the task runstate
: the state to setforce
: if True, disregard orchestration logic when setting the state, forcing the Prefect API to accept the state
Returns:
- an OrchestrationResult model representation of state orchestration output
read_task_run_states
Query for the states of a task run
Args:
task_run_id
: the id of the task run
Returns:
- a list of State model representations of the task run states