<@ULVA73B9P> can you give me an example of way to ...
# ask-marvin
l
@Marvin can you give me an example of way to set the defaul work pool concurrency limit using python sdk?
m
thought for 240.9 seconds
Here’s a concise example of setting a work pool’s default concurrency limit with the Python SDK (Prefect 3.x). Async (using get_client):
Copy code
from prefect.client.orchestration import get_client
from prefect.client.schemas.actions import WorkPoolUpdate

async def set_pool_concurrency_limit(pool_name: str, limit: int):
    async with get_client() as client:
        # Update an existing pool’s default concurrency limit
        await client.update_work_pool(pool_name, WorkPoolUpdate(concurrency_limit=limit))
Sync (using SyncPrefectClient):
Copy code
from prefect.client.orchestration import SyncPrefectClient
from prefect.client.schemas.actions import WorkPoolUpdate

with SyncPrefectClient() as client:
    client.update_work_pool("my-pool", WorkPoolUpdate(concurrency_limit=10))
Set at creation time:
Copy code
from prefect.client.orchestration import SyncPrefectClient
from prefect.client.schemas.actions import WorkPoolCreate

with SyncPrefectClient() as client:
    client.create_work_pool(
        WorkPoolCreate(
            name="my-pool",
            type="process",          # e.g., "process", "docker", "kubernetes", etc.
            concurrency_limit=10,
        )
    )
Notes: - This sets the pool-level “default” concurrency. If you also use work queues, those can have their own concurrency limits via
WorkQueueUpdate
. - If you want to remove/unlimit the pool’s concurrency later, update the pool with an unlimited value (typically None/unset). If you want help with that exact snippet for your version, let me know your Prefect version and I’ll tailor it. Related docs: - CLI reference: work-pool (shows the corresponding
--concurrency-limit
option)