Krystal
05/24/2024, 3:41 PMMarvin
05/24/2024, 3:41 PMPREFECT_API_URL
environment variable. Here's how you can do it:
### Environment Configuration
1. For Prefect Cloud:
sh
export PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/[ACCOUNT-ID]/workspaces/[WORKSPACE-ID]>"
2. For a Local Prefect Server:
sh
export PREFECT_API_URL="<http://127.0.0.1:4200/api>"
### Accessing in Python
You can retrieve the API URL using Python's os
module:
python
import os
# Get the PREFECT_API_URL from environment variables
api_url = os.getenv("PREFECT_API_URL")
print(api_url)
### Example Configuration
Here's a complete example including setting the environment variable and retrieving it in a Python script:
sh
# Set the Prefect API URL (example for Prefect Cloud)
export PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/your-account-id/workspaces/your-workspace-id>"
# Python script
import os
def get_prefect_api_url():
api_url = os.getenv("PREFECT_API_URL")
if not api_url:
raise ValueError("Prefect API URL is not set in the environment variables")
return api_url
if __name__ == "__main__":
print(get_prefect_api_url())
### Documentation
For more details, you can refer to the Prefect settings documentation.
This should help you get the Prefect API URL in your Python code effectively.Nate
05/24/2024, 5:23 PM» python -c "from prefect.settings import get_current_settings; print(get_current_settings().PREFECT_API_URL)"
<https://api.prefect.cloud/api/accounts/xxx/workspaces/xxx>