Name | pyenv-encrypt JSON |
Version |
0.1.2
JSON |
| download |
home_page | |
Summary | GPG based env file encryptor utility. |
upload_time | 2023-06-18 21:57:10 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.0 |
license | |
keywords |
encryption
development
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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.
```bash
SOMEVAR="hello world"
ANOTHERVAR="test"
```
Running `pyenc .env` will encrypt the text fields into:
```bash
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](https://pypi.org/project/pyenv-encrypt) using `pip`.
```sh
pip install pyenv-encrypt
```
Alternatively, clone this repo and install with `pip`.
```sh
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](https://gnupg.org/download/) for more info. Run the following command to check if GPG is installed.
```sh
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.
```sh
pyenc .env
```
Multiple files can also be processed.
```sh
pyenc .env vault.yaml data.json
```
`pyenc` will toggle between encryption and decryption. To force encryption or decryption specify `-e` or `-d` respectively.
```sh
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](pre-commit) file here.
## Use As A Python Module
```python
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
Raw data
{
"_id": null,
"home_page": "",
"name": "pyenv-encrypt",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": "",
"keywords": "encryption,development",
"author": "",
"author_email": "Akhlak Mahmood <akhlakm@gatech.edu>",
"download_url": "https://files.pythonhosted.org/packages/db/09/e68add6aec496613dd9d01c9ed944a5fac0e9e2377e829806118af0d5cce/pyenv-encrypt-0.1.2.tar.gz",
"platform": null,
"description": "# PyEnv-Encrypt\nGPG based env file encryptor utility.\n\nPyEnv-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.\n\n```bash\nSOMEVAR=\"hello world\"\nANOTHERVAR=\"test\"\n```\nRunning `pyenc .env` will encrypt the text fields into:\n\n```bash\nSOMEVAR=\"!ENC#~ hQGMA8pKDfwTzwbdAQv/c0/3Had47hxV6zuNmkBuOjv3bSGGGWzLGHVAN7ryL3tx =Y8Nr\"\nANOTHERVAR=\"!ENC#~ hQGMA8pKDfwTzwbdAQv+JRBiVJB3rFqjONyXbBuN6pwzfHkHR43rbSIGX0o/B0zU =ljcz\"\n```\n\n## Features\n- Encryption support for the following file types.\n - .env\n - yaml\n - json\n- Recursive update of all text fields.\n- Automatic decision of encryption or decryption based on file contents.\n\n## Installation\nYou can install `pyenv-encrypt` directly from [PyPI](https://pypi.org/project/pyenv-encrypt) using `pip`.\n\n```sh\npip install pyenv-encrypt\n```\n\nAlternatively, clone this repo and install with `pip`.\n```sh\ngit clone https://github.com/akhlakm/pyenv-encrypt.git\ncd pyenv-encrypt\npip install -e .\n```\n\n### Dependencies\nThe `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`.\n\nSee the official [installation instructions](https://gnupg.org/download/) for more info. Run the following command to check if GPG is installed.\n\n```sh\ngpg --version\n```\n\nPython dependencies:\n- python-dotenv\n- pyyaml\n\n\n## Commandline Usage\nAfter installation, use the `pyenc` command to encrypt or decrypt your config/env files directly from terminal.\n\n```sh\npyenc .env\n```\n\nMultiple files can also be processed.\n```sh\npyenc .env vault.yaml data.json\n```\n\n`pyenc` will toggle between encryption and decryption. To force encryption or decryption specify `-e` or `-d` respectively.\n\n```sh\npyenc -e .env vault.yaml data.json\n```\n\nTo make sure you do not commit unencrypted files, you can setup a githook for your repository.\nSee an [example pre-commit](pre-commit) file here.\n\n## Use As A Python Module\n\n```python\nimport os\nfrom pyenv_enc import enc\n\n# User ID for GPG\nUSERID = os.environ.get(\"USER\")\n\n# Check if a encryption key-pair exists for the userid,\n# or, create a new one.\nenc.check_gpg_pubkey(USERID)\n\n# Encrypt a value\ntext = \"hello world\"\nencrypted = enc.gpg_encrypt(USERID, text)\nprint(encrypted)\n\n# Decrypt a value\ndecrypted = enc.gpg_decrypt(encrypted)\nprint(decrypted)\n\n# Recursively encrypt the string fields of a dictionary.\n# This is useful to encrypt JSON, YAML, TOML files.\nmydict = {\n \"key1\": 1234,\n \"key2\": \"hello world\",\n \"key3\": [\"hello\", \"world\"],\n \"key4\": {\"foo\": \"bar\"}\n}\nencrypted_dict = enc.encrypt_data(USERID, mydict)\nprint(encrypted_dict)\n\n# Decrypt the dictionary.\nprint(enc.decrypt_data(encrypted_dict))\n```\n\n## About\nLICENSE MIT Copyright 2023 Akhlak Mahmood\n",
"bugtrack_url": null,
"license": "",
"summary": "GPG based env file encryptor utility.",
"version": "0.1.2",
"project_urls": {
"Bug Tracker": "https://github.com/akhlakm/pyenv-encrypt/issues",
"Homepage": "https://github.com/akhlakm/pyenv-encrypt"
},
"split_keywords": [
"encryption",
"development"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b111d9e406c981d9936dad81d995e7aacfda74eef55f694c9cff2952bd51d786",
"md5": "e609da489c1f1a57a12c47df23cf74fc",
"sha256": "a8e95b30a226a25411b476d520f2354bdb48c37471164f7c557645be98f4e615"
},
"downloads": -1,
"filename": "pyenv_encrypt-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e609da489c1f1a57a12c47df23cf74fc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0",
"size": 6119,
"upload_time": "2023-06-18T21:57:09",
"upload_time_iso_8601": "2023-06-18T21:57:09.373803Z",
"url": "https://files.pythonhosted.org/packages/b1/11/d9e406c981d9936dad81d995e7aacfda74eef55f694c9cff2952bd51d786/pyenv_encrypt-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db09e68add6aec496613dd9d01c9ed944a5fac0e9e2377e829806118af0d5cce",
"md5": "8a0a34bc5e49bd19466a84f960f66754",
"sha256": "029b782bd789d1a9d9f39969ea15dbcd0c3a4d71db2fca5863a6f5c27c22ea87"
},
"downloads": -1,
"filename": "pyenv-encrypt-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "8a0a34bc5e49bd19466a84f960f66754",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 5491,
"upload_time": "2023-06-18T21:57:10",
"upload_time_iso_8601": "2023-06-18T21:57:10.631579Z",
"url": "https://files.pythonhosted.org/packages/db/09/e68add6aec496613dd9d01c9ed944a5fac0e9e2377e829806118af0d5cce/pyenv-encrypt-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-18 21:57:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "akhlakm",
"github_project": "pyenv-encrypt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyenv-encrypt"
}