* 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`.
Metadata
Release files for confi 0.0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| confi-0.0.4.1.tar.gz | 3.2 kB | Without provenance | Details for confi-0.0.4.1.tar.gz |
Release files / confi-0.0.4.1.tar.gz
| Download URL | confi-0.0.4.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ffb8ebba51194f7be7b3b1bc0946216de42417e83fd487e83e8efb0450897c6
|
|
BLAKE2b-256 checksum How to use checksums |
336cd550680225b086899109c41ecb0fa1a64351d7d18d6ec578cc6103c6549b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.4.0 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/3.6.4
|
Security for confi 0.0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.