https://prefect.io logo
Title
p

Prasanth Kothuri

02/27/2023, 8:33 PM
Hi All, is it possible to create workpools with Python API, if so please point to an example, thanks
s

Sahil Rangwala

02/27/2023, 10:10 PM
Hello! Yes it is possible to create workpools from the rest API with a post request
👍 1
p

Prasanth Kothuri

02/28/2023, 7:20 PM
thank you very much, that works ! although I had to use locally run open source prefect api - https://docs.prefect.io/api-ref/rest-api-reference/
code block if it helps anyone
import requests
import os

# get environment variables
env = os.environ['env']

# payload to create the work pool
payload = {
    "name": f"{env}-agent-pool",
    "description": f"Default work pool for {env} environment",
    "type": "prefect-agent",
    "base_job_template": {},
    "is_paused": False,
    "concurrency_limit": 0
}

# create the work pool
r = <http://requests.post|requests.post>('<http://localhost:4200/api/work_pools>', json=payload)
if r.status_code == 201:
    print(f"Work pool created, details: {r.text}")
else:
    print(f"Unable to create work pool, error: {r.text}")