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.

@Lfooligan
Copy link

Lfooligan commented Apr 28, 2025

@motdotla For our containerized apps/services running on Kubernetes we use the binary library and it works great!

We currently run/deploy non-containerized Lambdas (i.e. plain ole' zip files) and I'm not actually sure how to shove the binary in there and override the handler function to use it. Do you have some documentation available we could follow?

Edit: I'm assuming the binary route would require all developers to be on the same CPU architecture - we have a mix of Apple Silicon (arm64) and legacy Intel, and I believe our Lambdas are running on x86_64.

@motdotla
Copy link
Contributor

and I'm not actually sure how to shove the binary in there and override the handler function to use it. Do you have some documentation available we could follow

I'll try to put that together this week.

I'm assuming the binary route would require all developers to be on the same CPU architecture

They can be on a mix. We publish binaries for all the major architectures: https://dotenvx.com/docs/stats

Just use the same curl -fsS https://dotenvx.sh | sh and the sh install script will take care of selecting the correct binary for the os-arch. (source: https://github.com/dotenvx/dotenvx.sh/blob/main/install.sh#L253)

@Lfooligan
Copy link

Update on my end:

I ended up experimenting with migrating one of our Lambda services to be containerized, this way I could install the binary and use it by overriding the entrypoint/cmd that Lambda invokes.

However, we use Localstack for local development and now realize I cannot test/deploy containerized lambdas locally without a Localstack Pro subscription (ECR is locked behind it and it's minimum 35$ / month / per developer).

So back to the zip approach, I suppose.

@motdotla
Copy link
Contributor

motdotla commented May 1, 2025

So back to the zip approach, I suppose.

@Lfooligan I have a solution for this now - just trying to tighten it up so it is very straightforward and documented on the docs site. I'll post here soon.

this repo was originally a placeholder with the intention to add a light python wrapper around native extensions

starting here by wrapping the binary and including a postinstall script. i'm not ready to commit to the ongoing effort of this being rewritten fully idiomatically. i do think it will be reasonably doable at a later time by doing a mix of mirroring filenames from dotenvx and automated migration to python using some ai tooling and then human managed PR reviewing, but i don't want to set up those systems yet. getting pro out of beta is my priority at the moment.

@motdotla
Copy link
Contributor

motdotla commented May 2, 2025

@Lfooligan here's documentation on using python-dotenvx with aws-lambda

https://dotenvx.com/docs/platforms/aws-lambda

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