Skip to main content

A nice config package

Project description

niceconf is a dropin replacement for the stdlib RawConfigParser object. It makes parsing and using configuration files in your python scripts approximately 10 times more pythonic and fun.

By default it reads and writes to ~/.conf. This can be changed by setting $CONF. If ~/.conf or the file specified in $CONF does not exist, it will be created on the first import.


basic usage:
>>> from niceconf import config
>>> config
gmail
my-database
secret-stuff
>>> config['gmail']
[gmail]
username = rick@gmail.com
password = wubalubadubdub
>>> config['gmail']['username']
'rick@gmail.com'
>>> config['gmail']['password']
'wubalubadubdub'
add or set config file options:
>>> config['my-database']['port'] = 3306
>>> config['my-database']['port']
'3306'
delete config file options:
>>> del config['secret-stuff']['burn-after-reading']
>>> config['secret-stuff']['burn-after-reading']
NoOptionError: No option 'burn-after-reading' in section: 'secret-stuff'
add a section (any valid dict-like can be added as section):
>>> config['stackoverflow'] = {'username': 'guido',
                               'password': 'pa$$word1'}
>>> config['stackoverflow']
[stackoverflow]
username = guido
password = pa$$word1
delete a section:
>>> del config['stackoverflow']
>>> config['stackoverflow']
NoSectionError: No section: 'stackoverflow'
write out to a file (overwrites by default):
>>> config.save()
read in another config file:
>>> config.read('/path/to/conf')
['/path/to/conf']
>>> config
gmail
my-database
secret-stuff
first_section_of_other_conf
second_section_of_other_conf
explode conf into function arguments
>>> print_kwargs(**config['gmail'])
{'username': 'rick@gmail.com', 'password': 'wubalubadubdub'}

Additionally, the config object _is_ an instance of RawConfigParser, so you can use any of those methods as before. This means that config is a dropin replacement for ConfigParser.

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

niceconf-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file niceconf-0.1.2.tar.gz.

File metadata

  • Download URL: niceconf-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for niceconf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 53660cc0d5ae852026b5d223a64f996e14421ca5153244515512ea50c7a5de52
MD5 a37a76af0c8b6a2d15eb95e43e07d555
BLAKE2b-256 5d36af2058ab95ac8d63ad880a3ebae048277340771f240c270a1d577048e592

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