loadfig – One-liner pyproject.toml config loader. Lightweight, simple, and VCS-aware (git, hg, svn)

What my project does

Hey all, I have created a small utility library loadfig which loads tool configuration from pyproject.toml (or from .TOOL-NAME.toml). No bells and whistles (like overriding by envvars), no third party dependencies, just this very task (added a basic root finding in git and two other VCS as I find it a very common need).

IMO this allows for a unified loading approach which adheres to the most common standards I’ve noticed in modern tooling.

GitHub repository: https://github.com/open-nudge/loadfig

Example

Assume you have the following section in your pyproject.toml file at the git-enabed root of your project:

toml [tool.mytool] name = « My Tool » version = « 1.0.0 »

You can load it simply as follows (automatically find pyproject.toml based on git directory):

« `python import loadfig

config = loadfig.config(« mytool ») config[« name »] # « My Tool » config[« version »] # « 1.0.0 » « `

Check out function signature and docs here

Target audience

Any python developer wanting to load configuration from pyproject.toml, usually tool creators.

Comparison

There are a few libraries loading toml (including builtin Python’s tomllib) and configuration loaders (e.g. dynaconf or python-dotenv), but these are usually:

Big libraries with larger scope More complex APIs (this project has one function) Having external dependencies

There are likely some smaller ones, but it is surprisingly difficult to find one being maintained and narrowly-focused (sorry for missing them in such case :()

Thanks in advance, hopefully it will be somewhat helpful (even if on a basic level).

submitted by /u/szymonmaszke to r/Python
[link] [comments]


Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *