Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A simplified interface to ConfigParser using dot notion with data type / comment support.

Project Description


A simplified interface to ConfigParser using dot notion with data type / comment support.

Feature Summary

  • Simple access to config using dot notion and iterators
  • Full compatibility with ConfigParser ini formats (as that is used as the backend)
  • Data type support by intelligently guessing the data types based on value on read.
  • Multiple config source input (read from string, file pointer, file, or list of them)
  • Full comment support / retention on save
  • Lazy reading of config sources for performance (only read when a config value is accessed)

Quick Start Tutorial

To install:

pip install localconfig

Let’s say we have a script named ‘program’ with the following config in ~/.config/program:

[Web Server]
# Server host
host =

# Server port
port = 8080

# Debug logging
debug = off

To read the config, simply do:

from localconfig import config

start_server(, config.web_server.port, config.web_server.debug)

# Or use get method:
# start_server(config.get('Web Server', 'host'),
#              config.get('Web Server', 'port'),
#              config.get('web_server', 'debug'))  # Yes, 'web_server' also works here!
# Or if the config is in docstring, read from it:
# Or if the config file is elsewhere:
#'/etc/path/to/config.ini')  # Non-existing file is ignored
# Or read from a list of sources
#['string config', file_path, file_pointer, io.StringIO('config')])
# Or create another instance for another config:
# from localconfig import LocalConfig
# config2 = LocalConfig('/etc/path/to/another/config.ini')

Now, let’s do some inspection:

# Iterate over sections and their keys/values
for section in config:
  print section                    # Web Server

  for key, value in config.items(section):
    print key, value, type(value)  # host <type 'str'>
                                   # port 8080 <type 'int'>
                                   # debug False <type 'bool'>

sections = list(config)            # ['Web Server']

# Iterate over keys/values
for key, value in config.web_server:
  print key, value, type(value)    # Same output as above config.items()

items = list(config.web_server)    # [('host', ''), ('port', 8080), ('debug', False)]
items = dict(config.web_server)    # {'host': '', 'port': 8080, 'debug': False}

# Check if a section or key is set - any non-existing section or key defaults to None.
if config.web_server or config.no_such_section:

if config.web_server and (config.web_server.port or config.web_server.no_such_key):

To add a section and set a value:

config.add_section('App Server', comment='Settings for application server') = 'localhost'

# Use `set` if you want to set a comment
config.set('App Server', 'port', 9090, comment='App server port')

To write the config:

# Or simply get the config as a string:
# config_str = str(config)
# Or save to a different location:

If we open ~/.config/program now, we would see:

[Web Server]

# Server host
host =

# Server port
port = 8080

# Debug logging
debug = off

# Settings for application server
[App Server]

host = localhost

# App server port
port = 9090

Supported Data Types

Data type is guessed based on the value and converted on read.

The following types are supported:

Type Example Value
int 1
float 2.0
bool true false yes no on off (case insensitive)
None none (case insensitive)
str Any other value not matched by above
Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
localconfig-1.0.2.tar.gz (16.1 kB) Copy SHA256 Checksum SHA256 Source May 25, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting