Skip to content

Instantly share code, notes, and snippets.

@skymoore
Created July 30, 2024 19:35
Show Gist options
  • Save skymoore/1d6487b39bc8de52a7859b6410a8d9d7 to your computer and use it in GitHub Desktop.
Save skymoore/1d6487b39bc8de52a7859b6410a8d9d7 to your computer and use it in GitHub Desktop.
Encrypted .env file python
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