Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/datek/datek-app-utils
https://github.com/datek/datek-app-utils
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/datek/datek-app-utils
- Owner: DAtek
- License: mit
- Created: 2021-11-14T12:48:03.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-08-27T18:58:11.000Z (4 months ago)
- Last Synced: 2024-10-03T11:36:48.038Z (3 months ago)
- Language: Python
- Size: 119 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[![codecov](https://codecov.io/gh/DAtek/datek-app-utils/graph/badge.svg?token=UR0G0I41LD)](https://codecov.io/gh/DAtek/datek-app-utils)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)# Utilities for building applications.
## Contains:
- Config loading from environment
- Bootstrap for logging
- Async timeout decorator, which is very useful for writing async tests## Examples:
### Env config
```python
import osfrom datek_app_utils.env_config.base import BaseConfig
# Just for demonstration, of course env vars shouldn't be set in python
os.environ["COLOR"] = "RED"
os.environ["TEMPERATURE"] = "50"
os.environ["DISABLE_AUTOTUNE"] = "y"class Config(BaseConfig):
COLOR: str
TEMPERATURE: int
DISABLE_AUTOTUNE: boolassert Config.COLOR == "RED"
assert Config.TEMPERATURE == 50
assert Config.DISABLE_AUTOTUNE is True
```The `Config` class casts the values automatically.
Moreover, you can test whether all the mandatory variables have been set or not.```python
import osfrom 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 ValidationErroros.environ["COLOR"] = "RED"
os.environ["DISABLE_AUTOTUNE"] = "I can't sing but I pretend to be a singer"class Config(BaseConfig):
COLOR: str
TEMPERATURE: int
AMOUNT: int = None
DISABLE_AUTOTUNE: bool = Nonetry:
validate_config(Config)
except ValidationError as error:
for attribute_error in error.errors:
print(attribute_error)```
Output:
```
DISABLE_AUTOTUNE: Invalid value. Required type:
TEMPERATURE: Not set. Required type:
```### Async timeout decorator
```python
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
```