Parses .env files against dataclass based schema validation
Project description
envdataclass
Parses .env files against dataclass based schema validation
pip install envdataclass
Supported schema types
intstrList[int]bool
Example usage (short and sweet)
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:
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:
@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_intgot parsed from astrequal to'123,456,123'to aListequal to[123, 456, 123]test_bool_dgot parsed fromstrequal 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file envdataclass-0.4.tar.gz.
File metadata
- Download URL: envdataclass-0.4.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
162ee1486218a0033221e0e27a001a6535643f610e7480b0e67accdd89bcc2d9
|
|
| MD5 |
10a5d50550a3f2c4dfd8ecf410a8202b
|
|
| BLAKE2b-256 |
41dc2b05055a65274899dc10c0c9e8a6f868049ddfcbb6307635a2e3b729b407
|
File details
Details for the file envdataclass-0.4-py3-none-any.whl.
File metadata
- Download URL: envdataclass-0.4-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f92f67da2b2ea3c9ad4866898e053072f9b10124cd94710a6df0252cb195b01
|
|
| MD5 |
8db6456a96ac574501a648475210ddaf
|
|
| BLAKE2b-256 |
205e65f2275e5a055064ecf766049609f73d93100099ec6b438af9136384a90d
|