Skip to main content

Key features

  1. Flexible configuration: noconf allows you to configure your Python applications using configuration files that use Python syntax.

  2. 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.

  3. 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).

  4. 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)

Source distribution for noconf 1.0
File Size Uploaded
noconf-1.0.tar.gz 8.1 kB Details

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

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page