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.
Metadata
Release files for keyring-configparser 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| keyring_configparser-1.0.0.tar.gz | 7.5 kB | Without provenance | Details for keyring_configparser-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| keyring_configparser-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for keyring_configparser-1.0.0-py3-none-any.whl |
Total release size: 12.5 kB
Release files / keyring_configparser-1.0.0.tar.gz
| Download URL | keyring_configparser-1.0.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
44d9deff97e49e10ddac22f4500df8f15884abb00d17ce2e031038930cffa930
|
|
BLAKE2b-256 checksum How to use checksums |
11bbf6ad97ddf0ea3f3c929b9d7112be52583850ae5d69d5a50d80a334ef4d4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Release files / keyring_configparser-1.0.0-py3-none-any.whl
| Download URL | keyring_configparser-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fcbf580441924bb49a7eace30de8aca65a0099c9a108fb59504815a1ba87f03e
|
|
BLAKE2b-256 checksum How to use checksums |
97b3ce0a019b4b064a945e475edb9f000ae18671780472bc41c2f064677175a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.2
|
Security for keyring-configparser 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.