-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-typed.py
executable file
·40 lines (28 loc) · 990 Bytes
/
example-typed.py
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
#!/usr/bin/env python3
import logging
from datetime import date
from pathlib import Path
from typing import Optional
from pydantic import BaseModel, Field
import alphaconf.cli
class Conn(BaseModel):
url: str = Field("http://github.com", title="Some URL")
home: Path = Path("~")
class MyConfiguration(BaseModel):
name: Optional[str] = Field(None, title="Some name to show")
some_date: Optional[date] = None
connection: Optional[Conn] = None
alphaconf.setup_configuration(MyConfiguration, prefix="c")
def main():
"""Typed configuration example"""
logging.info('Got configuration name: %s', alphaconf.get('c.name'))
c = alphaconf.get(MyConfiguration)
logging.info("Found configuration object: %s", c)
if c.connection:
logging.info(
'connection.home: %s (%s)',
alphaconf.get('c.connection.home', default='unset'),
c.connection.home,
)
if __name__ == '__main__':
alphaconf.cli.run(main)