Skip to main content

ORM-like *.ini config parser.

Project description

ConfigORM

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.

Examples

Lets say we have config like this:

#config.ini

[Database]
server = 10.10.10.10
password = my_password
user = admin
base = test_base

[General]
debug = True
connection port = 5000

Defining models is similar to ORM's:

#Config.py

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
'10.10.10.10'

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
True
>>> 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='10.10.10.10')
    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.

Source Distribution

ConfigORM-0.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ConfigORM-0.0.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file ConfigORM-0.0.2.tar.gz.

File metadata

  • Download URL: ConfigORM-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for ConfigORM-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a713ddfe518d0824f3b304270ef3bf46a347d370148671710e7ece00d59ae7b9
MD5 983697ce7f548508dea67f56724d53bc
BLAKE2b-256 1d6202657c7fa72b8d94a79f20ad3c936876894002c868bb9dc22db9d0ab2454

See more details on using hashes here.

File details

Details for the file ConfigORM-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: ConfigORM-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for ConfigORM-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b977f3d35e1e39fc4d7137d08f0c8f982f956a4c8a9401c81bdabb72327fcc69
MD5 7efafbc1a0939a93e6fd782465efa9c5
BLAKE2b-256 0ac458ddfc6c2746f2c6008569416180b5346f3bd630ea9b430c5eb6806fbeaa

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