confi-0.0.4.1
توضیحات
Comfortable python app configuration
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | confi-0.0.4.1 |
| نام | confi |
| نسخه کتابخانه | 0.0.4.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Boris Tseitlin |
| ایمیل نویسنده | btseytlin@start.film |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/confi/ |
| مجوز | - |
Comfortable python configs from environment variables.
* Validated at **import time**. If you forgot a configuration variable you find out at startup.
* One source of configuration for all application code. No more `flask_conf.cfg`, `myconfig.ini`, `.env`, hardcoded constants and variables from `docker-compose.yml`.
* Type casting and validation at load time. Do it once and forget.
# Quickstart
```
>>> from confy import BaseEnvironConfig
>>> class Config(BaseEnvironConfig):
... DEBUG = ConfigField(processor=strtobool, default=True)
...
>>> Config.DEBUG
True
```
Loads variable `DEBUG` __at import time__ from environment, applies function `string_to_bool` to the value,
If variable is not provided uses the default of `True`.
# Config field options
* `default` - default value, can be anything
* `required` - boolean, default `False`. Throws `ConfigError` if value is required, but not provided.
* `processor` - callable. Can be used to validate the value
* `from_var` - specify environment variable to take value from. If none uses config class property name, __case is important__.
# Mocking in tests
Since its a global class that can't be instanced it's __very important__ to import it like this:
```
from package import module
print(module.ConfigClass.as_text())
```
and __not__ like this:
```
from package.module import ConfigClass
print(ConfigClass.as_text())
```
The first option allows you to monkey patch the config during testing.
Pytest example:
```
from package.module import ConfigClass
class TestConfig(ConfigClass):
pass
TestConfig.TEST = True
monkeypatch.setattr('package.module.ConfigClass', TestConfig)
```
All code accesing `module.ConfigClass` will get `TestConfig`.
نحوه نصب
نصب پکیج whl confi-0.0.4.1:
pip install confi-0.0.4.1.whl
نصب پکیج tar.gz confi-0.0.4.1:
pip install confi-0.0.4.1.tar.gz