Dotconf

Advanced configuration parser for Python
Download

Dotconf Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Antoine Millet
  • Publisher web site:
  • http://inaps.org

Dotconf Tags


Dotconf Description

Dotconf is an advanced configuration parser which allow nested sections to any level, typed values in syntax, file include and so more. It is also shipped with a powerful schema validation system.ExampleThis is an example of configuration file for an imaginary web server:daemon = Truepidfile = '/var/run/myapp.pid'interface = '0.0.0.0:80'interface_ssl = '0.0.0.0:443'host 'example.org' { path '/' { rate_limit = 30 }}host 'protected.example.org' { enable_ssl = yes path '/files' { enable_auth = yes user 'foo' { password = 'bar' } }}You can access to each values using the developer friendly API:>>> from dotconf import Dotconf>>> parsed_conf = Dotconf.from_file('mywebserver.conf')>>> print parsed_conf.get('daemon', False)TrueEven more exciting, you can create a validation schema to avoid you the painful chore of manual configuration file validation:from dotconf.schema import many, oncefrom dotconf.schema.containers import Section, Valuefrom dotconf.schema.types import Boolean, Integer, Float, String# Schema definition:class UserSection(Section): password = Value(String()) _meta = {'repeat': many, 'unique': True}class PathSection(Section): rate_limit = Value(Float(), default=0) enable_auth = Value(Boolean(), default=False) user = UserSection()class VirtualHostSection(Section): base_path = Value(String()) enable_ssl = Value(Boolean(), default=False) path = PathSection() _meta = {'repeat': many, 'unique': True}class MyWebserverConfiguration(Section): daemon = Value(Boolean()default=False) pidfile = Value(String(), default=None) interface = Value(String(), default='127.0.0.1:80') interface_ssl = Value(String(), default='127.0.0.1:443') host = VirtualHostSection()Then you can use the API exactly as if it was not validated:>>> from dotconf import Dotconf>>> from myconfschema import MyWebserverConfiguration>>> parsed_conf = Dotconf(conf, schema=MyWebserverConfiguration)>>> print 'daemon:', parsed_conf.get('daemon')daemon: True>>> for vhost in parsed_conf.subsections('host'):>>> print vhost.args>>> if vhost.get('enable_ssl'):>>> print ' SSL enabled'>>> for path in vhost.subsections('path'):>>> print ' ' + path.args>>> if path.get('enable_auth'):>>> print ' Following users can access to this directory:'>>> for user in path.subsections('user'):>>> print ' - ' + user.args>>>example.org /protected.example.org SSL enabled /files Following users can access to this directory: - fooProduct's homepage


Dotconf Related Software