Skip to content

prefect.server.schemas.filters

Schemas that define Prefect REST API filtering operations.

Each filter schema includes logic for transforming itself into a SQL where clause.

ArtifactCollectionFilter

Bases: PrefectOperatorFilterBaseModel

Filter artifact collections. Only artifact collections matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
class ArtifactCollectionFilter(PrefectOperatorFilterBaseModel):
    """Filter artifact collections. Only artifact collections matching all criteria will be returned"""

    latest_id: Optional[ArtifactCollectionFilterLatestId] = Field(
        default=None, description="Filter criteria for `Artifact.id`"
    )
    key: Optional[ArtifactCollectionFilterKey] = Field(
        default=None, description="Filter criteria for `Artifact.key`"
    )
    flow_run_id: Optional[ArtifactCollectionFilterFlowRunId] = Field(
        default=None, description="Filter criteria for `Artifact.flow_run_id`"
    )
    task_run_id: Optional[ArtifactCollectionFilterTaskRunId] = Field(
        default=None, description="Filter criteria for `Artifact.task_run_id`"
    )
    type: Optional[ArtifactCollectionFilterType] = Field(
        default=None, description="Filter criteria for `Artifact.type`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.latest_id is not None:
            filters.append(self.latest_id.as_sql_filter())
        if self.key is not None:
            filters.append(self.key.as_sql_filter())
        if self.flow_run_id is not None:
            filters.append(self.flow_run_id.as_sql_filter())
        if self.task_run_id is not None:
            filters.append(self.task_run_id.as_sql_filter())
        if self.type is not None:
            filters.append(self.type.as_sql_filter())

        return filters

ArtifactCollectionFilterFlowRunId

Bases: PrefectFilterBaseModel

Filter by ArtifactCollection.flow_run_id.

Source code in src/prefect/server/schemas/filters.py
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
class ArtifactCollectionFilterFlowRunId(PrefectFilterBaseModel):
    """Filter by `ArtifactCollection.flow_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.ArtifactCollection.flow_run_id.in_(self.any_))
        return filters

ArtifactCollectionFilterKey

Bases: PrefectFilterBaseModel

Filter by ArtifactCollection.key.

Source code in src/prefect/server/schemas/filters.py
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
class ArtifactCollectionFilterKey(PrefectFilterBaseModel):
    """Filter by `ArtifactCollection.key`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact keys to include"
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A string to match artifact keys against. This can include "
            "SQL wildcard characters like `%` and `_`."
        ),
        examples=["my-artifact-%"],
    )

    exists_: Optional[bool] = Field(
        default=None,
        description=(
            "If `true`, only include artifacts with a non-null key. If `false`, "
            "only include artifacts with a null key. Should return all rows in "
            "the ArtifactCollection table if specified."
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.ArtifactCollection.key.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.ArtifactCollection.key.ilike(f"%{self.like_}%"))
        if self.exists_ is not None:
            filters.append(
                orm_models.ArtifactCollection.key.isnot(None)
                if self.exists_
                else orm_models.ArtifactCollection.key.is_(None)
            )
        return filters

ArtifactCollectionFilterLatestId

Bases: PrefectFilterBaseModel

Filter by ArtifactCollection.latest_id.

Source code in src/prefect/server/schemas/filters.py
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
class ArtifactCollectionFilterLatestId(PrefectFilterBaseModel):
    """Filter by `ArtifactCollection.latest_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of artifact ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.ArtifactCollection.latest_id.in_(self.any_))
        return filters

ArtifactCollectionFilterTaskRunId

Bases: PrefectFilterBaseModel

Filter by ArtifactCollection.task_run_id.

Source code in src/prefect/server/schemas/filters.py
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
class ArtifactCollectionFilterTaskRunId(PrefectFilterBaseModel):
    """Filter by `ArtifactCollection.task_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of task run IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.ArtifactCollection.task_run_id.in_(self.any_))
        return filters

ArtifactCollectionFilterType

Bases: PrefectFilterBaseModel

Filter by ArtifactCollection.type.

Source code in src/prefect/server/schemas/filters.py
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
class ArtifactCollectionFilterType(PrefectFilterBaseModel):
    """Filter by `ArtifactCollection.type`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact types to include"
    )
    not_any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact types to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.ArtifactCollection.type.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.ArtifactCollection.type.notin_(self.not_any_))
        return filters

ArtifactFilter

Bases: PrefectOperatorFilterBaseModel

Filter artifacts. Only artifacts matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
class ArtifactFilter(PrefectOperatorFilterBaseModel):
    """Filter artifacts. Only artifacts matching all criteria will be returned"""

    id: Optional[ArtifactFilterId] = Field(
        default=None, description="Filter criteria for `Artifact.id`"
    )
    key: Optional[ArtifactFilterKey] = Field(
        default=None, description="Filter criteria for `Artifact.key`"
    )
    flow_run_id: Optional[ArtifactFilterFlowRunId] = Field(
        default=None, description="Filter criteria for `Artifact.flow_run_id`"
    )
    task_run_id: Optional[ArtifactFilterTaskRunId] = Field(
        default=None, description="Filter criteria for `Artifact.task_run_id`"
    )
    type: Optional[ArtifactFilterType] = Field(
        default=None, description="Filter criteria for `Artifact.type`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.key is not None:
            filters.append(self.key.as_sql_filter())
        if self.flow_run_id is not None:
            filters.append(self.flow_run_id.as_sql_filter())
        if self.task_run_id is not None:
            filters.append(self.task_run_id.as_sql_filter())
        if self.type is not None:
            filters.append(self.type.as_sql_filter())

        return filters

ArtifactFilterFlowRunId

Bases: PrefectFilterBaseModel

Filter by Artifact.flow_run_id.

Source code in src/prefect/server/schemas/filters.py
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
class ArtifactFilterFlowRunId(PrefectFilterBaseModel):
    """Filter by `Artifact.flow_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Artifact.flow_run_id.in_(self.any_))
        return filters

ArtifactFilterId

Bases: PrefectFilterBaseModel

Filter by Artifact.id.

Source code in src/prefect/server/schemas/filters.py
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
class ArtifactFilterId(PrefectFilterBaseModel):
    """Filter by `Artifact.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of artifact ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Artifact.id.in_(self.any_))
        return filters

ArtifactFilterKey

Bases: PrefectFilterBaseModel

Filter by Artifact.key.

Source code in src/prefect/server/schemas/filters.py
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
class ArtifactFilterKey(PrefectFilterBaseModel):
    """Filter by `Artifact.key`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact keys to include"
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A string to match artifact keys against. This can include "
            "SQL wildcard characters like `%` and `_`."
        ),
        examples=["my-artifact-%"],
    )

    exists_: Optional[bool] = Field(
        default=None,
        description=(
            "If `true`, only include artifacts with a non-null key. If `false`, "
            "only include artifacts with a null key."
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Artifact.key.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.Artifact.key.ilike(f"%{self.like_}%"))
        if self.exists_ is not None:
            filters.append(
                orm_models.Artifact.key.isnot(None)
                if self.exists_
                else orm_models.Artifact.key.is_(None)
            )
        return filters

ArtifactFilterTaskRunId

Bases: PrefectFilterBaseModel

Filter by Artifact.task_run_id.

Source code in src/prefect/server/schemas/filters.py
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
class ArtifactFilterTaskRunId(PrefectFilterBaseModel):
    """Filter by `Artifact.task_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of task run IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Artifact.task_run_id.in_(self.any_))
        return filters

ArtifactFilterType

Bases: PrefectFilterBaseModel

Filter by Artifact.type.

Source code in src/prefect/server/schemas/filters.py
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
class ArtifactFilterType(PrefectFilterBaseModel):
    """Filter by `Artifact.type`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact types to include"
    )
    not_any_: Optional[List[str]] = Field(
        default=None, description="A list of artifact types to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Artifact.type.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.Artifact.type.notin_(self.not_any_))
        return filters

BlockDocumentFilter

Bases: PrefectOperatorFilterBaseModel

Filter BlockDocuments. Only BlockDocuments matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
class BlockDocumentFilter(PrefectOperatorFilterBaseModel):
    """Filter BlockDocuments. Only BlockDocuments matching all criteria will be returned"""

    id: Optional[BlockDocumentFilterId] = Field(
        default=None, description="Filter criteria for `BlockDocument.id`"
    )
    is_anonymous: Optional[BlockDocumentFilterIsAnonymous] = Field(
        # default is to exclude anonymous blocks
        BlockDocumentFilterIsAnonymous(eq_=False),
        description=(
            "Filter criteria for `BlockDocument.is_anonymous`. "
            "Defaults to excluding anonymous blocks."
        ),
    )
    block_type_id: Optional[BlockDocumentFilterBlockTypeId] = Field(
        default=None, description="Filter criteria for `BlockDocument.block_type_id`"
    )
    name: Optional[BlockDocumentFilterName] = Field(
        default=None, description="Filter criteria for `BlockDocument.name`"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.is_anonymous is not None:
            filters.append(self.is_anonymous.as_sql_filter())
        if self.block_type_id is not None:
            filters.append(self.block_type_id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        return filters

BlockDocumentFilterBlockTypeId

Bases: PrefectFilterBaseModel

Filter by BlockDocument.block_type_id.

Source code in src/prefect/server/schemas/filters.py
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
class BlockDocumentFilterBlockTypeId(PrefectFilterBaseModel):
    """Filter by `BlockDocument.block_type_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of block type ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockDocument.block_type_id.in_(self.any_))
        return filters

BlockDocumentFilterId

Bases: PrefectFilterBaseModel

Filter by BlockDocument.id.

Source code in src/prefect/server/schemas/filters.py
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
class BlockDocumentFilterId(PrefectFilterBaseModel):
    """Filter by `BlockDocument.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of block ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockDocument.id.in_(self.any_))
        return filters

BlockDocumentFilterIsAnonymous

Bases: PrefectFilterBaseModel

Filter by BlockDocument.is_anonymous.

Source code in src/prefect/server/schemas/filters.py
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
class BlockDocumentFilterIsAnonymous(PrefectFilterBaseModel):
    """Filter by `BlockDocument.is_anonymous`."""

    eq_: Optional[bool] = Field(
        default=None,
        description=(
            "Filter block documents for only those that are or are not anonymous."
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.eq_ is not None:
            filters.append(orm_models.BlockDocument.is_anonymous.is_(self.eq_))
        return filters

BlockDocumentFilterName

Bases: PrefectFilterBaseModel

Filter by BlockDocument.name.

Source code in src/prefect/server/schemas/filters.py
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
class BlockDocumentFilterName(PrefectFilterBaseModel):
    """Filter by `BlockDocument.name`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of block names to include"
    )
    like_: Optional[str] = Field(
        default=None,
        description=(
            "A string to match block names against. This can include "
            "SQL wildcard characters like `%` and `_`."
        ),
        examples=["my-block%"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockDocument.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.BlockDocument.name.ilike(f"%{self.like_}%"))
        return filters

BlockSchemaFilter

Bases: PrefectOperatorFilterBaseModel

Filter BlockSchemas

Source code in src/prefect/server/schemas/filters.py
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
class BlockSchemaFilter(PrefectOperatorFilterBaseModel):
    """Filter BlockSchemas"""

    block_type_id: Optional[BlockSchemaFilterBlockTypeId] = Field(
        default=None, description="Filter criteria for `BlockSchema.block_type_id`"
    )
    block_capabilities: Optional[BlockSchemaFilterCapabilities] = Field(
        default=None, description="Filter criteria for `BlockSchema.capabilities`"
    )
    id: Optional[BlockSchemaFilterId] = Field(
        default=None, description="Filter criteria for `BlockSchema.id`"
    )
    version: Optional[BlockSchemaFilterVersion] = Field(
        default=None, description="Filter criteria for `BlockSchema.version`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.block_type_id is not None:
            filters.append(self.block_type_id.as_sql_filter())
        if self.block_capabilities is not None:
            filters.append(self.block_capabilities.as_sql_filter())
        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.version is not None:
            filters.append(self.version.as_sql_filter())

        return filters

BlockSchemaFilterBlockTypeId

Bases: PrefectFilterBaseModel

Filter by BlockSchema.block_type_id.

Source code in src/prefect/server/schemas/filters.py
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
class BlockSchemaFilterBlockTypeId(PrefectFilterBaseModel):
    """Filter by `BlockSchema.block_type_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of block type ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockSchema.block_type_id.in_(self.any_))
        return filters

BlockSchemaFilterCapabilities

Bases: PrefectFilterBaseModel

Filter by BlockSchema.capabilities

Source code in src/prefect/server/schemas/filters.py
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
class BlockSchemaFilterCapabilities(PrefectFilterBaseModel):
    """Filter by `BlockSchema.capabilities`"""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["write-storage", "read-storage"]],
        description=(
            "A list of block capabilities. Block entities will be returned only if an"
            " associated block schema has a superset of the defined capabilities."
        ),
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(
                json_has_all_keys(orm_models.BlockSchema.capabilities, self.all_)
            )
        return filters

BlockSchemaFilterId

Bases: PrefectFilterBaseModel

Filter by BlockSchema.id

Source code in src/prefect/server/schemas/filters.py
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
class BlockSchemaFilterId(PrefectFilterBaseModel):
    """Filter by BlockSchema.id"""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockSchema.id.in_(self.any_))
        return filters

BlockSchemaFilterVersion

Bases: PrefectFilterBaseModel

Filter by BlockSchema.capabilities

Source code in src/prefect/server/schemas/filters.py
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
class BlockSchemaFilterVersion(PrefectFilterBaseModel):
    """Filter by `BlockSchema.capabilities`"""

    any_: Optional[List[str]] = Field(
        default=None,
        examples=[["2.0.0", "2.1.0"]],
        description="A list of block schema versions.",
    )

    def _get_filter_list(self) -> List:
        pass

        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockSchema.version.in_(self.any_))
        return filters

BlockTypeFilter

Bases: PrefectFilterBaseModel

Filter BlockTypes

Source code in src/prefect/server/schemas/filters.py
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
class BlockTypeFilter(PrefectFilterBaseModel):
    """Filter BlockTypes"""

    name: Optional[BlockTypeFilterName] = Field(
        default=None, description="Filter criteria for `BlockType.name`"
    )

    slug: Optional[BlockTypeFilterSlug] = Field(
        default=None, description="Filter criteria for `BlockType.slug`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.slug is not None:
            filters.append(self.slug.as_sql_filter())

        return filters

BlockTypeFilterName

Bases: PrefectFilterBaseModel

Filter by BlockType.name

Source code in src/prefect/server/schemas/filters.py
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
class BlockTypeFilterName(PrefectFilterBaseModel):
    """Filter by `BlockType.name`"""

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match. For example, "
            " passing 'marvin' will match "
            "'marvin', 'sad-Marvin', and 'marvin-robot'."
        ),
        examples=["marvin"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.like_ is not None:
            filters.append(orm_models.BlockType.name.ilike(f"%{self.like_}%"))
        return filters

BlockTypeFilterSlug

Bases: PrefectFilterBaseModel

Filter by BlockType.slug

Source code in src/prefect/server/schemas/filters.py
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
class BlockTypeFilterSlug(PrefectFilterBaseModel):
    """Filter by `BlockType.slug`"""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of slugs to match"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.BlockType.slug.in_(self.any_))

        return filters

DeploymentFilter

Bases: PrefectOperatorFilterBaseModel

Filter for deployments. Only deployments matching all criteria will be returned.

Source code in src/prefect/server/schemas/filters.py
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
class DeploymentFilter(PrefectOperatorFilterBaseModel):
    """Filter for deployments. Only deployments matching all criteria will be returned."""

    id: Optional[DeploymentFilterId] = Field(
        default=None, description="Filter criteria for `Deployment.id`"
    )
    name: Optional[DeploymentFilterName] = Field(
        default=None, description="Filter criteria for `Deployment.name`"
    )
    flow_or_deployment_name: Optional[DeploymentOrFlowNameFilter] = Field(
        default=None, description="Filter criteria for `Deployment.name` or `Flow.name`"
    )
    paused: Optional[DeploymentFilterPaused] = Field(
        default=None, description="Filter criteria for `Deployment.paused`"
    )
    tags: Optional[DeploymentFilterTags] = Field(
        default=None, description="Filter criteria for `Deployment.tags`"
    )
    work_queue_name: Optional[DeploymentFilterWorkQueueName] = Field(
        default=None, description="Filter criteria for `Deployment.work_queue_name`"
    )
    concurrency_limit: Optional[DeploymentFilterConcurrencyLimit] = Field(
        default=None,
        description="DEPRECATED: Prefer `Deployment.concurrency_limit_id` over `Deployment.concurrency_limit`. If provided, will be ignored for backwards-compatibility. Will be removed after December 2024.",
        deprecated=True,
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.flow_or_deployment_name is not None:
            filters.append(self.flow_or_deployment_name.as_sql_filter())
        if self.paused is not None:
            filters.append(self.paused.as_sql_filter())
        if self.tags is not None:
            filters.append(self.tags.as_sql_filter())
        if self.work_queue_name is not None:
            filters.append(self.work_queue_name.as_sql_filter())

        return filters

DeploymentFilterConcurrencyLimit

Bases: PrefectFilterBaseModel

Source code in src/prefect/server/schemas/filters.py
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
class DeploymentFilterConcurrencyLimit(PrefectFilterBaseModel):
    """DEPRECATED: Prefer `Deployment.concurrency_limit_id` over `Deployment.concurrency_limit`."""

    ge_: Optional[int] = Field(
        default=None,
        description="Only include deployments with a concurrency limit greater than or equal to this value",
    )

    le_: Optional[int] = Field(
        default=None,
        description="Only include deployments with a concurrency limit less than or equal to this value",
    )
    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include deployments without a concurrency limit",
    )

    def _get_filter_list(self) -> List:
        # This used to filter on an `int` column that was moved to a `ForeignKey` relationship
        # This filter is now deprecated rather than support filtering on the new relationship
        return []

DeploymentFilterId

Bases: PrefectFilterBaseModel

Filter by Deployment.id.

Source code in src/prefect/server/schemas/filters.py
939
940
941
942
943
944
945
946
947
948
949
950
class DeploymentFilterId(PrefectFilterBaseModel):
    """Filter by `Deployment.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of deployment ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Deployment.id.in_(self.any_))
        return filters

DeploymentFilterName

Bases: PrefectFilterBaseModel

Filter by Deployment.name.

Source code in src/prefect/server/schemas/filters.py
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
class DeploymentFilterName(PrefectFilterBaseModel):
    """Filter by `Deployment.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of deployment names to include",
        examples=[["my-deployment-1", "my-deployment-2"]],
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match. For example, "
            " passing 'marvin' will match "
            "'marvin', 'sad-Marvin', and 'marvin-robot'."
        ),
        examples=["marvin"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Deployment.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.Deployment.name.ilike(f"%{self.like_}%"))
        return filters

DeploymentFilterPaused

Bases: PrefectFilterBaseModel

Filter by Deployment.paused.

Source code in src/prefect/server/schemas/filters.py
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
class DeploymentFilterPaused(PrefectFilterBaseModel):
    """Filter by `Deployment.paused`."""

    eq_: Optional[bool] = Field(
        default=None,
        description="Only returns where deployment is/is not paused",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.eq_ is not None:
            filters.append(orm_models.Deployment.paused.is_(self.eq_))
        return filters

DeploymentFilterTags

Bases: PrefectOperatorFilterBaseModel

Filter by Deployment.tags.

Source code in src/prefect/server/schemas/filters.py
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
class DeploymentFilterTags(PrefectOperatorFilterBaseModel):
    """Filter by `Deployment.tags`."""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["tag-1", "tag-2"]],
        description=(
            "A list of tags. Deployments will be returned only if their tags are a"
            " superset of the list"
        ),
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only include deployments without tags"
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(json_has_all_keys(orm_models.Deployment.tags, self.all_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.Deployment.tags == []
                if self.is_null_
                else orm_models.Deployment.tags != []
            )
        return filters

DeploymentFilterWorkQueueName

Bases: PrefectFilterBaseModel

Filter by Deployment.work_queue_name.

Source code in src/prefect/server/schemas/filters.py
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
class DeploymentFilterWorkQueueName(PrefectFilterBaseModel):
    """Filter by `Deployment.work_queue_name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of work queue names to include",
        examples=[["work_queue_1", "work_queue_2"]],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Deployment.work_queue_name.in_(self.any_))
        return filters

DeploymentOrFlowNameFilter

Bases: PrefectFilterBaseModel

Filter by Deployment.name or Flow.name with a single input string for ilike filtering.

Source code in src/prefect/server/schemas/filters.py
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
class DeploymentOrFlowNameFilter(PrefectFilterBaseModel):
    """Filter by `Deployment.name` or `Flow.name` with a single input string for ilike filtering."""

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match on deployment or flow names. For example, "
            "passing 'example' might match deployments or flows with 'example' in their names."
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.like_ is not None:
            deployment_name_filter = orm_models.Deployment.name.ilike(f"%{self.like_}%")

            flow_name_filter = orm_models.Deployment.flow.has(
                orm_models.Flow.name.ilike(f"%{self.like_}%")
            )
            filters.append(sa.or_(deployment_name_filter, flow_name_filter))
        return filters

DeploymentScheduleFilter

Bases: PrefectOperatorFilterBaseModel

Filter for deployments. Only deployments matching all criteria will be returned.

Source code in src/prefect/server/schemas/filters.py
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
class DeploymentScheduleFilter(PrefectOperatorFilterBaseModel):
    """Filter for deployments. Only deployments matching all criteria will be returned."""

    active: Optional[DeploymentScheduleFilterActive] = Field(
        default=None, description="Filter criteria for `DeploymentSchedule.active`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.active is not None:
            filters.append(self.active.as_sql_filter())

        return filters

DeploymentScheduleFilterActive

Bases: PrefectFilterBaseModel

Filter by DeploymentSchedule.active.

Source code in src/prefect/server/schemas/filters.py
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
class DeploymentScheduleFilterActive(PrefectFilterBaseModel):
    """Filter by `DeploymentSchedule.active`."""

    eq_: Optional[bool] = Field(
        default=None,
        description="Only returns where deployment schedule is/is not active",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.eq_ is not None:
            filters.append(orm_models.DeploymentSchedule.active.is_(self.eq_))
        return filters

FilterSet

Bases: PrefectBaseModel

A collection of filters for common objects

Source code in src/prefect/server/schemas/filters.py
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
class FilterSet(PrefectBaseModel):
    """A collection of filters for common objects"""

    flows: FlowFilter = Field(
        default_factory=FlowFilter, description="Filters that apply to flows"
    )
    flow_runs: FlowRunFilter = Field(
        default_factory=FlowRunFilter, description="Filters that apply to flow runs"
    )
    task_runs: TaskRunFilter = Field(
        default_factory=TaskRunFilter, description="Filters that apply to task runs"
    )
    deployments: DeploymentFilter = Field(
        default_factory=DeploymentFilter,
        description="Filters that apply to deployments",
    )

FlowFilter

Bases: PrefectOperatorFilterBaseModel

Filter for flows. Only flows matching all criteria will be returned.

Source code in src/prefect/server/schemas/filters.py
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
class FlowFilter(PrefectOperatorFilterBaseModel):
    """Filter for flows. Only flows matching all criteria will be returned."""

    id: Optional[FlowFilterId] = Field(
        default=None, description="Filter criteria for `Flow.id`"
    )
    deployment: Optional[FlowFilterDeployment] = Field(
        default=None, description="Filter criteria for Flow deployments"
    )
    name: Optional[FlowFilterName] = Field(
        default=None, description="Filter criteria for `Flow.name`"
    )
    tags: Optional[FlowFilterTags] = Field(
        default=None, description="Filter criteria for `Flow.tags`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.deployment is not None:
            filters.append(self.deployment.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.tags is not None:
            filters.append(self.tags.as_sql_filter())

        return filters

FlowFilterDeployment

Bases: PrefectOperatorFilterBaseModel

Filter by flows by deployment

Source code in src/prefect/server/schemas/filters.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
class FlowFilterDeployment(PrefectOperatorFilterBaseModel):
    """Filter by flows by deployment"""

    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include flows without deployments",
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.is_null_ is not None:
            deployments_subquery = (
                sa.select(orm_models.Deployment.flow_id).distinct().subquery()
            )

            if self.is_null_:
                filters.append(
                    orm_models.Flow.id.not_in(sa.select(deployments_subquery.c.flow_id))
                )
            else:
                filters.append(
                    orm_models.Flow.id.in_(sa.select(deployments_subquery.c.flow_id))
                )

        return filters

FlowFilterId

Bases: PrefectFilterBaseModel

Filter by Flow.id.

Source code in src/prefect/server/schemas/filters.py
68
69
70
71
72
73
74
75
76
77
78
79
class FlowFilterId(PrefectFilterBaseModel):
    """Filter by `Flow.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Flow.id.in_(self.any_))
        return filters

FlowFilterName

Bases: PrefectFilterBaseModel

Filter by Flow.name.

Source code in src/prefect/server/schemas/filters.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
class FlowFilterName(PrefectFilterBaseModel):
    """Filter by `Flow.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of flow names to include",
        examples=[["my-flow-1", "my-flow-2"]],
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match. For example, "
            " passing 'marvin' will match "
            "'marvin', 'sad-Marvin', and 'marvin-robot'."
        ),
        examples=["marvin"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Flow.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.Flow.name.ilike(f"%{self.like_}%"))
        return filters

FlowFilterTags

Bases: PrefectOperatorFilterBaseModel

Filter by Flow.tags.

Source code in src/prefect/server/schemas/filters.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
class FlowFilterTags(PrefectOperatorFilterBaseModel):
    """Filter by `Flow.tags`."""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["tag-1", "tag-2"]],
        description=(
            "A list of tags. Flows will be returned only if their tags are a superset"
            " of the list"
        ),
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only include flows without tags"
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(json_has_all_keys(orm_models.Flow.tags, self.all_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.Flow.tags == []
                if self.is_null_
                else orm_models.Flow.tags != []
            )
        return filters

FlowRunFilter

Bases: PrefectOperatorFilterBaseModel

Filter flow runs. Only flow runs matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
class FlowRunFilter(PrefectOperatorFilterBaseModel):
    """Filter flow runs. Only flow runs matching all criteria will be returned"""

    id: Optional[FlowRunFilterId] = Field(
        default=None, description="Filter criteria for `FlowRun.id`"
    )
    name: Optional[FlowRunFilterName] = Field(
        default=None, description="Filter criteria for `FlowRun.name`"
    )
    tags: Optional[FlowRunFilterTags] = Field(
        default=None, description="Filter criteria for `FlowRun.tags`"
    )
    deployment_id: Optional[FlowRunFilterDeploymentId] = Field(
        default=None, description="Filter criteria for `FlowRun.deployment_id`"
    )
    work_queue_name: Optional[FlowRunFilterWorkQueueName] = Field(
        default=None, description="Filter criteria for `FlowRun.work_queue_name"
    )
    state: Optional[FlowRunFilterState] = Field(
        default=None, description="Filter criteria for `FlowRun.state`"
    )
    flow_version: Optional[FlowRunFilterFlowVersion] = Field(
        default=None, description="Filter criteria for `FlowRun.flow_version`"
    )
    start_time: Optional[FlowRunFilterStartTime] = Field(
        default=None, description="Filter criteria for `FlowRun.start_time`"
    )
    end_time: Optional[FlowRunFilterEndTime] = Field(
        default=None, description="Filter criteria for `FlowRun.end_time`"
    )
    expected_start_time: Optional[FlowRunFilterExpectedStartTime] = Field(
        default=None, description="Filter criteria for `FlowRun.expected_start_time`"
    )
    next_scheduled_start_time: Optional[FlowRunFilterNextScheduledStartTime] = Field(
        default=None,
        description="Filter criteria for `FlowRun.next_scheduled_start_time`",
    )
    parent_flow_run_id: Optional[FlowRunFilterParentFlowRunId] = Field(
        default=None, description="Filter criteria for subflows of the given flow runs"
    )
    parent_task_run_id: Optional[FlowRunFilterParentTaskRunId] = Field(
        default=None, description="Filter criteria for `FlowRun.parent_task_run_id`"
    )
    idempotency_key: Optional[FlowRunFilterIdempotencyKey] = Field(
        default=None, description="Filter criteria for `FlowRun.idempotency_key`"
    )

    def only_filters_on_id(self):
        return (
            self.id is not None
            and (self.id.any_ and not self.id.not_any_)
            and self.name is None
            and self.tags is None
            and self.deployment_id is None
            and self.work_queue_name is None
            and self.state is None
            and self.flow_version is None
            and self.start_time is None
            and self.end_time is None
            and self.expected_start_time is None
            and self.next_scheduled_start_time is None
            and self.parent_flow_run_id is None
            and self.parent_task_run_id is None
            and self.idempotency_key is None
        )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.tags is not None:
            filters.append(self.tags.as_sql_filter())
        if self.deployment_id is not None:
            filters.append(self.deployment_id.as_sql_filter())
        if self.work_queue_name is not None:
            filters.append(self.work_queue_name.as_sql_filter())
        if self.flow_version is not None:
            filters.append(self.flow_version.as_sql_filter())
        if self.state is not None:
            filters.append(self.state.as_sql_filter())
        if self.start_time is not None:
            filters.append(self.start_time.as_sql_filter())
        if self.end_time is not None:
            filters.append(self.end_time.as_sql_filter())
        if self.expected_start_time is not None:
            filters.append(self.expected_start_time.as_sql_filter())
        if self.next_scheduled_start_time is not None:
            filters.append(self.next_scheduled_start_time.as_sql_filter())
        if self.parent_flow_run_id is not None:
            filters.append(self.parent_flow_run_id.as_sql_filter())
        if self.parent_task_run_id is not None:
            filters.append(self.parent_task_run_id.as_sql_filter())
        if self.idempotency_key is not None:
            filters.append(self.idempotency_key.as_sql_filter())

        return filters

FlowRunFilterDeploymentId

Bases: PrefectOperatorFilterBaseModel

Filter by FlowRun.deployment_id.

Source code in src/prefect/server/schemas/filters.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
class FlowRunFilterDeploymentId(PrefectOperatorFilterBaseModel):
    """Filter by `FlowRun.deployment_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run deployment ids to include"
    )
    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include flow runs without deployment ids",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.deployment_id.in_(self.any_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.deployment_id.is_(None)
                if self.is_null_
                else orm_models.FlowRun.deployment_id.is_not(None)
            )
        return filters

FlowRunFilterEndTime

Bases: PrefectFilterBaseModel

Filter by FlowRun.end_time.

Source code in src/prefect/server/schemas/filters.py
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
class FlowRunFilterEndTime(PrefectFilterBaseModel):
    """Filter by `FlowRun.end_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs ending at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs ending at or after this time",
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only return flow runs without an end time"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.FlowRun.end_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.FlowRun.end_time >= self.after_)
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.end_time.is_(None)
                if self.is_null_
                else orm_models.FlowRun.end_time.is_not(None)
            )
        return filters

FlowRunFilterExpectedStartTime

Bases: PrefectFilterBaseModel

Filter by FlowRun.expected_start_time.

Source code in src/prefect/server/schemas/filters.py
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
class FlowRunFilterExpectedStartTime(PrefectFilterBaseModel):
    """Filter by `FlowRun.expected_start_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs scheduled to start at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs scheduled to start at or after this time",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.FlowRun.expected_start_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.FlowRun.expected_start_time >= self.after_)
        return filters

FlowRunFilterFlowVersion

Bases: PrefectFilterBaseModel

Filter by FlowRun.flow_version.

Source code in src/prefect/server/schemas/filters.py
383
384
385
386
387
388
389
390
391
392
393
394
class FlowRunFilterFlowVersion(PrefectFilterBaseModel):
    """Filter by `FlowRun.flow_version`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of flow run flow_versions to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.flow_version.in_(self.any_))
        return filters

FlowRunFilterId

Bases: PrefectFilterBaseModel

Filter by FlowRun.id.

Source code in src/prefect/server/schemas/filters.py
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
class FlowRunFilterId(PrefectFilterBaseModel):
    """Filter by `FlowRun.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run ids to include"
    )
    not_any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run ids to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.id.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.FlowRun.id.not_in(self.not_any_))
        return filters

FlowRunFilterIdempotencyKey

Bases: PrefectFilterBaseModel

Filter by FlowRun.idempotency_key.

Source code in src/prefect/server/schemas/filters.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
class FlowRunFilterIdempotencyKey(PrefectFilterBaseModel):
    """Filter by FlowRun.idempotency_key."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of flow run idempotency keys to include"
    )
    not_any_: Optional[List[str]] = Field(
        default=None, description="A list of flow run idempotency keys to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.idempotency_key.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.FlowRun.idempotency_key.not_in(self.not_any_))
        return filters

FlowRunFilterName

Bases: PrefectFilterBaseModel

Filter by FlowRun.name.

Source code in src/prefect/server/schemas/filters.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
class FlowRunFilterName(PrefectFilterBaseModel):
    """Filter by `FlowRun.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of flow run names to include",
        examples=[["my-flow-run-1", "my-flow-run-2"]],
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match. For example, "
            " passing 'marvin' will match "
            "'marvin', 'sad-Marvin', and 'marvin-robot'."
        ),
        examples=["marvin"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.FlowRun.name.ilike(f"%{self.like_}%"))
        return filters

FlowRunFilterNextScheduledStartTime

Bases: PrefectFilterBaseModel

Filter by FlowRun.next_scheduled_start_time.

Source code in src/prefect/server/schemas/filters.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
class FlowRunFilterNextScheduledStartTime(PrefectFilterBaseModel):
    """Filter by `FlowRun.next_scheduled_start_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description=(
            "Only include flow runs with a next_scheduled_start_time or before this"
            " time"
        ),
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description=(
            "Only include flow runs with a next_scheduled_start_time at or after this"
            " time"
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.FlowRun.next_scheduled_start_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.FlowRun.next_scheduled_start_time >= self.after_)
        return filters

FlowRunFilterParentFlowRunId

Bases: PrefectOperatorFilterBaseModel

Filter for subflows of a given flow run

Source code in src/prefect/server/schemas/filters.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
class FlowRunFilterParentFlowRunId(PrefectOperatorFilterBaseModel):
    """Filter for subflows of a given flow run"""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of parent flow run ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(
                orm_models.FlowRun.id.in_(
                    sa.select(orm_models.FlowRun.id)
                    .join(
                        orm_models.TaskRun,
                        sa.and_(
                            orm_models.TaskRun.id
                            == orm_models.FlowRun.parent_task_run_id,
                        ),
                    )
                    .where(orm_models.TaskRun.flow_run_id.in_(self.any_))
                )
            )
        return filters

FlowRunFilterParentTaskRunId

Bases: PrefectOperatorFilterBaseModel

Filter by FlowRun.parent_task_run_id.

Source code in src/prefect/server/schemas/filters.py
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
class FlowRunFilterParentTaskRunId(PrefectOperatorFilterBaseModel):
    """Filter by `FlowRun.parent_task_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run parent_task_run_ids to include"
    )
    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include flow runs without parent_task_run_id",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.parent_task_run_id.in_(self.any_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.parent_task_run_id.is_(None)
                if self.is_null_
                else orm_models.FlowRun.parent_task_run_id.is_not(None)
            )
        return filters

FlowRunFilterStartTime

Bases: PrefectFilterBaseModel

Filter by FlowRun.start_time.

Source code in src/prefect/server/schemas/filters.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
class FlowRunFilterStartTime(PrefectFilterBaseModel):
    """Filter by `FlowRun.start_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs starting at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include flow runs starting at or after this time",
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only return flow runs without a start time"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.FlowRun.start_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.FlowRun.start_time >= self.after_)
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.start_time.is_(None)
                if self.is_null_
                else orm_models.FlowRun.start_time.is_not(None)
            )
        return filters

FlowRunFilterState

Bases: PrefectOperatorFilterBaseModel

Filter by FlowRun.state_type and FlowRun.state_name.

Source code in src/prefect/server/schemas/filters.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
class FlowRunFilterState(PrefectOperatorFilterBaseModel):
    """Filter by `FlowRun.state_type` and `FlowRun.state_name`."""

    type: Optional[FlowRunFilterStateType] = Field(
        default=None, description="Filter criteria for `FlowRun.state_type`"
    )
    name: Optional[FlowRunFilterStateName] = Field(
        default=None, description="Filter criteria for `FlowRun.state_name`"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.type is not None:
            filters.extend(self.type._get_filter_list())
        if self.name is not None:
            filters.extend(self.name._get_filter_list())
        return filters

FlowRunFilterStateName

Bases: PrefectFilterBaseModel

Filter by FlowRun.state_name.

Source code in src/prefect/server/schemas/filters.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
class FlowRunFilterStateName(PrefectFilterBaseModel):
    """Filter by `FlowRun.state_name`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of flow run state names to include"
    )
    not_any_: Optional[List[str]] = Field(
        default=None, description="A list of flow run state names to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.state_name.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.FlowRun.state_name.not_in(self.not_any_))
        return filters

FlowRunFilterStateType

Bases: PrefectFilterBaseModel

Filter by FlowRun.state_type.

Source code in src/prefect/server/schemas/filters.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
class FlowRunFilterStateType(PrefectFilterBaseModel):
    """Filter by `FlowRun.state_type`."""

    any_: Optional[List[schemas.states.StateType]] = Field(
        default=None, description="A list of flow run state types to include"
    )
    not_any_: Optional[List[schemas.states.StateType]] = Field(
        default=None, description="A list of flow run state types to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.state_type.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.FlowRun.state_type.not_in(self.not_any_))
        return filters

FlowRunFilterTags

Bases: PrefectOperatorFilterBaseModel

Filter by FlowRun.tags.

Source code in src/prefect/server/schemas/filters.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
class FlowRunFilterTags(PrefectOperatorFilterBaseModel):
    """Filter by `FlowRun.tags`."""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["tag-1", "tag-2"]],
        description=(
            "A list of tags. Flow runs will be returned only if their tags are a"
            " superset of the list"
        ),
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only include flow runs without tags"
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(json_has_all_keys(orm_models.FlowRun.tags, self.all_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.tags == []
                if self.is_null_
                else orm_models.FlowRun.tags != []
            )
        return filters

FlowRunFilterWorkQueueName

Bases: PrefectOperatorFilterBaseModel

Filter by FlowRun.work_queue_name.

Source code in src/prefect/server/schemas/filters.py
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
class FlowRunFilterWorkQueueName(PrefectOperatorFilterBaseModel):
    """Filter by `FlowRun.work_queue_name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of work queue names to include",
        examples=[["work_queue_1", "work_queue_2"]],
    )
    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include flow runs without work queue names",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.FlowRun.work_queue_name.in_(self.any_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.FlowRun.work_queue_name.is_(None)
                if self.is_null_
                else orm_models.FlowRun.work_queue_name.is_not(None)
            )
        return filters

FlowRunNotificationPolicyFilter

Bases: PrefectFilterBaseModel

Filter FlowRunNotificationPolicies.

Source code in src/prefect/server/schemas/filters.py
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
class FlowRunNotificationPolicyFilter(PrefectFilterBaseModel):
    """Filter FlowRunNotificationPolicies."""

    is_active: Optional[FlowRunNotificationPolicyFilterIsActive] = Field(
        default=FlowRunNotificationPolicyFilterIsActive(eq_=False),
        description="Filter criteria for `FlowRunNotificationPolicy.is_active`. ",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.is_active is not None:
            filters.append(self.is_active.as_sql_filter())

        return filters

FlowRunNotificationPolicyFilterIsActive

Bases: PrefectFilterBaseModel

Filter by FlowRunNotificationPolicy.is_active.

Source code in src/prefect/server/schemas/filters.py
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
class FlowRunNotificationPolicyFilterIsActive(PrefectFilterBaseModel):
    """Filter by `FlowRunNotificationPolicy.is_active`."""

    eq_: Optional[bool] = Field(
        default=None,
        description=(
            "Filter notification policies for only those that are or are not active."
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.eq_ is not None:
            filters.append(orm_models.FlowRunNotificationPolicy.is_active.is_(self.eq_))
        return filters

LogFilter

Bases: PrefectOperatorFilterBaseModel

Filter logs. Only logs matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
class LogFilter(PrefectOperatorFilterBaseModel):
    """Filter logs. Only logs matching all criteria will be returned"""

    level: Optional[LogFilterLevel] = Field(
        default=None, description="Filter criteria for `Log.level`"
    )
    timestamp: Optional[LogFilterTimestamp] = Field(
        default=None, description="Filter criteria for `Log.timestamp`"
    )
    flow_run_id: Optional[LogFilterFlowRunId] = Field(
        default=None, description="Filter criteria for `Log.flow_run_id`"
    )
    task_run_id: Optional[LogFilterTaskRunId] = Field(
        default=None, description="Filter criteria for `Log.task_run_id`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.level is not None:
            filters.append(self.level.as_sql_filter())
        if self.timestamp is not None:
            filters.append(self.timestamp.as_sql_filter())
        if self.flow_run_id is not None:
            filters.append(self.flow_run_id.as_sql_filter())
        if self.task_run_id is not None:
            filters.append(self.task_run_id.as_sql_filter())

        return filters

LogFilterFlowRunId

Bases: PrefectFilterBaseModel

Filter by Log.flow_run_id.

Source code in src/prefect/server/schemas/filters.py
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
class LogFilterFlowRunId(PrefectFilterBaseModel):
    """Filter by `Log.flow_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of flow run IDs to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Log.flow_run_id.in_(self.any_))
        return filters

LogFilterLevel

Bases: PrefectFilterBaseModel

Filter by Log.level.

Source code in src/prefect/server/schemas/filters.py
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
class LogFilterLevel(PrefectFilterBaseModel):
    """Filter by `Log.level`."""

    ge_: Optional[int] = Field(
        default=None,
        description="Include logs with a level greater than or equal to this level",
        examples=[20],
    )

    le_: Optional[int] = Field(
        default=None,
        description="Include logs with a level less than or equal to this level",
        examples=[50],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.ge_ is not None:
            filters.append(orm_models.Log.level >= self.ge_)
        if self.le_ is not None:
            filters.append(orm_models.Log.level <= self.le_)
        return filters

LogFilterName

Bases: PrefectFilterBaseModel

Filter by Log.name.

Source code in src/prefect/server/schemas/filters.py
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
class LogFilterName(PrefectFilterBaseModel):
    """Filter by `Log.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of log names to include",
        examples=[["prefect.logger.flow_runs", "prefect.logger.task_runs"]],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Log.name.in_(self.any_))
        return filters

LogFilterTaskRunId

Bases: PrefectFilterBaseModel

Filter by Log.task_run_id.

Source code in src/prefect/server/schemas/filters.py
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
class LogFilterTaskRunId(PrefectFilterBaseModel):
    """Filter by `Log.task_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of task run IDs to include"
    )

    is_null_: Optional[bool] = Field(
        default=None,
        description="If true, only include logs without a task run id",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Log.task_run_id.in_(self.any_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.Log.task_run_id.is_(None)
                if self.is_null_
                else orm_models.Log.task_run_id.is_not(None)
            )
        return filters

LogFilterTimestamp

Bases: PrefectFilterBaseModel

Filter by Log.timestamp.

Source code in src/prefect/server/schemas/filters.py
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
class LogFilterTimestamp(PrefectFilterBaseModel):
    """Filter by `Log.timestamp`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include logs with a timestamp at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include logs with a timestamp at or after this time",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.Log.timestamp <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.Log.timestamp >= self.after_)
        return filters

Operator

Bases: AutoEnum

Operators for combining filter criteria.

Source code in src/prefect/server/schemas/filters.py
29
30
31
32
33
class Operator(AutoEnum):
    """Operators for combining filter criteria."""

    and_ = AutoEnum.auto()
    or_ = AutoEnum.auto()

PrefectFilterBaseModel

Bases: PrefectBaseModel

Base model for Prefect filters

Source code in src/prefect/server/schemas/filters.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class PrefectFilterBaseModel(PrefectBaseModel):
    """Base model for Prefect filters"""

    model_config = ConfigDict(extra="forbid")

    def as_sql_filter(self) -> "BooleanClauseList":
        """Generate SQL filter from provided filter parameters. If no filters parameters are available, return a TRUE filter."""
        filters = self._get_filter_list()
        if not filters:
            return True
        return sa.and_(*filters)

    def _get_filter_list(self) -> List:
        """Return a list of boolean filter statements based on filter parameters"""
        raise NotImplementedError("_get_filter_list must be implemented")

as_sql_filter()

Generate SQL filter from provided filter parameters. If no filters parameters are available, return a TRUE filter.

Source code in src/prefect/server/schemas/filters.py
41
42
43
44
45
46
def as_sql_filter(self) -> "BooleanClauseList":
    """Generate SQL filter from provided filter parameters. If no filters parameters are available, return a TRUE filter."""
    filters = self._get_filter_list()
    if not filters:
        return True
    return sa.and_(*filters)

PrefectOperatorFilterBaseModel

Bases: PrefectFilterBaseModel

Base model for Prefect filters that combines criteria with a user-provided operator

Source code in src/prefect/server/schemas/filters.py
53
54
55
56
57
58
59
60
61
62
63
64
65
class PrefectOperatorFilterBaseModel(PrefectFilterBaseModel):
    """Base model for Prefect filters that combines criteria with a user-provided operator"""

    operator: Operator = Field(
        default=Operator.and_,
        description="Operator for combining filter criteria. Defaults to 'and_'.",
    )

    def as_sql_filter(self) -> "BooleanClauseList":
        filters = self._get_filter_list()
        if not filters:
            return True
        return sa.and_(*filters) if self.operator == Operator.and_ else sa.or_(*filters)

TaskRunFilter

Bases: PrefectOperatorFilterBaseModel

Filter task runs. Only task runs matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
class TaskRunFilter(PrefectOperatorFilterBaseModel):
    """Filter task runs. Only task runs matching all criteria will be returned"""

    id: Optional[TaskRunFilterId] = Field(
        default=None, description="Filter criteria for `TaskRun.id`"
    )
    name: Optional[TaskRunFilterName] = Field(
        default=None, description="Filter criteria for `TaskRun.name`"
    )
    tags: Optional[TaskRunFilterTags] = Field(
        default=None, description="Filter criteria for `TaskRun.tags`"
    )
    state: Optional[TaskRunFilterState] = Field(
        default=None, description="Filter criteria for `TaskRun.state`"
    )
    start_time: Optional[TaskRunFilterStartTime] = Field(
        default=None, description="Filter criteria for `TaskRun.start_time`"
    )
    expected_start_time: Optional[TaskRunFilterExpectedStartTime] = Field(
        default=None, description="Filter criteria for `TaskRun.expected_start_time`"
    )
    subflow_runs: Optional[TaskRunFilterSubFlowRuns] = Field(
        default=None, description="Filter criteria for `TaskRun.subflow_run`"
    )
    flow_run_id: Optional[TaskRunFilterFlowRunId] = Field(
        default=None, description="Filter criteria for `TaskRun.flow_run_id`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.tags is not None:
            filters.append(self.tags.as_sql_filter())
        if self.state is not None:
            filters.append(self.state.as_sql_filter())
        if self.start_time is not None:
            filters.append(self.start_time.as_sql_filter())
        if self.expected_start_time is not None:
            filters.append(self.expected_start_time.as_sql_filter())
        if self.subflow_runs is not None:
            filters.append(self.subflow_runs.as_sql_filter())
        if self.flow_run_id is not None:
            filters.append(self.flow_run_id.as_sql_filter())

        return filters

TaskRunFilterExpectedStartTime

Bases: PrefectFilterBaseModel

Filter by TaskRun.expected_start_time.

Source code in src/prefect/server/schemas/filters.py
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
class TaskRunFilterExpectedStartTime(PrefectFilterBaseModel):
    """Filter by `TaskRun.expected_start_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include task runs expected to start at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include task runs expected to start at or after this time",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.TaskRun.expected_start_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.TaskRun.expected_start_time >= self.after_)
        return filters

TaskRunFilterFlowRunId

Bases: PrefectOperatorFilterBaseModel

Filter by TaskRun.flow_run_id.

Source code in src/prefect/server/schemas/filters.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
class TaskRunFilterFlowRunId(PrefectOperatorFilterBaseModel):
    """Filter by `TaskRun.flow_run_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of task run flow run ids to include"
    )

    is_null_: Optional[bool] = Field(
        default=False, description="Filter for task runs with None as their flow run id"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.is_null_ is True:
            filters.append(orm_models.TaskRun.flow_run_id.is_(None))
        elif self.is_null_ is False and self.any_ is None:
            filters.append(orm_models.TaskRun.flow_run_id.is_not(None))
        else:
            if self.any_ is not None:
                filters.append(orm_models.TaskRun.flow_run_id.in_(self.any_))
        return filters

TaskRunFilterId

Bases: PrefectFilterBaseModel

Filter by TaskRun.id.

Source code in src/prefect/server/schemas/filters.py
698
699
700
701
702
703
704
705
706
707
708
709
class TaskRunFilterId(PrefectFilterBaseModel):
    """Filter by `TaskRun.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of task run ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.TaskRun.id.in_(self.any_))
        return filters

TaskRunFilterName

Bases: PrefectFilterBaseModel

Filter by TaskRun.name.

Source code in src/prefect/server/schemas/filters.py
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
class TaskRunFilterName(PrefectFilterBaseModel):
    """Filter by `TaskRun.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of task run names to include",
        examples=[["my-task-run-1", "my-task-run-2"]],
    )

    like_: Optional[str] = Field(
        default=None,
        description=(
            "A case-insensitive partial match. For example, "
            " passing 'marvin' will match "
            "'marvin', 'sad-Marvin', and 'marvin-robot'."
        ),
        examples=["marvin"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.TaskRun.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.TaskRun.name.ilike(f"%{self.like_}%"))
        return filters

TaskRunFilterStartTime

Bases: PrefectFilterBaseModel

Filter by TaskRun.start_time.

Source code in src/prefect/server/schemas/filters.py
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
class TaskRunFilterStartTime(PrefectFilterBaseModel):
    """Filter by `TaskRun.start_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description="Only include task runs starting at or before this time",
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description="Only include task runs starting at or after this time",
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only return task runs without a start time"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.TaskRun.start_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.TaskRun.start_time >= self.after_)
        if self.is_null_ is not None:
            filters.append(
                orm_models.TaskRun.start_time.is_(None)
                if self.is_null_
                else orm_models.TaskRun.start_time.is_not(None)
            )
        return filters

TaskRunFilterState

Bases: PrefectOperatorFilterBaseModel

Filter by TaskRun.type and TaskRun.name.

Source code in src/prefect/server/schemas/filters.py
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
class TaskRunFilterState(PrefectOperatorFilterBaseModel):
    """Filter by `TaskRun.type` and `TaskRun.name`."""

    type: Optional[TaskRunFilterStateType] = Field(
        default=None, description="Filter criteria for `TaskRun.state_type`"
    )
    name: Optional[TaskRunFilterStateName] = Field(
        default=None, description="Filter criteria for `TaskRun.state_name`"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.type is not None:
            filters.extend(self.type._get_filter_list())
        if self.name is not None:
            filters.extend(self.name._get_filter_list())
        return filters

TaskRunFilterStateName

Bases: PrefectFilterBaseModel

Filter by TaskRun.state_name.

Source code in src/prefect/server/schemas/filters.py
784
785
786
787
788
789
790
791
792
793
794
795
class TaskRunFilterStateName(PrefectFilterBaseModel):
    """Filter by `TaskRun.state_name`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of task run state names to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.TaskRun.state_name.in_(self.any_))
        return filters

TaskRunFilterStateType

Bases: PrefectFilterBaseModel

Filter by TaskRun.state_type.

Source code in src/prefect/server/schemas/filters.py
770
771
772
773
774
775
776
777
778
779
780
781
class TaskRunFilterStateType(PrefectFilterBaseModel):
    """Filter by `TaskRun.state_type`."""

    any_: Optional[List[schemas.states.StateType]] = Field(
        default=None, description="A list of task run state types to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.TaskRun.state_type.in_(self.any_))
        return filters

TaskRunFilterSubFlowRuns

Bases: PrefectFilterBaseModel

Filter by TaskRun.subflow_run.

Source code in src/prefect/server/schemas/filters.py
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
class TaskRunFilterSubFlowRuns(PrefectFilterBaseModel):
    """Filter by `TaskRun.subflow_run`."""

    exists_: Optional[bool] = Field(
        default=None,
        description=(
            "If true, only include task runs that are subflow run parents; if false,"
            " exclude parent task runs"
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.exists_ is True:
            filters.append(orm_models.TaskRun.subflow_run.has())
        elif self.exists_ is False:
            filters.append(sa.not_(orm_models.TaskRun.subflow_run.has()))
        return filters

TaskRunFilterTags

Bases: PrefectOperatorFilterBaseModel

Filter by TaskRun.tags.

Source code in src/prefect/server/schemas/filters.py
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
class TaskRunFilterTags(PrefectOperatorFilterBaseModel):
    """Filter by `TaskRun.tags`."""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["tag-1", "tag-2"]],
        description=(
            "A list of tags. Task runs will be returned only if their tags are a"
            " superset of the list"
        ),
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only include task runs without tags"
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(json_has_all_keys(orm_models.TaskRun.tags, self.all_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.TaskRun.tags == []
                if self.is_null_
                else orm_models.TaskRun.tags != []
            )
        return filters

VariableFilter

Bases: PrefectOperatorFilterBaseModel

Filter variables. Only variables matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
class VariableFilter(PrefectOperatorFilterBaseModel):
    """Filter variables. Only variables matching all criteria will be returned"""

    id: Optional[VariableFilterId] = Field(
        default=None, description="Filter criteria for `Variable.id`"
    )
    name: Optional[VariableFilterName] = Field(
        default=None, description="Filter criteria for `Variable.name`"
    )
    tags: Optional[VariableFilterTags] = Field(
        default=None, description="Filter criteria for `Variable.tags`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.tags is not None:
            filters.append(self.tags.as_sql_filter())
        return filters

VariableFilterId

Bases: PrefectFilterBaseModel

Filter by Variable.id.

Source code in src/prefect/server/schemas/filters.py
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
class VariableFilterId(PrefectFilterBaseModel):
    """Filter by `Variable.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of variable ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Variable.id.in_(self.any_))
        return filters

VariableFilterName

Bases: PrefectFilterBaseModel

Filter by Variable.name.

Source code in src/prefect/server/schemas/filters.py
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
class VariableFilterName(PrefectFilterBaseModel):
    """Filter by `Variable.name`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of variables names to include"
    )
    like_: Optional[str] = Field(
        default=None,
        description=(
            "A string to match variable names against. This can include "
            "SQL wildcard characters like `%` and `_`."
        ),
        examples=["my_variable_%"],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Variable.name.in_(self.any_))
        if self.like_ is not None:
            filters.append(orm_models.Variable.name.ilike(f"%{self.like_}%"))
        return filters

VariableFilterTags

Bases: PrefectOperatorFilterBaseModel

Filter by Variable.tags.

Source code in src/prefect/server/schemas/filters.py
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
class VariableFilterTags(PrefectOperatorFilterBaseModel):
    """Filter by `Variable.tags`."""

    all_: Optional[List[str]] = Field(
        default=None,
        examples=[["tag-1", "tag-2"]],
        description=(
            "A list of tags. Variables will be returned only if their tags are a"
            " superset of the list"
        ),
    )
    is_null_: Optional[bool] = Field(
        default=None, description="If true, only include Variables without tags"
    )

    def _get_filter_list(self) -> List:
        from prefect.server.utilities.database import json_has_all_keys

        filters = []
        if self.all_ is not None:
            filters.append(json_has_all_keys(orm_models.Variable.tags, self.all_))
        if self.is_null_ is not None:
            filters.append(
                orm_models.Variable.tags == []
                if self.is_null_
                else orm_models.Variable.tags != []
            )
        return filters

WorkPoolFilter

Bases: PrefectOperatorFilterBaseModel

Filter work pools. Only work pools matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
class WorkPoolFilter(PrefectOperatorFilterBaseModel):
    """Filter work pools. Only work pools matching all criteria will be returned"""

    id: Optional[WorkPoolFilterId] = Field(
        default=None, description="Filter criteria for `WorkPool.id`"
    )
    name: Optional[WorkPoolFilterName] = Field(
        default=None, description="Filter criteria for `WorkPool.name`"
    )
    type: Optional[WorkPoolFilterType] = Field(
        default=None, description="Filter criteria for `WorkPool.type`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())
        if self.type is not None:
            filters.append(self.type.as_sql_filter())

        return filters

WorkPoolFilterId

Bases: PrefectFilterBaseModel

Filter by WorkPool.id.

Source code in src/prefect/server/schemas/filters.py
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
class WorkPoolFilterId(PrefectFilterBaseModel):
    """Filter by `WorkPool.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of work pool ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.WorkPool.id.in_(self.any_))
        return filters

WorkPoolFilterName

Bases: PrefectFilterBaseModel

Filter by WorkPool.name.

Source code in src/prefect/server/schemas/filters.py
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
class WorkPoolFilterName(PrefectFilterBaseModel):
    """Filter by `WorkPool.name`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of work pool names to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.WorkPool.name.in_(self.any_))
        return filters

WorkPoolFilterType

Bases: PrefectFilterBaseModel

Filter by WorkPool.type.

Source code in src/prefect/server/schemas/filters.py
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
class WorkPoolFilterType(PrefectFilterBaseModel):
    """Filter by `WorkPool.type`."""

    any_: Optional[List[str]] = Field(
        default=None, description="A list of work pool types to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.WorkPool.type.in_(self.any_))
        return filters

WorkQueueFilter

Bases: PrefectOperatorFilterBaseModel

Filter work queues. Only work queues matching all criteria will be returned

Source code in src/prefect/server/schemas/filters.py
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
class WorkQueueFilter(PrefectOperatorFilterBaseModel):
    """Filter work queues. Only work queues matching all criteria will be
    returned"""

    id: Optional[WorkQueueFilterId] = Field(
        default=None, description="Filter criteria for `WorkQueue.id`"
    )

    name: Optional[WorkQueueFilterName] = Field(
        default=None, description="Filter criteria for `WorkQueue.name`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.id is not None:
            filters.append(self.id.as_sql_filter())
        if self.name is not None:
            filters.append(self.name.as_sql_filter())

        return filters

WorkQueueFilterId

Bases: PrefectFilterBaseModel

Filter by WorkQueue.id.

Source code in src/prefect/server/schemas/filters.py
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
class WorkQueueFilterId(PrefectFilterBaseModel):
    """Filter by `WorkQueue.id`."""

    any_: Optional[List[UUID]] = Field(
        default=None,
        description="A list of work queue ids to include",
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.WorkQueue.id.in_(self.any_))
        return filters

WorkQueueFilterName

Bases: PrefectFilterBaseModel

Filter by WorkQueue.name.

Source code in src/prefect/server/schemas/filters.py
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
class WorkQueueFilterName(PrefectFilterBaseModel):
    """Filter by `WorkQueue.name`."""

    any_: Optional[List[str]] = Field(
        default=None,
        description="A list of work queue names to include",
        examples=[["wq-1", "wq-2"]],
    )

    startswith_: Optional[List[str]] = Field(
        default=None,
        description=(
            "A list of case-insensitive starts-with matches. For example, "
            " passing 'marvin' will match "
            "'marvin', and 'Marvin-robot', but not 'sad-marvin'."
        ),
        examples=[["marvin", "Marvin-robot"]],
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.WorkQueue.name.in_(self.any_))
        if self.startswith_ is not None:
            filters.append(
                sa.or_(
                    *[
                        orm_models.WorkQueue.name.ilike(f"{item}%")
                        for item in self.startswith_
                    ]
                )
            )
        return filters

WorkerFilter

Bases: PrefectOperatorFilterBaseModel

Filter by Worker.last_heartbeat_time.

Source code in src/prefect/server/schemas/filters.py
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
class WorkerFilter(PrefectOperatorFilterBaseModel):
    """Filter by `Worker.last_heartbeat_time`."""

    # worker_config_id: Optional[WorkerFilterWorkPoolId] = Field(
    #     default=None, description="Filter criteria for `Worker.worker_config_id`"
    # )

    last_heartbeat_time: Optional[WorkerFilterLastHeartbeatTime] = Field(
        default=None,
        description="Filter criteria for `Worker.last_heartbeat_time`",
    )

    status: Optional[WorkerFilterStatus] = Field(
        default=None, description="Filter criteria for `Worker.status`"
    )

    def _get_filter_list(self) -> List:
        filters = []

        if self.last_heartbeat_time is not None:
            filters.append(self.last_heartbeat_time.as_sql_filter())

        if self.status is not None:
            filters.append(self.status.as_sql_filter())

        return filters

WorkerFilterLastHeartbeatTime

Bases: PrefectFilterBaseModel

Filter by Worker.last_heartbeat_time.

Source code in src/prefect/server/schemas/filters.py
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
class WorkerFilterLastHeartbeatTime(PrefectFilterBaseModel):
    """Filter by `Worker.last_heartbeat_time`."""

    before_: Optional[DateTime] = Field(
        default=None,
        description=(
            "Only include processes whose last heartbeat was at or before this time"
        ),
    )
    after_: Optional[DateTime] = Field(
        default=None,
        description=(
            "Only include processes whose last heartbeat was at or after this time"
        ),
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.before_ is not None:
            filters.append(orm_models.Worker.last_heartbeat_time <= self.before_)
        if self.after_ is not None:
            filters.append(orm_models.Worker.last_heartbeat_time >= self.after_)
        return filters

WorkerFilterStatus

Bases: PrefectFilterBaseModel

Filter by Worker.status.

Source code in src/prefect/server/schemas/filters.py
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
class WorkerFilterStatus(PrefectFilterBaseModel):
    """Filter by `Worker.status`."""

    any_: Optional[List[schemas.statuses.WorkerStatus]] = Field(
        default=None, description="A list of worker statuses to include"
    )
    not_any_: Optional[List[schemas.statuses.WorkerStatus]] = Field(
        default=None, description="A list of worker statuses to exclude"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Worker.status.in_(self.any_))
        if self.not_any_ is not None:
            filters.append(orm_models.Worker.status.notin_(self.not_any_))
        return filters

WorkerFilterWorkPoolId

Bases: PrefectFilterBaseModel

Filter by Worker.worker_config_id.

Source code in src/prefect/server/schemas/filters.py
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
class WorkerFilterWorkPoolId(PrefectFilterBaseModel):
    """Filter by `Worker.worker_config_id`."""

    any_: Optional[List[UUID]] = Field(
        default=None, description="A list of work pool ids to include"
    )

    def _get_filter_list(self) -> List:
        filters = []
        if self.any_ is not None:
            filters.append(orm_models.Worker.worker_config_id.in_(self.any_))
        return filters