Skip to main content

Configuration library for Python applications

Project description

Everett is a Python configuration library for your app.

Code:

https://github.com/willkg/everett

Issues:

https://github.com/willkg/everett/issues

License:

MPL v2

Documentation:

https://everett.readthedocs.io/

Goals

Goals of Everett:

  1. flexible configuration from multiple configured environments

  2. easy testing with configuration

  3. easy automated documentation of configuration for users

From that, Everett has the following features:

  • is flexible for your configuration environment needs and supports process environment, env files, dicts, INI files, YAML files, and writing your own configuration environments

  • facilitates helpful error messages for users trying to configure your software

  • has a Sphinx extension for documenting configuration including autocomponentconfig and automoduleconfig directives for automatically generating configuration documentation

  • facilitates testing of configuration values

  • supports parsing values of a variety of types like bool, int, lists of things, classes, and others and lets you write your own parsers

  • supports key namespaces

  • supports component architectures

  • works with whatever you’re writing–command line tools, web sites, system daemons, etc

Everett is inspired by python-decouple and configman.

Install

Run:

$ pip install everett

Some configuration environments require additional dependencies:

# For INI support
$ pip install 'everett[ini]'

# for YAML support
$ pip install 'everett[yaml]'

Quick start

Example:

# myserver.py

"""
Minimal example showing how to use configuration for a web app.
"""

from everett.manager import ConfigManager

config = ConfigManager.basic_config(
    doc="Check https://example.com/configuration for documentation."
)

host = config("host", default="localhost")
port = config("port", default="8000", parser=int)
debug_mode = config(
    "debug",
    default="False",
    parser=bool,
    doc="Set to True for debugmode; False for regular mode",
)

print(f"host: {host}")
print(f"port: {port}")
print(f"debug_mode: {debug_mode}")

Then you can run it:

$ python myserver.py
host: localhost
port: 8000
debug_mode: False

You can set environment variables to affect configuration:

$ PORT=7000 python myserver.py
host: localhost
port: 7000
debug_mode: False

It checks a .env file in the current directory:

$ echo "HOST=127.0.0.1" > .env
$ python myserver.py
host: 127.0.0.1
port: 8000
debug_mode: False

It spits out useful error information if configuration is wrong:

$ DEBUG=foo python myserver.py
<traceback>
everett.InvalidValueError: ValueError: 'foo' is not a valid bool value
DEBUG requires a value parseable by everett.manager.parse_bool
DEBUG docs: Set to True for debugmode; False for regular mode
Project docs: Check https://example.com/configuration for documentation.

You can test your code using config_override in your tests to test various configuration values:

# testdebug.py

"""
Minimal example showing how to override configuration values when testing.
"""

import unittest

from everett.manager import ConfigManager, config_override


class App:
    def __init__(self):
        config = ConfigManager.basic_config()
        self.debug = config("debug", default="False", parser=bool)


class TestDebug(unittest.TestCase):
    def test_debug_on(self):
        with config_override(DEBUG="on"):
            app = App()
            self.assertTrue(app.debug)

    def test_debug_off(self):
        with config_override(DEBUG="off"):
            app = App()
            self.assertFalse(app.debug)


if __name__ == "__main__":
    unittest.main()

Run that:

$ python testdebug.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

That’s perfectly fine for a 12-Factor app.

When you outgrow that or need different variations of it, you can switch to creating a ConfigManager instance that meets your needs.

Why not other libs?

Most other libraries I looked at had one or more of the following issues:

  • were tied to a specific web app framework

  • didn’t allow you to specify configuration sources

  • provided poor error messages when users configure things wrong

  • had a global configuration object

  • made it really hard to override specific configuration when writing tests

  • had no facilities for autogenerating configuration documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

everett-3.4.0.tar.gz (66.8 kB view details)

Uploaded Source

Built Distribution

everett-3.4.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file everett-3.4.0.tar.gz.

File metadata

  • Download URL: everett-3.4.0.tar.gz
  • Upload date:
  • Size: 66.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for everett-3.4.0.tar.gz
Algorithm Hash digest
SHA256 f403c4a41764a6301fb31e2558d6e9718999f0eab9e260d986b894fa2e6b6871
MD5 f175a5148dd50159e3ffb3348ef47e0d
BLAKE2b-256 f5f4709258252f35f1ccadef745833252cc646eac540c97af28a860d8482860c

See more details on using hashes here.

File details

Details for the file everett-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: everett-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for everett-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8c29c7300702f47b7323b75348e2b86647246694fda7ad410c2a2bfaa980ff7
MD5 34a278c99b33792beab36aa4de633241
BLAKE2b-256 8cf1fd919ed781658d611322a41fcc1fbd8618887f09dc554f583e474a153f40

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page