It’s common to use Python script for device configuration, backup or automation. And to do that we usually put credentials, API Key in the script itself. It creates a whole lot of problem with sharing scripts with others; store/share it public repository. There are few options to overcome the issue like storing credentials, API Key’s in separate file and not share that file with others. We can also use “keyring” which will store the password in operating system’s credential store.
The keyring package is a library designed to let you access your operating system’s credential store. In summary, it let us to store and retrieve passwords in operating system, which allows you to avoid having a password in plaintext in the script.
keyring” is by default installed in our linux operating system. We need to install related python modules only. To check keyring installation try “
keyring --help” or “
keyring --list-backends” for list of supported backends. The common one is to use
keyrings.cryptfile - Encrypted text file storage.
pip3 install keyring
pip3 install keyrings.cryptfile
We can use
keyring set command to store the credentials and
keyring get command to retrieve it. Lets store some credential and API key
keyring set meraki MERAKI_API_VALUE
keyring set meraki ORG_ID