Skip to main content
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`.

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)

Source distribution for confi 0.0.4.1
File Size Uploaded
confi-0.0.4.1.tar.gz 3.2 kB Details

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

Release history Release notifications | RSS feed

This release

0.0.4.1 This release

1 release file

0.0.3

1 release file

0.0.2

2 release files

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page