Skip to content

prefect.server.api.admin

Routes for admin-level interactions with the Prefect REST API.

clear_database(db=Depends(provide_database_interface), confirm=Body(False, embed=True, description='Pass confirm=True to confirm you want to modify the database.'), response=None) async

Clear all database tables without dropping them.

Source code in src/prefect/server/api/admin.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
@router.post("/database/clear", status_code=status.HTTP_204_NO_CONTENT)
async def clear_database(
    db: PrefectDBInterface = Depends(provide_database_interface),
    confirm: bool = Body(
        False,
        embed=True,
        description="Pass confirm=True to confirm you want to modify the database.",
    ),
    response: Response = None,  # type: ignore
):
    """Clear all database tables without dropping them."""
    if not confirm:
        response.status_code = status.HTTP_400_BAD_REQUEST
        return
    async with db.session_context(begin_transaction=True) as session:
        # work pool has a circular dependency on pool queue; delete it first
        await session.execute(db.WorkPool.__table__.delete())
        for table in reversed(db.Base.metadata.sorted_tables):
            await session.execute(table.delete())

create_database(db=Depends(provide_database_interface), confirm=Body(False, embed=True, description='Pass confirm=True to confirm you want to modify the database.'), response=None) async

Create all database objects.

Source code in src/prefect/server/api/admin.py
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@router.post("/database/create", status_code=status.HTTP_204_NO_CONTENT)
async def create_database(
    db: PrefectDBInterface = Depends(provide_database_interface),
    confirm: bool = Body(
        False,
        embed=True,
        description="Pass confirm=True to confirm you want to modify the database.",
    ),
    response: Response = None,
):
    """Create all database objects."""
    if not confirm:
        response.status_code = status.HTTP_400_BAD_REQUEST
        return

    await db.create_db()

drop_database(db=Depends(provide_database_interface), confirm=Body(False, embed=True, description='Pass confirm=True to confirm you want to modify the database.'), response=None) async

Drop all database objects.

Source code in src/prefect/server/api/admin.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@router.post("/database/drop", status_code=status.HTTP_204_NO_CONTENT)
async def drop_database(
    db: PrefectDBInterface = Depends(provide_database_interface),
    confirm: bool = Body(
        False,
        embed=True,
        description="Pass confirm=True to confirm you want to modify the database.",
    ),
    response: Response = None,
):
    """Drop all database objects."""
    if not confirm:
        response.status_code = status.HTTP_400_BAD_REQUEST
        return

    await db.drop_db()

read_settings() async

Get the current Prefect REST API settings.

Secret setting values will be obfuscated.

Source code in src/prefect/server/api/admin.py
16
17
18
19
20
21
22
23
@router.get("/settings")
async def read_settings() -> prefect.settings.Settings:
    """
    Get the current Prefect REST API settings.

    Secret setting values will be obfuscated.
    """
    return prefect.settings.get_current_settings()

read_version() async

Returns the Prefect version number

Source code in src/prefect/server/api/admin.py
26
27
28
29
@router.get("/version")
async def read_version() -> str:
    """Returns the Prefect version number"""
    return prefect.__version__