Metadata-Version: 2.4
Name: python-dotenvx
Version: 3.1.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Rust
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
License-File: LICENSE
Summary: the secure dotenv—from the creator of `dotenv`
Keywords: environment,environment variables,env,dotenv,python,dotenvx
Author-email: dotenv <mot@dotenvx.com>
License: BSD-3-Clause
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://dotenvx.com
Project-URL: Repository, https://github.com/dotenvx/python-dotenvx

[![dotenvx](https://dotenvx.com/banner.png?v2)](https://dotenvx.com)

*The secure dotenv*–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).

* Encrypt
* Commit
* Ship

[PyPI](https://pypi.org/project/python-dotenvx/) · [Quickstart](#quickstart) · [Changelog](https://github.com/dotenvx/python-dotenvx/blob/main/CHANGELOG.md)

## Quickstart

With [uv](https://docs.astral.sh/uv/getting-started/installation/) installed, create a project and add `python-dotenvx`.

```sh
uv init hello-dotenvx
cd hello-dotenvx
uv add python-dotenvx
```

In an existing pip project, install the same package with `python -m pip install python-dotenvx`.

Create these two files in the project directory.

```dotenv
# .env
HELLO=World
```

```python
# index.py
import os
from dotenvx import load_dotenv

load_dotenv()
print(f"Hello {os.environ['HELLO']}")
```

Run `uv run index.py` (or `python index.py` with pip). The script prints `Hello World`.

## Loading files

`load_dotenv()` loads values into `os.environ` and preserves existing variables. Pass `override=True` to replace them or `strict=True` to raise on loading errors. To read values into a dictionary without changing the environment, use `dotenv_values()`.

```python
from dotenvx import dotenv_values

values = dotenv_values(".env.production")
```

An explicit path takes precedence. With the default settings and no path argument, the SDK checks `DOTENV_FILE`, then `DOTENV_PATH`, then looks for files named by exported private keys (for example, `DOTENV_PRIVATE_KEY_PRODUCTION` selects `.env.production`). Otherwise it searches for `.env` from the working directory up through its parents.

## Encrypt and deploy

With the [dotenvx CLI](https://dotenvx.com/docs/install) installed, run this in the example project to encrypt the values in `.env`.

```sh
dotenvx encrypt
```

Commit the encrypted `.env` with your code. Keep the generated `.env.keys` file out of version control. In production, set `DOTENV_PRIVATE_KEY` in your deployment environment using the value from `.env.keys`.

Run the script again. The SDK decrypts `HELLO` at runtime and the script still prints `Hello World`.

&nbsp;

## Design

Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.

We chose git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world class one is right there at your fingertips.

We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.

Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging git's distribution advantages while still following the twelve-factor config – by separating the decryption key from the code (environment).

It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.

The result is a system built entirely from primitives, developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. The kicker, all this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.

[Read the whitepaper →](https://dotenvx.com/dotenvx.pdf?v=README)

&nbsp;

