Skip to main content

The blazing-fast, tiny opinionated config loader.

Project description

PicoConf

PicoConf is a tiny, opinionated, lightning fast, 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.

This project is a Rust port of my NanoConf project, so inherits the usage patterns from that. However, it is roughtly 40x faster!

Installation

uv pip install picoconf

Usage

from picoconf import PicoConf
# or if PicoConf if too long of a name
from picoconf import PC

# Create a new configuration object
config = PicoConf("/path/to/config.pconf")

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

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

# Both methods work interchangeably
assert config["some_key"] == config.some_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 PicoConf objects become regular dicts

Configuration File Format

PicoConf 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 .pconf extension. This ensures that PicoConf 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 PicoConf. PicoConf 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.pconf
  |__ cfg2.pconf
  |__ cfg3.pconf
# load an entire directory
proj_config = PicoConf("/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.pconf
_import:
    - /path/to/project/more_config
key: value
test: 1
<project root>
main.pconf
more_config
  |__ subcfg1.pconf
  |__ subcfg2.pconf
  |__ subcfg3.pconf
# loading the main config file will also load the sub-configs
proj_config = PicoConf("/path/to/project/main.pconf")
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

PicoConf 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: Environment variable names are matched case-insensitively and normalized to lowercase for cross-platform compatibility. Both the _envar_prefix and the config keys extracted from environment variables are converted to lowercase to ensure consistent behavior across all platforms (Windows treats env vars as case-insensitive).

_envar_prefix: myapp
key: value
overrideme: original
export myapp_overrideme=changed
config = PicoConf("/path/to/config.pconf")
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 = PicoConf("/path/to/config.pconf")
print(config.abc.b)

Converting to Plain Dictionaries

PicoConf 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 = PicoConf("/path/to/config.pconf")

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

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

picoconf-0.2.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

picoconf-0.2.0-cp311-abi3-win_amd64.whl (299.9 kB view details)

Uploaded CPython 3.11+Windows x86-64

picoconf-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (438.2 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

picoconf-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (425.8 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

picoconf-0.2.0-cp311-abi3-macosx_11_0_arm64.whl (390.4 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

picoconf-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl (404.3 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file picoconf-0.2.0.tar.gz.

File metadata

  • Download URL: picoconf-0.2.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for picoconf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 41a2bbd4e1399f29567d6563975e20a07a82cdaae0de2d219424341dc92c0d9b
MD5 35822ecb036bbecd51cd0a0f992a343b
BLAKE2b-256 6b81b1c585e2b7fa1944dd8a8699f4279f9a6de43e45644824fdfaa15f527c76

See more details on using hashes here.

File details

Details for the file picoconf-0.2.0-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: picoconf-0.2.0-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 299.9 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.0

File hashes

Hashes for picoconf-0.2.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5ae93c33e03f7091f341fccd4d9e9a03a30d13d19b3952254677cc2542bed1cb
MD5 9ffcbcc4b1ca6d1eb388770d2358870e
BLAKE2b-256 7f6967e20f791b1e95f9e205f1689cd838b39bb9fd0fa9a586bda10375114a7f

See more details on using hashes here.

File details

Details for the file picoconf-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for picoconf-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d373005cdbc900ef7fd79efdfceada8d2f94e83a6029d4ea0fc32884696221b
MD5 ca71354bf35b7d56576b1d4a29c1bf10
BLAKE2b-256 9991cdba01a8705a6c33e3ce93dc5c78c42fbd6031fe5b1044eb228b199c2237

See more details on using hashes here.

File details

Details for the file picoconf-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for picoconf-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e573af728a53c78662fe6fbb1af6d3520cb24d914914b13a849c51f5a0e14a6c
MD5 ae218b72a18069816a1f21cb29c575f5
BLAKE2b-256 c3e7db2b1155a4147cd49ee6ec4ba29a3a0c1c12e6a89efe8b3fa1af030d2acd

See more details on using hashes here.

File details

Details for the file picoconf-0.2.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for picoconf-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f8e47b16f1e09a32ef84b4e876f8214336c54538e63903eb8daadff2527669c
MD5 2ae1585ee8b7f4b5183a66fc1b5cf1f7
BLAKE2b-256 23348d35d71db0e4eee621586145e35a28d4d070eb873554a9dad14e08174b27

See more details on using hashes here.

File details

Details for the file picoconf-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for picoconf-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7797837d0ef53df10cd088090be902511311086c0a8a4e20aba371af4ba61441
MD5 76f7bb53c6e0f00e28b895012b2414b8
BLAKE2b-256 1eb217f00e8b5643355f0643b1ee5b33b79b59e66f65183d9a282f8284423300

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page