Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A configurable way of moving some settings out of the django settings.py and into a deployable .ini file

Project Description
# django-ini-settings


This library aims to be a non-intrusive configurable way of moving some local
settings out of the django settings.py and into a deployable .ini file

## Quick-start

Install this library

pip install django_ini_settings

Add the hook into your settings.py, if you want to use the default config
mapping the following would do:

from django_ini_settings.load import load_ini

load_ini(ini_file="/etc/application/application.ini",
settings_module=sys.modules[__name__])

This implies that your ini file is located in /etc/application/application.ini
For example this ini might look like:

[database]
user = postgres
password = secret

[security]
secret_key = !sfgr42325asdasd$34324
debug = false

To insert custom configs you can either use the default format of the type as the group
and the config name as the option. e.g.

[string]
custom_url = /custom/url

[bool]
feature_on = false

[int]
max_num_files = 120

This would be transformed to the following in your settings.py

CUSTOM_URL = "/custom/url"
FEATURE_ON = False
MAX_NUM_FILES = 120

You can also provide your own mapping, including wildcards. e.g. add the
following in your settings


from django_ini_settings.load import load_ini
from django_ini_settings.settings_types import (DictItemSetting, StringSetting,
BoolSetting, IntSetting)
from django_ini_settings.statics import ANY, NAME_TO_UPPER

CONFIG_FILE_MAPPING = {
("database", "user"): DictItemSetting(("DATABASES", "default", "USER")),
("database", "password"): DictItemSetting(("DATABASES", "default", "PASSWORD")),
("database", "engine"): DictItemSetting(("DATABASES", "default", "ENGINE")),
("database", "name"): DictItemSetting(("DATABASES", "default", "NAME")),
("database", "host"): DictItemSetting(("DATABASES", "default", "HOST")),
("database", "port"): DictItemSetting(("DATABASES", "default", "PORT")),
("security", "secret_key"): StringSetting("SECRET_KEY"),
("security", "debug"): BoolSetting("DEBUG"),
("urls", "media_url"): StringSetting("MEDIA_URL"),
("urls", "static_url"): StringSetting("STATIC_URL"),
("application", "max_file_size"): IntSetting("MAX_FILE_SIZE"),
("application", ANY): StringSetting(NAME_TO_UPPER),
}

load_ini(ini_file="/etc/application/application.ini",
settings_module=sys.modules[__name__],
config_mapping=CONFIG_FILE_MAPPING)

## Environment Variables

Instead of doing:

load_ini(ini_file="/etc/application/application.ini",
settings_module=sys.modules[__name__])

You can also set an environment variable "DJANGO_CONFIG_FILE" containing the location of
the INI file. e.g.

DJANGO_CONFIG_FILE=/etc/application/application.ini

Then change the line to:

load_ini(settings_module=sys.modules[__name__])

## Tests

To run the tests, first make sure you have nose. If not then:

pip install nose

If you have nose installed then from the same directory as this README:

nosetests
Release History

Release History

This version
History Node

0.1.0

History Node

0.0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_ini_settings-0.1.0.tar.gz (4.7 kB) Copy SHA256 Checksum SHA256 Source Sep 30, 2015

Supported By

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