Skip to main content

NanoConf

NanoConf is a tiny, opinionated, and easy to use configuration library for Python. It is designed to be used in small to medium sized projects where a full blown configuration library is overkill.

Installation

pip install nanoconf

Usage

from nanoconf import NanoConf
# or if NanoConf if too long of a name
from nanoconf import NC

# Create a new configuration object
config = NanoConf("/path/to/config.nconf")

# Access config values using dictionary-style access
print(config["key"])

# Or use dotted attribute access (recommended for cleaner code)
print(config.key)

# Both methods work interchangeably
assert config["key"] == config.key

# Nested values support both access methods too
print(config.database.host)  # attribute access
print(config["database"]["host"])  # dictionary access

# Convert to plain Python dict (recursively)
plain_dict = config.to_dict()
# All nested NanoConf objects become regular dicts

Configuration File Format

NanoConf uses a simple configuration file format that is easy to read and write. Each File is YAML formatted and contains a single top-level dictionary. Even though the top-level must be a dictionary, you can nest dictionaries and lists as deep as you want. Each config file also must have the .nconf extension. This ensures that NanoConf will only load files that are meant to be configuration files.

key: value
test: 1
overriden: false
things:
    - thing1
    - thing2
    - thing3
top:
    v1: 1
    middle:
        v2: 2
        inner:
            v3: 3
            deep:
                v4: 4

If you have multiple config files you want to load into a single config object, you can put them all in the same directory and pass that directory to NanoConf. NanoConf will automatically place sub-files by their filename as an attribute of the parent file. The contents of that file will be accessible as you'd expect under the corresponding filename attribute.

<project root>
conf_dir
  |__ cfg1.nconf
  |__ cfg2.nconf
  |__ cfg3.nconf
# load an entire directory
proj_config = NanoConf("/path/to/conf_dir")
print(proj_config.cfg1.test)

Or you can import additional files or directories from within any config file by using the _import keyword.

# main.nconf
_import:
    - /path/to/project/more_config
key: value
test: 1
<project root>
main.nconf
more_config
  |__ subcfg1.nconf
  |__ subcfg2.nconf
  |__ subcfg3.nconf
# loading the main config file will also load the sub-configs
proj_config = NanoConf("/path/to/project/main.nconf")
print(proj_config.more_config.subcfg1.test)

Notice how the directory structure was also maintained in the attribute path. This makes it easier to find the file that a value came from.

Environment Variables

NanoConf supports environment variables either as overrides to existing values or as additions to the loaded config. Envars are evaluated on a per-file basis, so you can have different envars for different config files. The way we manage this is by having a special _envar_prefix key in the config file. Note: NanoConf will not modify the case of any environment varable name or value. It is up to you to ensure that the case is correct.

_envar_prefix: myapp
key: value
overrideme: original
export myapp_overrideme=changed
config = NanoConf("/path/to/config.nconf")
print(config.overrideme)

You can also pass complex data structures as JSON strings in environment variables.

export myapp_abc='{"a": 1, "b": 2, "c": 3}'
config = NanoConf("/path/to/config.nconf")
print(config.abc.b)

Converting to Plain Dictionaries

NanoConf objects can be recursively converted to plain Python dictionaries using the to_dict() method. This is useful for serialization, passing to libraries that expect plain dicts, or API responses.

config = NanoConf("/path/to/config.nconf")

# Convert entire config to plain dict
plain = config.to_dict()

# All nested NanoConf objects become regular dicts
assert isinstance(plain, dict)
assert not isinstance(plain, NanoConf)

# Works with deeply nested structures
if "database" in config:
    db_dict = config.database.to_dict()
    # Can now be serialized to JSON, YAML, etc.

Metadata

Release files for nanoconf 1.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 nanoconf 1.1.0
File Size Uploaded Provenance Actions
nanoconf-1.1.0.tar.gz 9.4 kB Without provenance Details for nanoconf-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nanoconf 1.1.0
File Interpreter ABI Platform Actions
nanoconf-1.1.0-py3-none-any.whl Python 3 none any Details for nanoconf-1.1.0-py3-none-any.whl

Total release size: 14.2 kB

Release files / nanoconf-1.1.0.tar.gz

Download URL nanoconf-1.1.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
46974962b776761b50996b35463fdfcd3e4262650d0aa44b69c69feb5895b4cb
BLAKE2b-256 checksum
How to use checksums
98da5c0b45b58930e9624e7d0308a9e011e76bac1f3ec7b39acc41aad86476ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / nanoconf-1.1.0-py3-none-any.whl

Download URL nanoconf-1.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3c72059ad0c7609dadb87834b8f92ba1c5fcaa6631422e68a8214a86f0a8d07
BLAKE2b-256 checksum
How to use checksums
e2a3a6d2939d1a7a3a505bbe2b3e5b047710927b6887bf3f880c5a8105ef236e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Security for nanoconf 1.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.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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