Skip to main content

Build declarative schemas for multi-file configuration directories using Python dataclasses, with dict-based read and write.

Project description

dirconf

PyPI version Python versions License CI Docs

dirconf is a Python tool for declaratively specifying configuration directory structures, and constructing Python dict representations of their contents.

For full user documentation and examples please visit https://jmarshrossney.github.io/dirconf/.

Motivations

I wrote this because I sometimes have to work with quite old scientific models that require various configuration files and data inputs in various formats to be present in various locations. I was (and remain) concerned about how easy it can be to misconfigure certain models without realising, and how common workflows compromise reproducibility.

dirconf helps by

  1. Allowing the user to describe the structure of a directory representing a valid configuration using Python dataclasses, and validate real directories against this description.

  2. Providing a scaffold for defining consistent read/write mechanisms through which complex, distributed configurations in legacy formats can be mapped to Python dicts.

The ability to represent configurations as dicts is very useful indeed. With no extra effort, we can:

  • Validate configurations using excellent tools such as JSON Schema and Pydantic.
  • Generate new configurations and metadata programmatically, as opposed to copying and editing files by hand or writing shell scripts.

Installation

dirconf is a Python package and thus can be installed using pip, or tools such as uv and poetry that wrap around pip.

uv add dirconf

or

pip install dirconf

Currently Python versions equal to or above 3.12 are supported.

Overview of usage

There are two essential steps for adapting dirconf to a specific use-case.

  1. Define handlers satisfying the Handler protocol for each of the paths (files and directories) present in your configuration.
  2. Define the structure of a valid configuration in terms of its paths and their respective handlers, by subclassing the DirConfig class. This is most easily done using the make_dirconfig function.

The custom DirConfig subclass can then be used to

  1. Read a configuration from the filesystem into a Python dict.
  2. Write a configuration dict to the filesystem.

These steps are most easily understood through examples: see the docs. All examples are based on self-contained marimo notebooks, which can be found in the examples directory.

Philosophy

dirconf contains ~700 lines of code (including docstrings) and has no dependencies beyond the Standard Library.

This is by design. I have no intention of developing dirconf into a more sophisticated tool than it already is. The aim is that is works seamlessly alongside other tools and packages for parsing and validation, without ever getting in the way or creating conflicts.

With that out of the way, please feel free to raise an issue or make a pull request to suggest a change or feature.

See CONTRIBUTING.md for full details.

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

dirconf-0.5.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

dirconf-0.5.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file dirconf-0.5.1.tar.gz.

File metadata

  • Download URL: dirconf-0.5.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","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}

File hashes

Hashes for dirconf-0.5.1.tar.gz
Algorithm Hash digest
SHA256 863d05ba0bc35403f18c95551416f022cfb657d9a8a72c79d29e8c97459918f0
MD5 4fb6a3f5ed8fc0465b083e947a7c3610
BLAKE2b-256 bd18f628701dcfe786579e035abe840fe0659cd4b25c0aa22b0df5d35e350a64

See more details on using hashes here.

File details

Details for the file dirconf-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: dirconf-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.10 {"installer":{"name":"uv","version":"0.11.10","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}

File hashes

Hashes for dirconf-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f26d3da7169fbdcd131c6242d62c86d0e1c6464cd56ee34f44e361dfc28af8e4
MD5 cf0e7ec921f1382ebfbc28fa2b1449fa
BLAKE2b-256 3f5a21f5e8e97040aeada9f1c2d6b936be1c394562d3064222630e9e462bb9fe

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