Riya Sinha
08/25/2025, 3:51 AMConfiguration
How to store secrets
Store secret strings
You can use the Secret block to store secret strings.
Copy
from prefect.blocks.system import Secret
secret = Secret(value="Marvin's surprise birthday party is on the 15th")
secret.save("surprise-party")
how do i set this in prefect cloud?Marvin
08/25/2025, 3:51 AMMarvin
08/25/2025, 3:55 AMprefect cloud open
or go to Prefect Cloud.
2) Navigate to Blocks.
3) Click “Create” → choose “Secret” (under the System category).
4) Give it a name (e.g., surprise-party
) and paste the secret value.
5) Save. That Secret is now available to all flows in that workspace.
Option B — Create it from Python (while logged into Cloud)
If your local profile is authenticated to Cloud and your workspace is set, this will save to Cloud:
from prefect.blocks.system import Secret
# create or update the secret in your current Cloud workspace
Secret(value="Marvin's surprise birthday party is on the 15th").save(
"surprise-party",
overwrite=True, # optional, to update if it already exists
)
To use it in a flow:
from prefect import flow
from prefect.blocks.system import Secret
@flow
def use_secret():
secret = Secret.load("surprise-party").get()
# use the secret (avoid printing secrets in logs!)
return len(secret)
if __name__ == "__main__":
use_secret()
Option C — Generate a Cloud UI creation link via CLI
- Ensure you’re logged in and workspace is set:
- prefect cloud login -k <API_KEY> -w <account>/<workspace>
- prefect cloud workspace set -w <account>/<workspace>
- List block types and find the secret slug:
- prefect block type ls
- Generate a creation link for the Secret block:
- prefect block create secret
This opens a link to create the Secret in your Cloud workspace.
Verify and manage
- List configured blocks: prefect block ls
- Delete a block if needed: prefect block delete secret/surprise-party
Notes
- Secrets are encrypted at rest in Prefect Cloud and values are redacted in the UI and logs.
- Blocks are workspace-scoped (not project-specific).
Docs
- How to store secrets: Store secrets
- CLI block commands: CLI: block