Skip to main content

UNKNOWN

Project description

So you have some configuration variables, and you want them to be available to be in any number of ini-like files, as well as overridable from the environment, and overridable from the command line. Define once, and use.

>>> options = [
...    Option('debug', 'Run in debug mode', False,
...           short_name='d', converter=bool, action='store_true'),
... ]
>>> conf = Config(options)
>>> conf.debug # Will start as the default value
False

This time we shall pass an env prefix to look up on, so as not to pollute any environment namespace too badly:

>>> conf = Config(options, 'PONY')
>>> conf.grab_from_env({'PONY_DEBUG': '1'})
>>> conf.debug
True

Now we can grab some stuff from argv:

>>> conf = Config(options)
>>> conf.grab_from_argv(['--debug', '1'])
>>> conf.debug
True

Also, remember that you can serialize these things:

>>> conf = Config(options)
>>> conf.to_dict()
{'debug': False}

So as you can see above, the options were declared, and then the config object was created from those options. It is imagined that an application may collate the options from many different places, such as plugins which wish to define their own options.

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

sensibleconfig-0.1.tar.gz (1.2 kB view details)

Uploaded Source

File details

Details for the file sensibleconfig-0.1.tar.gz.

File metadata

  • Download URL: sensibleconfig-0.1.tar.gz
  • Upload date:
  • Size: 1.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sensibleconfig-0.1.tar.gz
Algorithm Hash digest
SHA256 e96eaebac18d4ed055ac9d82331cc6d85a1f43f2a912a7b460902877dc23e2c7
MD5 1843d2fe960c6993ccab5f7a6af5c4ca
BLAKE2b-256 5c85c5612a46fd811f35c5a0a7abb88cc8f59f52558b188a4e8b017c0e827bd6

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