docs/v3/api-ref/python/prefect-server-models-deployments.mdx
prefect.server.models.deploymentsFunctions for interacting with deployment ORM objects. Intended for internal use by the Prefect REST API.
create_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L110" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_deployment(db: PrefectDBInterface, session: AsyncSession, deployment: schemas.core.Deployment | schemas.actions.DeploymentCreate) -> Optional[orm_models.Deployment]
Upserts a deployment.
Args:
session: a database sessiondeployment: a deployment modelReturns:
update_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L276" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>update_deployment(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, deployment: schemas.actions.DeploymentUpdate) -> bool
Updates a deployment.
Args:
session: a database sessiondeployment_id: the ID of the deployment to modifydeployment: changes to a deployment modelReturns:
read_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L462" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>read_deployment(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID) -> Optional[orm_models.Deployment]
Reads a deployment by id.
Args:
session: A database sessiondeployment_id: a deployment idReturns:
read_deployment_by_name <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L479" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>read_deployment_by_name(db: PrefectDBInterface, session: AsyncSession, name: str, flow_name: str) -> Optional[orm_models.Deployment]
Reads a deployment by name.
Args:
session: A database sessionname: a deployment nameflow_name: the name of the flow the deployment belongs toReturns:
read_deployments <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L571" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>read_deployments(db: PrefectDBInterface, session: AsyncSession, offset: Optional[int] = None, limit: Optional[int] = None, flow_filter: Optional[schemas.filters.FlowFilter] = None, flow_run_filter: Optional[schemas.filters.FlowRunFilter] = None, task_run_filter: Optional[schemas.filters.TaskRunFilter] = None, deployment_filter: Optional[schemas.filters.DeploymentFilter] = None, work_pool_filter: Optional[schemas.filters.WorkPoolFilter] = None, work_queue_filter: Optional[schemas.filters.WorkQueueFilter] = None, sort: schemas.sorting.DeploymentSort = schemas.sorting.DeploymentSort.NAME_ASC) -> Sequence[orm_models.Deployment]
Read deployments.
Args:
session: A database sessionoffset: Query offsetlimit: Query limitflow_filter: only select deployments whose flows match these criteriaflow_run_filter: only select deployments whose flow runs match these criteriatask_run_filter: only select deployments whose task runs match these criteriadeployment_filter: only select deployment that match these filterswork_pool_filter: only select deployments whose work pools match these criteriawork_queue_filter: only select deployments whose work pool queues match these criteriasort: the sort criteria for selected deployments. Defaults to name ASC.Returns:
count_deployments <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L626" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>count_deployments(db: PrefectDBInterface, session: AsyncSession, flow_filter: Optional[schemas.filters.FlowFilter] = None, flow_run_filter: Optional[schemas.filters.FlowRunFilter] = None, task_run_filter: Optional[schemas.filters.TaskRunFilter] = None, deployment_filter: Optional[schemas.filters.DeploymentFilter] = None, work_pool_filter: Optional[schemas.filters.WorkPoolFilter] = None, work_queue_filter: Optional[schemas.filters.WorkQueueFilter] = None) -> int
Count deployments.
Args:
session: A database sessionflow_filter: only count deployments whose flows match these criteriaflow_run_filter: only count deployments whose flow runs match these criteriatask_run_filter: only count deployments whose task runs match these criteriadeployment_filter: only count deployment that match these filterswork_pool_filter: only count deployments that match these work pool filterswork_queue_filter: only count deployments that match these work pool queue filtersReturns:
delete_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L670" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>delete_deployment(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID) -> bool
Delete a deployment by id.
Args:
session: A database sessiondeployment_id: a deployment idReturns:
delete_deployments <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L727" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>delete_deployments(db: PrefectDBInterface, session: AsyncSession, deployment_ids: list[UUID]) -> list[UUID]
Delete multiple deployments by their IDs.
Args:
session: A database sessiondeployment_ids: a list of deployment ids to deleteReturns:
schedule_runs <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L795" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>schedule_runs(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, start_time: Optional[datetime.datetime] = None, end_time: Optional[datetime.datetime] = None, min_time: Optional[datetime.timedelta] = None, min_runs: Optional[int] = None, max_runs: Optional[int] = None, auto_scheduled: bool = True) -> Sequence[UUID]
Schedule flow runs for a deployment
Args:
session: a database sessiondeployment_id: the id of the deployment to schedulestart_time: the time from which to start scheduling runsend_time: runs will be scheduled until at most this timemin_time: runs will be scheduled until at least this far in the futuremin_runs: a minimum amount of runs to schedulemax_runs: a maximum amount of runs to scheduleThis function will generate the minimum number of runs that satisfy the min and max times, and the min and max counts. Specifically, the following order will be respected.
- Runs will be generated starting on or after the `start_time`
- No more than `max_runs` runs will be generated
- No runs will be generated after `end_time` is reached
- At least `min_runs` runs will be generated
- Runs will be generated until at least `start_time` + `min_time` is reached
Returns:
check_work_queues_for_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1052" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>check_work_queues_for_deployment(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID) -> Sequence[orm_models.WorkQueue]
Get work queues that can pick up the specified deployment.
Work queues will pick up a deployment when all of the following are met.
Notes on the query:
A.contains(B) should be interpreted as "True if A
contains B".Returns:
create_deployment_schedules <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1112" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>create_deployment_schedules(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, schedules: list[schemas.actions.DeploymentScheduleCreate]) -> list[schemas.core.DeploymentSchedule]
Creates a deployment's schedules.
Args:
session: A database sessiondeployment_id: a deployment idschedules: a list of deployment schedule create actionsread_deployment_schedules <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1147" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>read_deployment_schedules(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, deployment_schedule_filter: Optional[schemas.filters.DeploymentScheduleFilter] = None) -> list[schemas.core.DeploymentSchedule]
Reads a deployment's schedules.
Args:
session: A database sessiondeployment_id: a deployment idReturns:
update_deployment_schedule <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1184" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>update_deployment_schedule(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, schedule: schemas.actions.DeploymentScheduleUpdate, deployment_schedule_id: UUID | None = None, deployment_schedule_slug: str | None = None) -> bool
Updates a deployment's schedules.
Args:
session: A database sessiondeployment_schedule_id: a deployment schedule idschedule: a deployment schedule update actiondelete_schedules_for_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1233" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>delete_schedules_for_deployment(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID) -> bool
Deletes a deployment schedule.
Args:
session: A database sessiondeployment_id: a deployment iddelete_deployment_schedule <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1258" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>delete_deployment_schedule(db: PrefectDBInterface, session: AsyncSession, deployment_id: UUID, deployment_schedule_id: UUID) -> bool
Deletes a deployment schedule.
Args:
session: A database sessiondeployment_schedule_id: a deployment schedule idmark_deployments_ready <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1284" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>mark_deployments_ready() -> None
mark_deployments_not_ready <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1345" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>mark_deployments_not_ready(db: PrefectDBInterface, deployment_ids: Optional[Iterable[UUID]] = None, work_queue_ids: Optional[Iterable[UUID]] = None) -> None
with_system_labels_for_deployment <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1402" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>with_system_labels_for_deployment(session: AsyncSession, deployment: schemas.core.Deployment) -> schemas.core.KeyValueLabels
Augment user supplied labels with system default labels for a deployment.
with_system_labels_for_deployment_flow_run <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1423" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>with_system_labels_for_deployment_flow_run(session: AsyncSession, deployment: orm_models.Deployment, user_supplied_labels: Optional[schemas.core.KeyValueLabels] = None) -> schemas.core.KeyValueLabels
Generate system labels for a flow run created from a deployment.
Args:
session: Database sessiondeployment: The deployment the flow run is created fromuser_supplied_labels: Optional user-supplied labels to includeReturns:
emit_deployment_created_event <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1470" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>emit_deployment_created_event(session: AsyncSession, deployment: orm_models.Deployment) -> None
Emit an event when a deployment is created.
emit_deployment_updated_event <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1485" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>emit_deployment_updated_event(session: AsyncSession, deployment: orm_models.Deployment, changed_fields: dict[str, dict[str, Any]]) -> None
Emit an event when a deployment is updated.
emit_deployment_deleted_event <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/models/deployments.py#L1504" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>emit_deployment_deleted_event(session: AsyncSession, deployment: orm_models.Deployment) -> None
Emit an event when a deployment is deleted.