This project has been archived by its maintainers, and is no longer receiving any updates.
PyEnv-Encrypt
GPG based env file encryptor utility.
PyEnv-Encrypt selectively encrypts and decrypts the fields of config files keeping the keys readable. For example, consider an environment variable file .env with the following values.
SOMEVAR="hello world"
ANOTHERVAR="test"
Running pyenc .env will encrypt the text fields into:
SOMEVAR="!ENC#~ hQGMA8pKDfwTzwbdAQv/c0/3Had47hxV6zuNmkBuOjv3bSGGGWzLGHVAN7ryL3tx =Y8Nr"
ANOTHERVAR="!ENC#~ hQGMA8pKDfwTzwbdAQv+JRBiVJB3rFqjONyXbBuN6pwzfHkHR43rbSIGX0o/B0zU =ljcz"
Features
- Encryption support for the following file types.
- .env
- yaml
- json
- Recursive update of all text fields.
- Automatic decision of encryption or decryption based on file contents.
Installation
You can install pyenv-encrypt directly from PyPI using pip.
pip install pyenv-encrypt
Alternatively, clone this repo and install with pip.
git clone https://github.com/akhlakm/pyenv-encrypt.git
cd pyenv-encrypt
pip install -e .
Dependencies
The gpg utility must be installed in your system. GPG comes built-in with most versions of Linux OS. For Mac, use homebrew: brew install gpg.
See the official installation instructions for more info. Run the following command to check if GPG is installed.
gpg --version
Python dependencies:
- python-dotenv
- pyyaml
Commandline Usage
After installation, use the pyenc command to encrypt or decrypt your config/env files directly from terminal.
pyenc .env
Multiple files can also be processed.
pyenc .env vault.yaml data.json
pyenc will toggle between encryption and decryption. To force encryption or decryption specify -e or -d respectively.
pyenc -e .env vault.yaml data.json
To make sure you do not commit unencrypted files, you can setup a githook for your repository. See an example pre-commit file here.
Use As A Python Module
import os
from pyenv_enc import enc
# User ID for GPG
USERID = os.environ.get("USER")
# Check if a encryption key-pair exists for the userid,
# or, create a new one.
enc.check_gpg_pubkey(USERID)
# Encrypt a value
text = "hello world"
encrypted = enc.gpg_encrypt(USERID, text)
print(encrypted)
# Decrypt a value
decrypted = enc.gpg_decrypt(encrypted)
print(decrypted)
# Recursively encrypt the string fields of a dictionary.
# This is useful to encrypt JSON, YAML, TOML files.
mydict = {
"key1": 1234,
"key2": "hello world",
"key3": ["hello", "world"],
"key4": {"foo": "bar"}
}
encrypted_dict = enc.encrypt_data(USERID, mydict)
print(encrypted_dict)
# Decrypt the dictionary.
print(enc.decrypt_data(encrypted_dict))
About
LICENSE MIT Copyright 2023 Akhlak Mahmood
Metadata
Release files for pyenv-encrypt 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyenv-encrypt-0.1.2.tar.gz | 5.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyenv_encrypt-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / pyenv-encrypt-0.1.2.tar.gz
| Download URL | pyenv-encrypt-0.1.2.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
029b782bd789d1a9d9f39969ea15dbcd0c3a4d71db2fca5863a6f5c27c22ea87
|
|
BLAKE2b-256 checksum How to use checksums |
db09e68add6aec496613dd9d01c9ed944a5fac0e9e2377e829806118af0d5cce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / pyenv_encrypt-0.1.2-py3-none-any.whl
| Download URL | pyenv_encrypt-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8e95b30a226a25411b476d520f2354bdb48c37471164f7c557645be98f4e615
|
|
BLAKE2b-256 checksum How to use checksums |
b111d9e406c981d9936dad81d995e7aacfda74eef55f694c9cff2952bd51d786
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Security for pyenv-encrypt 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.