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
@@ -39,38 +38,43 @@ Create YAML configuration files for your project:
39
38
40
39
```yaml
41
40
# default.config.yaml - this file usually goes to version control system
42
-
database:
43
-
host: localhost
44
-
port: 5432
45
-
username: postgres
46
-
password: postgres
41
+
database:
42
+
host: localhost
43
+
port: 5432
44
+
username: postgres
45
+
password: postgres
47
46
48
47
redis:
49
-
host: localhost
50
-
port: 6379
48
+
host: localhost
49
+
port: 6379
51
50
```
52
51
53
52
```yaml
54
53
# config.yaml - this file for production usage
55
-
database:
56
-
username: username
57
-
password: password
54
+
database:
55
+
username: username
56
+
password: password
58
57
```
59
58
60
59
Import configuration files in your Python code with `pyya`:
61
60
62
61
```python
63
62
import json
64
63
65
-
from pyya import init_config
64
+
from pyya import init_config, logger
65
+
66
+
logger.setLevel(logging.INFO)
66
67
67
68
config = init_config(
68
-
'config.yaml', 'default.config.yaml',
69
+
'config.yaml', 'default.config.yaml',
69
70
merge_configs = True,
70
-
sections_ignored_on_merge = ['redis'], # do not include redis on your config
71
+
sections_ignored_on_merge = ['redis'], # do not include redis in your config
71
72
convert_keys_to_snake_case = False,
72
73
add_underscore_prefix_to_keywords = False
73
-
raise_error_non_identifiers = False)
74
+
raise_error_non_identifiers = False,
75
+
validate_data_types = True,
76
+
allow_extra_sections = True,
77
+
)
74
78
print(json.dumps(config))
75
79
76
80
# Output:
@@ -82,31 +86,45 @@ As you can see, `pyya` automatically merges default config file with production
82
86
83
87
Under the hood `pyya` uses [PyYAML](https://pypi.org/project/PyYAML/) to parse YAML files and [munch](https://pypi.org/project/munch/) library to create attribute-stylish dictionaries.
84
88
85
-
86
89
### Flags
87
90
88
-
```python
91
+
```python
89
92
# merge default and production configuration files
90
93
# setting to `False` disables other flags and makes default config optional
91
-
# `False` means "open config file and apply `ymal.safe_load` and `munchify` with no formatting"
92
-
merge_configs=True
94
+
# `False` means "open config file and apply `yaml.safe_load` and `munchify` with no formatting"
95
+
merge_configs=True
93
96
```
97
+
94
98
```python
95
99
# list of sections to ignore when merging configs
96
100
# it is useful when you have examples in your default config but do not want to have in the main one
0 commit comments