MichaelT
11/28/2025, 3:04 AMMarvin
11/28/2025, 3:04 AMMarvin
11/28/2025, 3:08 AMfrom prefect.variables import Variable
# Set values
Variable.set("api_base_url", "<https://api.example.com>")
Variable.set("db_config", {"host": "localhost", "port": 5432})
# Get values
api_base_url = Variable.get("api_base_url")
db_config = Variable.get("db_config", default={"host": "localhost", "port": 5432})
CLI examples
# Set
prefect variable set api_base_url "<https://api.example.com>"
prefect variable set db_config '{"host":"localhost","port":5432}' --overwrite
# Get
prefect variable get api_base_url
prefect variable get db_config
Notes
- Variables store JSON-serializable values and are visible in the UI (not encrypted)
- Use Secret blocks for real secrets
- You can reference Variables in deployments via Jinja, e.g. {{ prefect.variables.api_base_url }}
Docs
- Variables
- Blocks
- Secrets
If you want, share an example of how you’re using String/JSON blocks today and I can show the exact migration.