Skip to main content

Declare a credential dependency

Save this as service.py:
Secret("SERVICE_API_KEY") only names the secret, and only workloads that list it receive the value, as an environment variable. The name lives in code, the value never does.

Provision the value from Python

Save this as configure_secrets.py beside service.py:
Run it once to store the key:
set() creates or replaces the value. In CI, the same script can call api_key.set(os.environ["SERVICE_API_KEY"]) with the value from the CI secret store. With SERVICE_URL set to your API’s URL, the function runs:
Secrets are encrypted at rest and scoped to the workspace. Code can still leak one by printing it, and the record set() returns contains the value.

Rotate or remove a secret

Rotation is the setup script with a new value, then a redeploy so new containers get it. create(value) refuses to overwrite, update(), get(), and delete() do the rest, and a secret stays stored until deleted. Image.with_secrets([...]) covers build-time credentials.

From the CLI or dashboard

The secret commands and the dashboard’s Storage page manage secrets too.