https://github.com/agu3rra/pykeys
Securely store and use your API keys
https://github.com/agu3rra/pykeys
api coding cryptography key secure token
Last synced: 5 months ago
JSON representation
Securely store and use your API keys
- Host: GitHub
- URL: https://github.com/agu3rra/pykeys
- Owner: agu3rra
- License: mit
- Created: 2018-12-14T23:55:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-26T19:28:59.000Z (over 2 years ago)
- Last Synced: 2025-10-19T11:12:55.207Z (8 months ago)
- Topics: api, coding, cryptography, key, secure, token
- Language: Python
- Homepage:
- Size: 64.5 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://snyk.io//test/github/agu3rra/pykeys?targetFile=requirements.txt)
# pykeys: Securely store and use your API keys
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.
## Use example
```Python
>>> 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:
```Python
>>> import pykeys as pk
>>> pk.view()
{
"Google API": {
"token": "gAAAAABcFPyihLHc4NuJk2SymYcmTZgGO0gHeSjEbDWy6GugrlTHJ7o0kjQ6tduHdHsSuquD0lgGlRQij02f47uYCyvWEfBE4o2j5KV5yP7t3qCADl-Ou9o="
}
}
```
PS: this is what a Fernet key looks like: `7MHyRPCy5TrVwYsKULvCMzUe5ha9-34ZaPTcw98PxyE=`
## New Dictionary encryption feature
Allows you to provide an unencrypted dictionary and get an encrypted version of its values. Only leafs will be encrypted. Example:
```Python
>>> 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"
}
}
```
## Install
```bash
$ pip install pykeys
```