utility tool that load secret information safely.
Project description
Welcome to pysecret Documentation
pysecret is a library to ease your life dealing with secret information.
For example, if you have a database connection information, so you can’t include it in your source code, but you want to easily and securely access it, then pysecret is the library for you. It provides several options out of the box:
Features:
access secret in environment variable from commandline, shell scripts, or Python.
access secret in json file from Python.
use AWS Key Management Service or AWS Secret Manager to access your secret info.
For large file or binary data encryption, I highly recommend you to use AWS Key Management Service and AWS Secret Manager to fetch your encryption key, then use windtalker library to encrypt it.
Load Data From Environment
The idea is: put your secret information in ~/.bashrc_pysecret file.
# content of ~/.bashrc_pysecret file
export DB_SECRET_MY_DB_PASSWORD="mypassword"
...
And put source ~/.bashrc_pysecret into your ~/.bashrc / ~/.bash_profile / .zshrc …
Whenever you need your secret info:
Your interactive command line interface gives you easy access to those secrets.
You can put source ~/.bashrc_pysecret in your CI / CD scripts.
pysecret allows you to load secret value in python code. By doing this:
>>> from pysecret import EnvSecret
>>> env = EnvSecret()
>>> env.load_pysecret_script()
>>> env.get("DB_SECRET_MY_DB_PASSWORD")
mypassword
You can write your secret to ~/.bashrc_pysecret file in a pythonic way:
from pysecret import EnvSecret
env = EnvSecret()
# will create ~/.bashrc_pysecret file if not exists
# will update ~/.bashrc_pysecret file too
# if you don't want to update ~/.bashrc_pysecret file, just set .set(..., temp=True)
env.set("DB_SECRET_MYDB_HOST", "123.456.789.000")
env.set("DB_SECRET_MYDB_USERNAME", "username")
env.set("DB_SECRET_MYDB_PASSWORD", "password")
Load Data From Json File
The idea is, put your secret info in a json file and load info from it. You can create it manually by your own, or do it in pythonic way:
from pysecret import JsonSecret, get_home_path
SECRET_FILE = get_home_path(".pysecret.json")
js = JsonSecret.new(secret_file=SECRET_FILE)
# construct / update secret json file
js.set("mydb.host": "123.456.789.000")
js.set("mydb.username": "username")
js.set("mydb.password": "password")
or you can just create $HOME/.pysecret.json includes:
{
"mydb": {
"host": "123.456.789.000",
"username": "username",
"password": "password
}
}
Load secret safely:
host = js.get("mydb.host")
username = js.get("mydb.username")
password = js.get("mydb.password")
AWS Key Management Service and Secret Manager Integration
Create a encryption key in AWS KMS, then encrypt your secret info with the key in AWS Secret Manger. Access it is easy with pysecret.
Suppose you defined a “secret” called “my-secret” in AWS Secret Manger:
username: “myusername”
password: “mypassword”
>>> from pysecret import AWSSecret
>>> aws_profile = "my_aws_profile"
>>> aws = AWSSecret(profile_name=aws_profile)
>>> aws.get_secret_value(secret_id="my-secret", key="password")
mypassword
Install
pysecret is released on PyPI, so all you need is:
$ pip install pysecret
To upgrade to latest version:
$ pip install --upgrade pysecret
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pysecret-0.0.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3a4e7aa950e6bcdad8a277d0f3c907d17b95423c744b25d4bdcf53cbf55e4e |
|
MD5 | 8e210b19190eacca888bc2dae8cc25ae |
|
BLAKE2b-256 | cd9f8a79d77ff971d7a93b19b4749470d18ccfd48d32b5796ed20600aa5309f9 |