noconf
Key features
Flexible configuration: noconf allows you to configure your Python applications using configuration files that use Python syntax.
Multiple configuration files: noconf allows you to split your configuration across multiple files, making it easier to manage and update your configuration as your application grows.
Configuration referencing: noconf allows you to reference other parts of your configuration from within your configuration, avoiding duplication and keeping your configuration DRY (Don’t Repeat Yourself).
Component-based programming: noconf enables you to initialize classes using your configuration, making it easy to compose complex systems out of smaller, reusable components. This promotes code reuse and maintainability.
Usage
At a minimum, noconf allows us to read configuration that’s stored in files with Python syntax, where the file contains exactly one top level dictionary.
Let’s first write a very simple config file:
>>> config1_fname = folder / "config1.py"
>>> config1_fname.write_text("""
... {'key1': 'value1', 'key2': ['value2']}
... """)
40
>>> from noconf import load
>>> load(config1_fname)
{'key1': 'value1', 'key2': ['value2']}
We can also chain configuration files, that is, load multiple configuration files and merge them, where contents of the files later in the list of files to load will take precedence:
>>> config2_fname = folder / "config2.py"
>>> config2_fname.write_text("""
... {'key1': 'new', 'key3': {'__copy__': 'key2'}}
... """)
47
>>> load((config1_fname, config2_fname)) # a tuple of config files
{'key1': 'new', 'key2': ['value2'], 'key3': ['value2']}
Notice that in the above example, we also used a ‘__copy__’ feature, which allows us to refer to other parts in the configuration, and to avoid duplication.
We can also instantiate classes directly from the configuration. Let’s create a configuration file that instantiates a Python logging FileHandler class. We’re also going to configure the FileHandler with a filename that’s passed as an environment variable. We use the special environ variable in noconf to access environment variables:
>>> setenv("LOGFILE", str(folder / "mylogfile.txt"))
>>> config3_fname = folder / "config3.py"
>>> config3_fname.write_text("""
... {
... 'handlers': [
... {
... '!': 'logging.FileHandler',
... 'filename': environ['LOGFILE'],
... },
... ],
... }
... """)
135
>>> config = load(config3_fname)
>>> filehandler = config['handlers'][0]
>>> from pathlib import Path >>> Path(filehandler.baseFilename).parts[-1] 'mylogfile.txt'
Metadata
Release files for noconf 1.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 |
|---|---|---|---|---|
| noconf-1.0.tar.gz | 8.1 kB | Without provenance | Details for noconf-1.0.tar.gz |
Release files / noconf-1.0.tar.gz
| Download URL | noconf-1.0.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
138960fec7641fb854f229bc20b4bd96a017f4c15d90d9a1cf8bdf5b1954a00b
|
|
BLAKE2b-256 checksum How to use checksums |
2970eff04f7a719a2ff74bb5a1d66aa0a469878d6156fcdf78dc7cdab1ed1f89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.2
|
Security for noconf 1.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.