Devin Dennis
07/26/2024, 3:34 AMMarvin
07/26/2024, 3:34 AMprefect-client
package with a self-hosted Prefect server on Kubernetes, you should use an API token instead of an API key, as API keys are typically for Prefect Cloud.
Here’s an overview:
1. API Token Configuration:
- You will need to obtain an API token from your self-hosted Prefect server. This token acts similarly to an API key but is used for self-hosted servers.
2. Setting up Environment:
- Ensure you set the PREFECT_API_URL
environment variable to point to your self-hosted server's API endpoint (e.g., http://<your-prefect-server-url>:4200/graphql
).
3. Client Authentication:
- When initializing the prefect-client
, you can provide the API token to authenticate the client.
Here’s a basic example of connecting to a self-hosted Prefect server using `prefect-client`:
python
import os
from prefect import Client
# Set the environment variable for the API URL
os.environ['PREFECT_API_URL'] = 'http://<your-prefect-server-url>:4200/graphql'
# Initialize the client
client = Client(api_token="your-api-token")
# Example: Fetch flow runs
flow_runs = client.graphql('''
{
flow_run {
id
name
}
}
''')
print(flow_runs)
### Resources and Documentation
- Kubernetes Credentials
- Prefect API Keys
If you encounter specific issues, make sure to explore related GitHub issues. A relevant issue to look at might be RuntimeError using prefect client from sync flow in Kubernetes.
If you need further assistance or run into specific errors, feel free to ask!Devin Dennis
07/26/2024, 3:35 AMMarvin
07/26/2024, 3:36 AM