My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages

Introduction

configpy lets you read config files with ease in Python. See the below for examples of the power of this module.

Examples

Simple Variables

from configpy import Config

cfg = """
first_name="Foo"
"""

config = Config(cfg)
print config.first_name # "prints Foo"

Compound Variables

configpy support look-behind and look-ahead variables.

from configpy import Config

cfg = """ 
last_name="${temp}"
first_name="Foo"
temp="Bar"
full_name="${last_name}, ${first_name}"
"""

config = Config(cfg)
print config.full_name # prints "Bar, Foo"

Type Aware

configpy supports list, dict, float, int and string types.

from configpy import Config

cfg = """ 
nums = [1,2,3,4]
nando = "Nando" 
names = ["Stevie", "${nando}", "Robbie"]
planets = { 'planet': '${red_planet}' }
red_planet = 'mars'
num_items = 5
item_cost = 1.99
"""

config = Config(cfg)
print sum(config.nums) # prints 10
print config.planets['planet'] # prints "mars"
config.names.sort()
print config.names # prints ["Nando", "Robbie", "Stevie"]
print config.num_items * config.item_cost # prints 9.95

See the test file for more examples.

Powered by Google Project Hosting