https://github.com/zachcheung/agenv
A simple Python package for securely loading environment variables from age encrypted file.
https://github.com/zachcheung/agenv
age env python
Last synced: 7 months ago
JSON representation
A simple Python package for securely loading environment variables from age encrypted file.
- Host: GitHub
- URL: https://github.com/zachcheung/agenv
- Owner: zachcheung
- License: mit
- Created: 2025-02-06T00:34:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-06T00:37:56.000Z (over 1 year ago)
- Last Synced: 2025-02-06T01:03:16.384Z (over 1 year ago)
- Topics: age, env, python
- Language: Python
- Homepage: https://pypi.org/project/agenv/
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# agenv
A simple Python package for securely loading environment variables from age encrypted file.
## Installation
### Basic Installation (Decryption Only)
If you only need to decrypt files at runtime:
```sh
pip install agenv
```
### With dotenv Support (Load Encrypted Environment Variables)
If you need to load encrypted environment variables automatically:
```sh
pip install agenv[dotenv]
```
> [!NOTE]
> [age](https://github.com/FiloSottile/age#installation) must be installed separately, as there is no native Python implementation of age.
## Usage
#### Loading Environment Variables
```python
from agenv import load_age_env
# Decrypts and loads environment variables from a .env.age file
load_age_env(".env.age")
```
#### Decrypting and Loading YAML Data
```python
import yaml
from agenv import decrypt
# Decrypts the .age encrypted file and loads the content as a YAML object
yaml_str = decrypt("database.yml.age")
data = yaml.safe_load(yaml_str)
print(data)
```
### Identity Key Selection Order
agenv determines the age identity key in the following order:
1. The `identity` parameter provided to `load_age_env()`
2. The `AGE_SECRET_KEY` environment variable
3. The `AGE_SECRET_KEY_FILE` environment variable (path to key file)
4. The default key file: `$HOME/.age/age.key`
If no valid identity is found, decryption will fail.
## License
[MIT](LICENSE)