Andrew M
01/09/2025, 6:26 AMMarvin
01/09/2025, 6:26 AMSecret
block to store and retrieve sensitive information. Here's a concise overview:
1. Saving a Secret: You can create a Secret
block and save it with a specific name. Here's a basic example:
python
from prefect.blocks.system import Secret
secret = Secret(value="my-secret-value")
secret.save("my-secret", overwrite=True, _sync=True)
2. Loading a Secret: To access the secret, you can retrieve it by its name:
python
from prefect.blocks.system import Secret
loaded_secret = Secret.load("my-secret")
print(loaded_secret.value)
3. JSON Format: If your secret is in JSON format, you can store it as a string and parse it when needed. Prefect does not automatically parse JSON, but you can use Python's built-in json
library to handle it.
4. Retrieving Specific Key: If your secret contains multiple key-value pairs in JSON format, you can access specific keys by parsing the JSON string:
python
import json
from prefect.blocks.system import Secret
loaded_secret = Secret.load("my-json-secret")
secret_dict = json.loads(loaded_secret.value)
specific_value = secret_dict.get("specific_key")
print(specific_value)
For more details, you can refer to the Prefect documentation on secrets.
If you have any further questions or need additional clarification, feel free to ask.Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by