Skip to content

Initial Implementation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jrobertson20
Copy link

Summary

This PR implements the load_dotenvx() function, which extends the existing load_dotenv() functionality to decrypt any encrypted environment variables before injecting them into os.environ.

Changes Made

  • Added load_dotenvx() function in src/dotenvx/main.py.
  • Utilized python-dotenv for existing dotenv loading logic.
  • Implemented decryption for encrypted variables.

Usage Example

from dotenvx import load_dotenvx
load_dotenvx()

@Lfooligan
Copy link

Hey I'd love to use this library - it's especially useful for AWS Lambda functions. Any word on when this PR might be merged?

@tmf-chilledornaments
Copy link

I'd love to see this merged. My org is eager to use dotenvx for Lambda

encoding = encoding)

env_keys_values = dotenv.dotenv_values('.env.keys')
dotenv_private_key = env_keys_values['DOTENV_PRIVATE_KEY']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since .env.keys should be .gitignored, can we assume os.environ['DOTENV_PRIVATE_KEY'] is already set correctly and use it?

@motdotla
Copy link
Contributor

hi everyone, this is great BUT any reason you're not just using dotenvx via the binary install? That should work for lambda @Lfooligan, right? Or use python and node together on a lambda and use the npm dotenvx?

background: this repo was originally a placeholder with the intention to add a light python wrapper around native extensions. Similar to like nokogiri does for example as a rubygem. In other words, we'd write convenient python methods for dotenvx's functions but those functions would call out to binaries and/or c-code that did the heavy lifting. This would avoid feature drift with the core dotenvx library.

@nmatte
Copy link

nmatte commented Apr 26, 2025

In support of implementing this library:
My team's workflow makes heavy use of PyCharm, which does not support dotenvx + Python out of the box.

I ended up writing my own version of this PR in order to "natively" use dotenvx without relying on the binary. It greatly improved the portability of our application in CI, local workflows, etc, while allowing us to take advantage of better secrets management through dotenvx.

Counterpoint:
PyCharm supports command wrappers, so we could have done something like this:

#/bin/bash  
PATH=~/.pyenv/shims:/usr/local/bin:$PATH  
exec /usr/local/bin/dotenvx run -q -f /home/t4/proj/example/.env.test -- python "$@"

This solution was not easy to discover, though (I couldn't find this via googling and had to ask JetBrains support).

In conclusion: it was quicker/easier to implement and use this library than go digging for a way to properly use the binary in PyCharm. So, at least for my use case, this library would have been helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants