Dev (old posts, page 25)

Everett v0.8 released!

, | Tweet this

What is it?

Everett is a Python configuration library.

Configuration with Everett:

  • is composeable and flexible
  • makes it easier to provide helpful error messages for users trying to configure your software
  • can pull configuration from a variety of specified sources (environment, ini files, dict, write-your-own)
  • supports parsing values (bool, int, lists of things, classes, write-your-own)
  • supports key namespaces
  • facilitates writing tests that change configuration values
  • supports component architectures with auto-documentation of configuration with a Sphinx autoconfig directive
  • works with whatever you're writing--command line tools, web sites, system daemons, etc

Everett is inspired by python-decouple and configman.

v0.8 released!

As I sat down to write this, I discovered I'd never written about Everett before. I wrote it initially as part of another project and then extracted it and did a first release in August 2016.

Since then, I've been tinkering with how it works in relation to how it's used and talking with peers to understand their thoughts on configuration.

At this stage, I like Everett and it's at a point where it's worth telling others about and probably due for a 1.0 release.

This is v0.8. In this release, I spent some time polishing the autoconfig Sphinx directive to make it more flexible to use in your project documentation. Instead of having configuration bits all over your project, you centralize it in one place and then in your Sphinx docs, you have something like:

.. autoconfig:: path.to.AppConfig

and it happily spits out the relevant configuration documentation. For example, here's Antenna's configuration documentation.

It'd be nice if configuration variables showed up in the index. I'll mull over that later.

Where to go for more

For more specifics on this release, see here: https://everett.readthedocs.io/en/latest/history.html#january-24th-2017

Documentation and quickstart here: https://everett.readthedocs.org/en/v0.8/

Source code and issue tracker here: https://github.com/willkg/everett

Anatomy of a class/function decorator and context manager

, | Tweet this

Over the weekend, I wanted to implement something that acted as both a class and function decorator, but could also be used as a context manager. I needed this flexibility for overriding configuration values making it easier to write tests. I wanted to use it in the following ways:

  1. as a function decorator:

    @config_override(DEBUG='False')
    def test_something():
        ...
    
  2. as a class decorator that would decorate all methods that start with test_:

    @config_override(DEBUG='False')
    class TestSomething:
        def test_something(self):
            ...
    
  3. as a context manager that allowed for multiple layer of overriding:

    def test_something():
        with config_override(DEBUG='False'):
            with config_override(SOMETHING_ELSE='ou812'):
                ...
    

This kind of need comes up periodically, but infrequently enough that I forget how I wrote it the last time around.

This post walks through how I structured it.

Read more…