snekcfg is a minimalist wrapper over
configparser that offers
a more streamlined user experience.
Expected options and their types are predefined to prevent errors and minimize repetitive logic within your codebase. This allows for simple, direct access to your configuration within your program without worrying about typos or type conversion.
example.py
import snekcfg
cfg = snekcfg.Config('example.cfg')
sct = cfg.section('server')
# the default value is used to automatically type as an int
sct.define('port', 8080)
# or, you can be explicit
sct.define('host', default='127.0.0.1', type=str)
# some common types like set[str] are already built-in,
# but here is an example of adding a codec for a new type.
# *type* can be a type object, or just a string like 'str_set'
cfg.register_type(
type=set[str],
encode=lambda v: ','.join(v),
decode=lambda v: set(v.split(',')))
# sections can be accessed using dot notation (one level deep)
cfg.define('users.whitelist', default=set(), type=set[str])
# update values with dot notation
users = {'graham', 'john', 'terryg', 'eric', 'terryj', 'michael'}
cfg['users.whitelist'].update(users)
# or through the section
cfg.section('server')['port'] = 1337
# write to 'example.cfg'
cfg.write()
# let's tweak the config file externally
with open('example.cfg', 'r+') as f:
s = f.read()
f.seek(0)
f.write(s.replace('1337', '1234'))
# read from 'example.cfg'
cfg.read()
# types are preserved
assert cfg['server.port'] == 1234
assert cfg['users.whitelist'] == users, users
example.cfg
[server]
host = 127.0.0.1
port = 1337
[users]
whitelist = eric,graham,michael,john,terryg,terryj
Metadata
Release files for snekcfg 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snekcfg-0.1.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for snekcfg-0.1.1-py2.py3-none-any.whl |
Release files / snekcfg-0.1.1-py2.py3-none-any.whl
| Download URL | snekcfg-0.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b60b00805b912e4e86f2376d7f9cd26701f26fdbffb0df2ebd47942822752149
|
|
BLAKE2b-256 checksum How to use checksums |
5dec21cd3a9a929b6e2bea4292570e4a3fc2ae36dbe1fb77da3380803a5be5c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for snekcfg 0.1.1
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.