envdataclass-0.4


توضیحات

Parses .env files against dataclass based schema validation
ویژگی مقدار
سیستم عامل -
نام فایل envdataclass-0.4
نام envdataclass
نسخه کتابخانه 0.4
نگهدارنده []
ایمیل نگهدارنده []
نویسنده briccardo
ایمیل نویسنده rbiagini02@gmail.com
آدرس صفحه اصلی -
آدرس اینترنتی https://pypi.org/project/envdataclass/
مجوز MIT
# envdataclass Parses .env files against dataclass based schema validation `pip install envdataclass` # Supported schema types - `int` - `str` - `List[int]` - `bool` # Example usage (short and sweet) ```python from dataclasses import dataclass from typing import List from envdataclass import from_string @dataclass class my_cool_config_schema: test_list_int: List[int] foo = from_string(my_cool_config_schema, 'test_list_int=1,2,3,5') print(foo) print(type(foo.test_list_int)) print(type(foo.test_list_int[1])) ``` Output: ```python my_cool_config_schema(test_list_int=[1, 2, 3, 5]) <class 'list'> <class 'int'> ``` # Example usage (longer version) Define a data class for your config schema: ```python @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: ```python foo = from_file(my_cool_config_schema, '/path/.env') ``` Result: ```python 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 a `str` equal to `'123,456,123'` to a `List` equal to `[123, 456, 123]` - `test_bool_d` got parsed from `str` equal to `'true'` to `True`


نیازمندی

مقدار نام
- python-dotenv


نحوه نصب


نصب پکیج whl envdataclass-0.4:

    pip install envdataclass-0.4.whl


نصب پکیج tar.gz envdataclass-0.4:

    pip install envdataclass-0.4.tar.gz