<@ULVA73B9P> how to use basic auth for the client ...
# ask-marvin
r
@Marvin how to use basic auth for the client in sdk?
m
thought for 34.8 seconds
Based on the research, here's how to set up basic authentication for the Prefect client in the SDK: 1. You can set the basic authentication credentials using the
api.auth_string
setting. The format is
username:password
. Here are a few ways to configure it:
Copy code
python
# Method 1: Using PrefectClient directly
from prefect.client.orchestration import PrefectClient

client = PrefectClient(api_auth_string="admin:mypassword")

# Method 2: Using settings
from prefect.settings import Setting
from prefect.context import Settings

settings = Settings(
    api=Settings(
        auth_string="admin:mypassword"
    )
)
You can also set this via environment variable:
Copy code
bash
export PREFECT_API_AUTH_STRING="admin:mypassword"
Important Security Notes: 1. Store these credentials securely, preferably in environment variables or secure secret management systems 2. When using a self-hosted Prefect server with basic auth enabled, all client processes (including workers) that need to communicate with the Prefect API will need this authentication configured 3. The Prefect UI will prompt for these credentials upon first load For more detailed information about security settings, you can refer to the Prefect security settings documentation. Would you like me to provide more specific examples for your use case or explain any part of this in more detail?