A ConfigParser subclass that can read values stored with the keyring pypi package.
Project description
keyring_configparser
A ConfigParser subclass that can read values stored with the keyring pypi package.
Installation
pip install keyring_configparser
Usage
It is recommended to be familiar with the ConfigParser module and the keyring pypi package before use.
KeryingConfigParser
is identical to ConfigParser
except when it reads a specific token as a configuration value ("$."
by default) it uses the keyring package to resolve the value. This enables using secret values in configuration files without storing the value as plain-text within the file.
Basic Example
#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = $.
import keyring
keyring.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser
config = KeyringConfigParser()
config.read("/tmp/app.config")
config.get('section_name', 'non_secret')
> "hello world"
sec = config.get('section_name', 'secret_name')
> "secret_value"
Additional Examples
Configured Keyring Instances
A configured keyring instance can be supplied to the KeyringConfigParser
constructor. This allows using non-default backends or any other non-default keyring settings when looking up values in keyring.
For example, to use the keyrings.cryptfile
backend:
#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = $.
from keyrings.cryptfile.cryptfile import CryptFileKeyring
kr = CryptFileKeyring()
kr.keyring_key = "CRYPTFILE_PASSWORD"
kr.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser
from keyrings.cryptfile.cryptfile import CryptFileKeyring
kr = CryptFileKeyring()
kr.keyring_key = "CRYPTFILE_PASSWORD"
config = KeyringConfigParser(keyring=kr)
config.read("/tmp/app.config")
config.get('section_name', 'secret_name')
> "secret_value"
Custom Config Token
A token can be supplied to the KeyringConfigParser
constructor to override the default token "$."
. When the custom token is encountered in the configuration file the value will be resolved with keyring.
#/tmp/app.config
[section_name]
non_secret = hello world
secret_name = !~!
default_token = $.
import keyring
keyring.set_password("section_name", "secret_name", "secret_value")
from keyring_configparser import KeyringConfigParser
config = KeyringConfigParser(token="!~!")
config.read("/tmp/app.config")
config.get('section_name', 'secret_name')
> "secret_value"
config.get('section_name', 'default_token')
> "$."
Questions / Issues
Please raise any questions in the Discussions page of the repository.
Please document any issues encountered in the Issues page of the repository.
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
Built Distribution
File details
Details for the file keyring_configparser-1.0.0.tar.gz
.
File metadata
- Download URL: keyring_configparser-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44d9deff97e49e10ddac22f4500df8f15884abb00d17ce2e031038930cffa930 |
|
MD5 | 4377d25d63afeeb76c34f562b1c0a5f3 |
|
BLAKE2b-256 | 11bbf6ad97ddf0ea3f3c929b9d7112be52583850ae5d69d5a50d80a334ef4d4e |
File details
Details for the file keyring_configparser-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: keyring_configparser-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcbf580441924bb49a7eace30de8aca65a0099c9a108fb59504815a1ba87f03e |
|
MD5 | f60521840c71e51b97a5c482b98fff56 |
|
BLAKE2b-256 | 97b3ce0a019b4b064a945e475edb9f000ae18671780472bc41c2f064677175a6 |