Skip to main content

ORM-like *.ini config parser.

Project description


Build Status PyPI - Status PyPI - Python Version PyPI PyPI - License

Heavily inspired by Charles Leifer peewee ORM. This package provides ORM-like interface to interact with *.ini configs. And map their data onto object models.


Lets say we have config like this:


server =
password = my_password
user = admin
base = test_base

debug = True
connection port = 5000

Defining models is similar to ORM's:

import os
from configorm import *

current_dir = os.path.abspath(os.path.dirname(__file__))
connection_string = os.path.join(current_dir, 'config.ini')

connector = IniConnector(connection_string=connection_string)

class BaseSection(Section):
    class Meta:
        connector = connector

class Database(BaseSection):
    server = StringField()
    password = StringField()
    user = StringField()
    base = StringField()

class General(BaseSection):
    debug = BooleanField()
    connection_port = IntegerField()
>>> from Config import Database
>>> Database.server

Section names must match their counterparts in ini file, but case does not matter at all. All spaces in section or key names of config file will be treated as underlines.

Depending on field data will be casted to exact type.

>>> from Config import General
>>> General.debug
>>> type(General.debug)
<class 'bool'>

You may provide default fallback values for your fields. If field may return None Type values, null parameter must be set as True

from configorm import *

class Database(Section):
    server = StringField(default='')
    password = StringField(default='secret')
    user = StringField(default='admin')
    base = StringField(default='development')

    possible_none_value = StringField(null=True)

Base Section aside from connection to config file also provides tool to create configuration from models, allowing model-first approach. It crates config file, sections from your models names and option based on provided fields. In case if fields have default values, they will be written in config as well. Otherwise options will be filled with empty values.

>>> from Config import *
>>> BaseSection.check_config_integrity()

Project details

Download files

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

Files for ConfigORM, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size ConfigORM-0.0.2-py3-none-any.whl (5.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size ConfigORM-0.0.2.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page