Parses .env files against dataclass based schema validation
Project description
Supported schema types
int
str
List[int]
bool
Example usage
Define a data class for your config schema:
@dataclass
class my_cool_config_schema:
test_list_int: List[int]
test_int: int
test_string: str = '123'
test_bool: bool = False
test_string_d: str = 'hello'
test_int_d: int = 1234
test_bool_d: bool = False
The variables without a default value assigned will be assumed to be required. This means an exception will be thrown when any number of required variables are not present or are invalid in the environment file.
Example: TypeError: __init__() missing 1 required positional argument: 'test_int'
Setup a .env
file:
test_string_d=hellofromtheotherside
test_int=98766
test_bool_d=true
test_list_int=123,456,123
Load it:
foo = from_file(my_cool_config_schema, '/path/.env')
Result:
lol(test_list_int=[123, 456, 123],
test_int=98766,
test_string='123',
test_bool=False,
test_string_d='hellofromtheotherside',
test_int_d=1234,
test_bool_d=True)
test_list_int
got parsed from astr
equal to'123,456,123'
to aList
equal to[123, 456, 123]
test_bool_d
got parsed fromstr
equal to'true'
toTrue
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
envdataclass-0.1.tar.gz
(2.3 kB
view hashes)
Built Distribution
Close
Hashes for envdataclass-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbb4b68e586ee13b3cf23336562aa1daa0376ae1333a966377ced7fcc2c56d6d |
|
MD5 | ee2e16b2b627bec602d0eaa2b1f793e1 |
|
BLAKE2b-256 | 3540f6a8f296db89b763f55320f8a0fc638127a33dcb12caa72368a2231f766e |