The purpose of this package is to offer a secure way to store and retrieve API tokens when interacting with such interfaces in Python code. Once you register a key in the vault you can reuse it in any of your Python programs. All keys are encrypted and stored in the library's install path.
It uses Python's criptography
library to encrypt all token values that are stored in the local vault.
>>> import pykeys as pk
>>> app='Google API'
>>> secrets={'token':'mysupersecrettoken'}
>>> pk.add(app,secrets)
>>> pk.view()
{
"Google API": {
"token": "gAAAAABcFPOMUOyFhnchp6u6j8v0J7lzcY_0ZtCdgrToHpv2Vtsr44Lb9BRDfoMWuNXQNbnBiXIBxYsHjXRAkyuf9VJYZbR_E7tY1AeKjpYglpk0NSC_NN0="
}
}
>>> pk.get('Google API', 'token')
'mysupersecrettoken'
Subsequent code executions can use the previously saved tokens:
>>> import pykeys as pk
>>> pk.view()
{
"Google API": {
"token": "gAAAAABcFPyihLHc4NuJk2SymYcmTZgGO0gHeSjEbDWy6GugrlTHJ7o0kjQ6tduHdHsSuquD0lgGlRQij02f47uYCyvWEfBE4o2j5KV5yP7t3qCADl-Ou9o="
}
}
PS: this is what a Fernet key looks like: 7MHyRPCy5TrVwYsKULvCMzUe5ha9-34ZaPTcw98PxyE=
Allows you to provide an unencrypted dictionary and get an encrypted version of its values. Only leafs will be encrypted. Example:
>>> secrets = {
"postgresql":{
"names": {
"db":"sampledb",
"user":"admin"
},
"password":"supersecret"
}
}
>>> pk.dict_encrypt(secrets)
>>> secrets
{
"postgresql":{
"names": {
"db":"gAAAAABcFPyihLHc4NuJk2SymYcmTZgdasdsaGugrlTHJ7o0kjQ6tduHdHsSuquD0lgGlRQij02f47uYCyvWEfBE4o2j5KV5yP7t3qCADl-Ou9o=",
"user":"gAAAAABcFPyihLHc4NuJk2SymYcmTZgGO0gHeSjEbDWy6GugrlTHJ7o0gsdfg45SuquD0lgGlRQij02f47uYCyvWEfBE4o2j5KV5yP7t3qCADl-Ou9o="
},
"password":"gAAAAABcFPyihLHc4NuJk2SymYcmTZgGO0gHeSjEbDWy6GugrlTHdasdo0kjQ6tduHdHsSuquD0lgGlRQij02f47uYCyvWEfBE4o2j5KV5yP7t3qCADl-Ou9o="
}
}
>>> pk.dict_decrypt(secrets)
{
"postgresql":{
"names": {
"db":"sampledb",
"user":"admin"
}
"password":"supersecret"
}
}
$ pip install pykeys