This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Overview

Flask-INIConfig is a Flask extension that adds two additional methods from_inifile and from_inifile_sections to the Flask.config configuration instance for an application. This allows you to load ini files or sections from an ini file directly into the config object.

Installation

Install the extension using pip:

$ pip install flask-iniconfig

or easy_install:

$ easy_install flask-iniconfig

Usage

Basic Usage

You can initialize the extension by calling it’s constructor:

from flask import Flask
from flask.ext.iniconfig import INIConfig

app = Flask(__name__)
INIConfig(app)
# or use the init_app form
# INIConfig().init_app(app)

app.config.from_inifile('/path/to/file.ini')

property = (app.config.get('section') or {}).get('property')

Important

  • Property and section names are case-sensitive.
  • Typically ConfigParser normalizes settings and property names to be lower case, however that is turned off for the instance that is used by the extension.

from_inifile

When you use from_inifile sections in an ini file are individual properties in the config object. For example if you have the following:

[section]
a_property = 1

and you load it using:

app.config.from_inifile('/path/to/file.ini')

you can access it as:

section = current_app.config.get('section')
property = section['a_property']

As of v0.0.8 if you provide a flag called objectify to from_inifile, it will add the section as an instance variable to the config object. You can then load it using:

app.config.from_inifile('/path/to/file.ini', objectify=True)

which will allow you to access it as:

section = current_app.config.section
property = section['a_property']

Important

  • Be very careful about the section names so that there is no conflict with built in members as app.config is merely a dict.
  • These section instance variables are plain dictionaries. Thes are not objects themselves.

There is a special section for Flask apps called flask which can be used to specify the application properties. So if you have the following:

[flask]
DEBUG = 1

you can use current_app.config['DEBUG'] instead of having to specify the section. All property names in the flask section are converted to upper case just like in from_inifile_sections but only for the flask section.

from_inifile_sections

When you use from_inifile_sections only the relevant sections and the flask section, if present, are loaded from the ini file. The other major difference is that instead of app.config having a property with the name of the section, all properties are tacked on to the app.config object.

Moreover all property names are converted to upper-case as most extensions and Flask’s internal configuration properties are all in upper case.

The only exception is when you provide the preserve_case flag to this method. When given this will preserve the case for all non-flask options. Flask options will still be converted to upper case. This allows you to use things like sqlalchemy’s engine_from_config directly with the config object.

This is quite useful if you have one ini file with settings for development, staging, production and test settings you can load only the ones you want which can then be used by flask directly.

For e.g. if you have the following:

[flask]
DEBUG = 1

[common]
a = 1
b = 0

[dev]
b = 2

[prod]
b = 3

and you load it using:

app.config.from_inifile_sections('/path/to/file.ini', ['common', 'dev'])

which would add the properties A and B to app.config.

Note

This particular method does not load sections that are not specified. Prior to r4372a8e this was not the case and would occasionally cause problems with interpolations.

Customizing SafeConfigParser

If you want to customize the way the internal SafeConfigParser works you can use the arguments as specified in the RawConfigParser constructor documentation.

For example:

INIConfig(app, defaults={...}, dict_type=OrderedDict, allow_no_value=True)

Implementation Details

The base class that implements the extension is derived from SafeConfigParser and uses that to load the ini file. Consequently you get the built-in parsing and interpolation capabilities of the parser.

Because SafeConfigParser does not automatically coerce the values to an appropriate type, Flask-INIConfig will try to do it’s best to do some for you. The following cast attempts are made in order of precedence:

Note

  • You do not get access to the parser instance directly, however the constructor will accept the arguments to SafeConfigParser and pass them through.
  • The extension deviates from SafeConfigParser’s treatment of boolean because a type-coercion to int happens before a type-coercion to boolean. So if you want a boolean set it to one of yes, no, on, off, true or false only.

Warning

The extension does not try coerce values to types for keys that are already specified in the application configuration. So if you are overriding configuration properties in an ini file you need to be careful about the actual types.

Release History

Release History

0.1.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
Flask_INIConfig-0.1.0-py2.py3-none-any.whl (8.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jul 8, 2016
Flask-INIConfig-0.1.0.tar.gz (11.6 kB) Copy SHA256 Checksum SHA256 Source Jul 8, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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