You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any settings you see in the `--help` command can be modified via a YAML config file.
3
+
4
+
By default, we try to find one in the current working dir, whose name stem is the same as the program's. Ex: program.py will search for program.yaml. This behaviour can be changed via the [run][mininterface.run] method.
5
+
6
+
!!! Tip
7
+
You do not have to re-define all the settings in the config file, you can choose a few.
8
+
9
+
## Basic example
10
+
11
+
We have this nested structure:
12
+
13
+
```python
14
+
# program.py
15
+
@dataclass
16
+
classFurtherConfig:
17
+
token: str
18
+
host: str="example.org"
19
+
20
+
@dataclass
21
+
classEnv:
22
+
further: FurtherConfig
23
+
24
+
...
25
+
m = run(Env)
26
+
print(m.env.further.host) # example.com
27
+
```
28
+
29
+
The config file being used:
30
+
31
+
```yaml
32
+
# program.yaml
33
+
further:
34
+
host: example.com
35
+
```
36
+
37
+
## Complex example
38
+
39
+
Nested container structures are supported too.
40
+
41
+
```python
42
+
from mininterface import run
43
+
@dataclass
44
+
class ComplexEnv:
45
+
a1: dict[int, str]
46
+
a2: dict[int, tuple[str, int]]
47
+
a3: dict[int, list[str]]
48
+
a4: list[int]
49
+
a5: tuple[str, int]
50
+
a6: list[int | str]
51
+
a7: list[tuple[str, float]]
52
+
53
+
m = run(ComplexEnv)
54
+
m.env
55
+
# ComplexEnv(
56
+
# a1={1: 'a'},
57
+
# a2={2: ('b', 22), 3: ('c', 33), 4: ('d', 44)},
58
+
# a3={5: ['e', 'ee', 'eee']},
59
+
# a4=[6, 7],
60
+
# a5=('h', 8),
61
+
# a6=['i', 9],
62
+
# a7=[('j', 10.0), ('k', 11), ('l', 12)])
63
+
```
64
+
65
+
The YAML file used. (Note the various YAML syntax and the automatic YAML-list to Python-tuple conversion.)
0 commit comments