Created
July 30, 2024 19:35
-
-
Save skymoore/1d6487b39bc8de52a7859b6410a8d9d7 to your computer and use it in GitHub Desktop.
Encrypted .env file python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import getenv | |
from io import StringIO | |
from gnupg import GPG | |
from dotenv import load_dotenv | |
# encrypted with `gpg -o .env.gpg -e --default-recipient-self .env` | |
with open("test.env.gpg", "rb") as f: | |
env_vars = GPG().decrypt_file(f) | |
if not env_vars.ok: | |
raise Exception(f"Decryption failed: {env_vars.status}") | |
load_dotenv(stream=StringIO(env_vars.data.decode())) | |
foo = getenv("FOO") | |
print(f"FOO: {foo}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment