File: README.md

package info (click to toggle)
python-maison 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 464 kB
  • sloc: python: 816; makefile: 17; sh: 5
file content (61 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Maison

Read configuration settings from configuration files.

## Motivation

When developing a `python` package, e.g a command-line tool, it can be helpful
to allow the user to set their own configuration options to allow them to tailor
the tool to their needs. These options are typically set in files in the root of
a user's directory that uses the tool, for example in a `pyproject.toml` or an
`{project_name}.ini` file.

`maison` aims to provide a simple and flexible way to read and validate those
configuration options so that they may be used in the package.

### Features

- Supports multiple config files and multiple config filetypes.
- Optional merging of multiple configs.
- Optional config validation with [pydantic](https://pydantic-docs.helpmanual.io/).
- Caching of config files for quick access.
- Fully tested and typed.

## Installation

```bash
pip install maison
```

## Usage

Suppose the following `pyproject.toml` lives somewhere in a user's directory:

```toml
[tool.acme]
enable_useful_option = true
```

`maison` exposes a `UserConfig` class to retrieve values from config files
like so:

```python
from maison import UserConfig

from my_useful_package import run_useful_action

config = UserConfig(package_name="acme")

if config.values["enable_useful_option"]:
    run_useful_action()
```

## Help

See the [documentation](https://maison.readthedocs.io) for more details.

## Licence

MIT

<!-- github-only -->