Skip to main content

A better configuration library for Django and other Python projects

Project description

Walter is a configuration library, inspired by python-decouple, and intended to replace direct access to os.environ in Django settings.py files (although it is by no means Django-specific). It currently supports Python 3.6+.

It differs from other, similar libraries for one reason: when your users try to start up your app with invalid configuration, the error message they get shows a list of all of the errors with every configuration parameter, not just the first one.

Installation

pip install walter
# or
poetry add walter

Usage

Here’s an example of a Python file that uses Walter to define its configuration.

from walter.config import Config

with Config("Acme Inc.", "My Awesome App") as config:

    # Read a configuration value with config.get()
    SECRET_KEY = config.get('SECRET_KEY')

    # Convert the returned value to something other than a string with cast.
    DEBUG = config.get('DEBUG', cast=bool)

    # You can pass any function that takes a string to `cast`.
    # Here, we're using a third party function to parse a database URL
    # string into a Django-compatible dictionary.
    import dj_database_url
    DATABASES = {
        'default': config.get('DATABASE_URL', cast=dj_database_url.parse),
    }

    # You can also make a parameter optional by giving it a default.
    SENTRY_DSN = config.get('SENTRY_DSN', default=None)

    # Last but not least, help_text will be displayed in your
    # Sphinx docs, in a future release.
    SITE_NAME = config.get(
        'SITE_NAME',
        help_text="Displayed to users in the admin",
    )

print(f"Here, you can use values like {SITE_NAME}!")

If we run that code without setting anything, Walter throws an error at the end of the with block.

Traceback (most recent call last):
File "<stdin>", line 27, in <module>
File "/Users/leigh/Projects/walter/walter/config.py", line 90, in __exit__
    raise ConfigErrors(errors=self.errors)
walter.config.ConfigErrors: 4 configuration values not set, 0 invalid

SECRET_KEY not set
DEBUG not set
DATABASE_URL not set
SITE_NAME not set

Note that Walter lists out all of the errors in our configuration, not just the first one! If we set all of those settings as environment variables and run the code again, the code runs to completion:

Here, you can use values like MyAwesomeApp!

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

walter-1.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

walter-1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file walter-1.0.tar.gz.

File metadata

  • Download URL: walter-1.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Darwin/19.4.0

File hashes

Hashes for walter-1.0.tar.gz
Algorithm Hash digest
SHA256 61aed794c077eca35c026ee68a8a735effecb280628f95f757d036f4b6a8f4e3
MD5 54a80285cd4bf17d11d71079455fe664
BLAKE2b-256 e2f1e91428e2fd9b2a0f491a1b2cec13d6362a80be3dee39aad84c230a25b606

See more details on using hashes here.

File details

Details for the file walter-1.0-py3-none-any.whl.

File metadata

  • Download URL: walter-1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.2 Darwin/19.4.0

File hashes

Hashes for walter-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 380d52b6df47b125f6c1d22b41be9f64a51f069dd24da6c24355d2f0ffee9430
MD5 172775ae1aebec607636a84b3bed6470
BLAKE2b-256 55c5849b7fba2890e721724cc16a6a41df0d805f75850b8b95a960d6089fcf2e

See more details on using hashes here.

Supported by

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