Skip to main content

A python module to store, encrypt and decrypt type hinted strings in a python file

Project description

ETYPES

This package allows for encrypting secret strings in python files in a human readable way using type hints. it also supports dynamic loading of python files which contain encrypted strings, providing the password via an environment variable

Installation

$ pip install etypes

or

$ poetry add etypes

Example

Define a variable with the type hint DecryptedSecret

from etypes import DecryptedSecret
SECRET_VAR: DecryptedSecret = "some-secret-value"

encrypt

To encrypt the file, run the following

$ etypes encrypt -p PASSWORD ./path/to/python_file.py

or

$ etypes encrypt -pf ./path/to/password_file ./path/to/python_file.py

results in

from etypes import EncryptedSecret
SECRET_VAR: EncryptedSecret = "gAAAAABmT9yA6HQOXF4BM6gvUG_ryKqrXK9BEgRY2W4lNQvDNBVbiCEOz50-viDLEMXA71upgcGgRbqvC-IAltbjE8w5MbSooJN5EV-8sVe1q3LndfBNzEg="

decrypt

To decrypt the file run

$ etypes decrypt -p PASSWORD ./path/to/python_file.py

or

$ etypes v -pf ./path/to/password_file ./path/to/python_file.py

Autoloader

To import this python file in your project and have it decrypt itself seamlessly when accessed.

You must import the AutoLoader and configure it to accept a password via a environment variable or to look for a file at a path.

# app/settings/secrets.py

from etypes import EncryptedSecret, AutoLoader
SECRET_VAR: EncryptedSecret = "gAAAAABmT9yA6HQOXF4BM6gvUG_ryKqrXK9BEgRY2W4lNQvDNBVbiCEOz50-viDLEMXA71upgcGgRbqvC-IAltbjE8w5MbSooJN5EV-8sVe1q3LndfBNzEg="

AutoLoader(locals(), password_var_name="SOME_ENV_VAR_WHICH_CONTAINS_PASSWORD")
# or
AutoLoader(locals(), password_file="/path/to/your/secret_file")

import your settings/secrets file normally.

# app/main.py

from .settings import secrets
print(secrets.SECRET_VAR)

Run your application providing the password declaring in your AutoLoader $ SOME_ENV_VAR_WHICH_CONTAINS_PASSWORD="PASSWORD" ./main.py

TODO: Add support for the environs package

Changelog

1.0.4

  • fix ansible implementation and tests

1.0.2, 1.0.3

  • doc updates

1.0.1 breaking changes but still initial 1.0 release

  • rename hits EncryptedSecret and DecryptedSecret

1.0 release

  • basic functionality

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

etypes-1.0.4.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

etypes-1.0.4-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file etypes-1.0.4.tar.gz.

File metadata

  • Download URL: etypes-1.0.4.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.14 Linux/6.7.12-orbstack-00201-g2ddb8f197a46

File hashes

Hashes for etypes-1.0.4.tar.gz
Algorithm Hash digest
SHA256 2e65439ac2b169d2c24f9af80df7055625399fd96afba03c11690a110e24943d
MD5 dc2486fb9bef41580fdbbcc3f042940f
BLAKE2b-256 055958c590f874dff18dfd098c8b3c70467f8075182746b9a256dabd2165b1ed

See more details on using hashes here.

File details

Details for the file etypes-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: etypes-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.14 Linux/6.7.12-orbstack-00201-g2ddb8f197a46

File hashes

Hashes for etypes-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d01dbbcaf32e74f29ff5a0496797300602ff3482c340a590e0655574041feaa6
MD5 c8cc6d4756e1bbaf4a9b83d1d4636461
BLAKE2b-256 2f54e8656c5f11bd2d77d0d7699d7125f1ac445e0091c26a8c85438a7f34bab9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page