Skip to main content

PyPI - Downloads

Comprehensive Configuration

A simple configuration library that lets you create a pydantic-like model for your configuration.

Installation

pip install comprehensiveconfig

Features

  • Supports static type checking
  • toml writer
  • json writer
  • Number fields
  • Text fields (with regex filtering)
  • File/Folder path fields (PathField)
    • Ability to change validator (unix/linux, windows, agnostic, and current system)
    • Validate for only files, folder, or accept both.
  • List fields
  • Table fields
  • TableSpec (Model) fields
  • Sections
  • Include doc comments in Section
  • auto loading
  • initialize default config (with auto loader)
  • [N/a] yaml writer (This will likely be moved to a different library as an extension of comprehensiveconfig!)
  • Tests targetting mypy and other static type checkers to ensure EVERYTHING looks good across IDE's
  • section list (via a Table field)
  • Field type unions (overwriting normal union syntax)
  • per attribute doc comments (inline and noninline)
  • enum support (Via spec.ConfigEnum and python's enum.Enum)
  • fully supported string escapes

Example (Python)

# example.py
from comprehensiveconfig import ConfigSpec
from comprehensiveconfig.spec import Section, Integer, Float, Text, List
from comprehensiveconfig.toml import TomlWriter

class MyConfigSpec(ConfigSpec,
                   default_file="myconfig.toml",
                   writer=TomlWriter,
                   create_file=True):
    class MySection(Section, name="My_Section"):
        some_field = Integer(10)
        other_field = Text("Some Default Text")

        class SubSection(Section):
            '''An example Sub Section'''
            x = Integer(10)

    class Credentials(Section):
        '''Example credentials section'''
        email = Text("example@email.com", regex=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")
        password = Text("MyPassword")

    some_field = Float(6.9)
    list_of_stuff = List(["12", "13", "14"], inner_type=Text())


# Accessing values from globally loaded config (if one exists, otherwise it accesses the actual Field class)
print(MyConfigSpec.some_field)
print(MyConfigSpec.MySection.other_field)

# Another way to open configuration
second_config = MyConfigSpec.load("another_config.toml", TomlWriter)

Example (toml output)

some_field = 6.9
list_of_stuff = ["12", "13", "14"]

[My_Section]
some_field = 10
other_field = "Some Default Text"

[My_Section.SubSection]
# An example Sub Section
x = 10

[Credentials]
# Example credentials section
email = "example@email.com"
password = "MyPassword"

Autoloaded Configuration Classes (Typing Issues in Mypy)

There is one particular pitfall I have yet to develop around. Mypy is missing a few essential checks that improve type checking on autoloaded configuration classes. For the time being, I recommend avoiding using mypy with this project until class-decorator annotations work (something that hasn't worked since 2017) or until I can manage to create a mypy plugin to work around the issue. Pyright doesn't seem to believe anything is wrong. Pyright is the default typechecker used in vscode's pylance extension.

If type checking issues occur on your autoloaded config classes, try using this temporary decorator as a fix:

@autoloaded # makes your type checker think `MyConfig` is an instance of itself. (or at least it *should* do that.)
class MyConfig(ConfigSpec, default_file="test.toml", writer=TomlWriter, create_file=True):
    ... # impl here

The other option is to just manually load your configuration.

class MyConfig(ConfigSpec, auto_load=False):
    ...

config = MyConfig.load("test.toml", TomlWriter, create_file=True) # load and/or create our config file

Release files for comprehensiveconfig 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for comprehensiveconfig 1.2.1
File Size Uploaded
comprehensiveconfig-1.2.1.tar.gz 24.3 kB Details

Built distribution (wheel)

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

Total release size: 46.8 kB

Release files / comprehensiveconfig-1.2.1.tar.gz

Download URL comprehensiveconfig-1.2.1.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
03e59d3dfca6990a0a4d584322cbbc9789995b72b7220b81106d39a1ea94ad90
BLAKE2b-256 checksum
How to use checksums
ac58cd8bdf9ce8818b99e6753e732e029f26cb49feb82c99503e23951176545a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / comprehensiveconfig-1.2.1-py3-none-any.whl

Download URL comprehensiveconfig-1.2.1-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
136f5371a647cee5f48bffbc863a39b639e8ed01a63ea2ca600215e0f0377449
BLAKE2b-256 checksum
How to use checksums
7d09fb42a5f1b99a41c07439a96a558191286d80cddd34cb6fca2777199b1829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.1

2 release files

1.0.0

2 release files

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