Skip to content

prefect.server.api.block_documents

Routes for interacting with block objects.

count_block_documents(block_documents=None, block_types=None, block_schemas=None, db=Depends(provide_database_interface)) async

Count block documents.

Source code in src/prefect/server/api/block_documents.py
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@router.post("/count")
async def count_block_documents(
    block_documents: Optional[schemas.filters.BlockDocumentFilter] = None,
    block_types: Optional[schemas.filters.BlockTypeFilter] = None,
    block_schemas: Optional[schemas.filters.BlockSchemaFilter] = None,
    db: PrefectDBInterface = Depends(provide_database_interface),
) -> int:
    """
    Count block documents.
    """
    async with db.session_context() as session:
        result = await models.block_documents.count_block_documents(
            session=session,
            block_document_filter=block_documents,
            block_type_filter=block_types,
            block_schema_filter=block_schemas,
        )

    return result

create_block_document(block_document, db=Depends(provide_database_interface)) async

Create a new block document.

Source code in src/prefect/server/api/block_documents.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
@router.post("/", status_code=status.HTTP_201_CREATED)
async def create_block_document(
    block_document: schemas.actions.BlockDocumentCreate,
    db: PrefectDBInterface = Depends(provide_database_interface),
) -> schemas.core.BlockDocument:
    """
    Create a new block document.
    """
    async with db.session_context(begin_transaction=True) as session:
        if block_document.name is not None:
            exists = (
                await models.block_documents.block_document_with_unique_values_exists(
                    session=session,
                    block_type_id=block_document.block_type_id,
                    name=block_document.name,
                )
            )
            if exists:
                raise HTTPException(
                    status.HTTP_409_CONFLICT,
                    detail="Block already exists",
                )

        return await models.block_documents.create_block_document(
            session=session, block_document=block_document
        )

read_block_documents(limit=dependencies.LimitBody(), block_documents=None, block_types=None, block_schemas=None, include_secrets=Body(False, description='Whether to include sensitive values in the block document.'), sort=Body(schemas.sorting.BlockDocumentSort.NAME_ASC), offset=Body(0, ge=0), db=Depends(provide_database_interface)) async

Query for block documents.

Source code in src/prefect/server/api/block_documents.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@router.post("/filter")
async def read_block_documents(
    limit: int = dependencies.LimitBody(),
    block_documents: Optional[schemas.filters.BlockDocumentFilter] = None,
    block_types: Optional[schemas.filters.BlockTypeFilter] = None,
    block_schemas: Optional[schemas.filters.BlockSchemaFilter] = None,
    include_secrets: bool = Body(
        False, description="Whether to include sensitive values in the block document."
    ),
    sort: Optional[schemas.sorting.BlockDocumentSort] = Body(
        schemas.sorting.BlockDocumentSort.NAME_ASC
    ),
    offset: int = Body(0, ge=0),
    db: PrefectDBInterface = Depends(provide_database_interface),
) -> List[schemas.core.BlockDocument]:
    """
    Query for block documents.
    """
    async with db.session_context() as session:
        result = await models.block_documents.read_block_documents(
            session=session,
            block_document_filter=block_documents,
            block_type_filter=block_types,
            block_schema_filter=block_schemas,
            include_secrets=include_secrets,
            sort=sort,
            offset=offset,
            limit=limit,
        )

    return result