https://prefect.io logo
Title
a

Andrew Pruchinski

07/12/2022, 6:30 PM
Hey all! Thanks in advance for your time. Looking how we can use the python prefect client to access the project name the current flow is being ran under. This is how we will determine which environment our processes are being ran under. We used to have different Tenants for the environments and used the
TenantView
class but for security purposes we now have all environments (projects) under one tenant/team. Appreciate the help!
1
a

Anna Geller

07/12/2022, 6:42 PM
Try:
prefect.context.get("project_name")
prefect.context.get("project_id")
a

Andrew Pruchinski

07/12/2022, 6:45 PM
Thank you @Anna Geller for the prompt response!
I am not able to get a return value for those methods. Running the method with other inputs such as
flow_id
and
task_id
return values though.
I don't see those options in the prefect context docs / github code either
a

Anna Geller

07/12/2022, 6:54 PM
try calling this from a Flow:
import task, Flow, prefect

@task
def some_task():
   print(prefect.context.get("project_name"))
a

Andrew Pruchinski

07/12/2022, 7:00 PM
It was returning None for me when running locally. I will try to deploy the flow and see what returns when i run it there.
It works when running the flow in the cloud! Thank you for your help @Anna Geller
🙌 1