Skip to main content

An app configuration toolkit that tries to do things right.

Project description

An app configuration toolkit that tries to do things right.

Install

Convoke is available from PyPI:

pip install convoke

Usage

Create a Settings object:

from convoke import Settings

settings = Settings('My App Name')

Convoke will pull settings from three places, in order of priority:

  1. Local overrides:

    Settings('My App Name', foo='bar')
  2. os.environ values (upper-cased):

    settings.get('foo') == os.environ.get('FOO')
  3. a provided INI-style configuration filepath or config.ini in the OS-specific application directory:

    # ~/.config/config.ini (or OS equivalent)
    foo = bar

The Settings object provides convenience accessors for different value types:

  • Strings:

    settings['foo']
    settings.get('foo', default='blah')
  • Boolean:

    settings.as_bool('foo', default='True')
  • Integer:

    settings.as_int('foo', default='5')
  • Float:

    settings.as_float('foo', default='5.0')
  • Path (returns path.Path objects):

    settings.as_path('foo', default='~/blah')

For simple usage, there’s also a singleton Settings mode:

settings = convoke.get_settings('My App Name', foo='bar')
assert settings.app_name == 'My App Name'
assert settings['foo'] == 'bar'

# Further calls to get_settings returns the same object:
settings2 = convoke.get_settings()
assert settings2 is settings

# Future overrides have no effect:
settings2 = convoke.get_settings('Some other name', foo='blah')
assert settings.app_name == 'My App Name'
assert settings['foo'] == 'bar'

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

convoke-1.3.3.tar.gz (20.9 kB view details)

Uploaded Source

File details

Details for the file convoke-1.3.3.tar.gz.

File metadata

  • Download URL: convoke-1.3.3.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for convoke-1.3.3.tar.gz
Algorithm Hash digest
SHA256 a92181c25ac83e7669fcb58301964decfe21aa91742833cbc9b16c5c950e3bc6
MD5 ce49a3fa077d4c125bcf528d58357d72
BLAKE2b-256 b163494ed47345dbb39ac48f5fcd682dd03910e164a80ee69f995e71ab5bd4cd

See more details on using hashes here.

Supported by

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