Utilities for building applications
Project description
Utilities for building applications.
Contains:
- Config loading from environment
- Bootstrap for logging
- Base class for creating async workers
- Async timeout decorator, which is very useful for writing async tests
Examples:
Env config
import os
from datek_app_utils.env_config.base import BaseConfig
os.environ["COLOR"] = "RED"
os.environ["TEMPERATURE"] = "50"
class Config(BaseConfig):
COLOR: str
TEMPERATURE: int
assert Config.COLOR == "RED"
assert Config.TEMPERATURE == 50
The Config
class casts the values automatically.
Moreover, you can test whether all the mandatory variables have been set or not.
import os
from datek_app_utils.env_config.base import BaseConfig
from datek_app_utils.env_config.utils import validate_config
from datek_app_utils.env_config.errors import ValidationError
os.environ["COLOR"] = "RED"
class Config(BaseConfig):
COLOR: str
TEMPERATURE: int
AMOUNT: int = None
try:
validate_config(Config)
except ValidationError as error:
for attribute_error in error.errors:
print(attribute_error)
Output:
TEMPERATURE: Not set. Required type: <class 'int'>
Async timeout decorator
from asyncio import sleep, run
from datek_app_utils.async_utils import async_timeout
@async_timeout(0.1)
async def sleep_one_sec():
await sleep(1)
run(sleep_one_sec())
Output:
TimeoutError
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
datek_app_utils-0.3.4.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for datek_app_utils-0.3.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fea4b6cd48f4075296374274c7a0d3c187c2a88e789b052c5c201e876199d8c5 |
|
MD5 | 563c9869876ea2367bc71c325882f8b2 |
|
BLAKE2b-256 | 818f86f0bda3dcd90ca95b601612ff549110dde1d1ddbe5abb9bcd66288a5be4 |