Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Configuration manager

Project description

Python Package Documentation Status Build Status Code Coverage License

configuration parser.


$ pip install kaptan

Also available as a package on FreeBSD, Debian, Arch Linux and Slackware.


supported handlers

  • dict
  • json
  • yaml
  • .ini
  • python file

default (dict) handler

config = kaptan.Kaptan()
    'environment': 'DEV',
    'redis_uri': 'redis://localhost:6379/0',
    'debug': False,
    'pagination': {
        'per_page': 10,
        'limit': 20,

print config.get("pagination.limit")

# output: 20

json handler

config = kaptan.Kaptan(handler="json")
config.import_config('{"everything": 42}')

print config.get("everything")
# output: 42

yaml handler

config = kaptan.Kaptan(handler="yaml")
    value: 12.65
      1. TL
      2. EURO
print config.get("product.price.currency_list.0")
# output: TL

or you can get from directly from the filename:


.ini handler


database_uri = mysql://root:123456@localhost/posts

database_uri = mysql://poor_user:poor_password@localhost/poor_posts
config = kaptan.Kaptan(handler="ini")

print config.get("production.database_uri")
# output: mysql://poor_user:poor_password@localhost/poor_posts

file handler

DATABASE = 'mysql://root:123456@localhost/posts'
DEBUG = False
    'per_page': 10,
    'limit': 20,
config = kaptan.Kaptan(handler="file")

print config.get("DEBUG")
# output: False

exporting configuration

config = kaptan.Kaptan(handler="file")
    'environment': 'DEV',
    'redis_uri': 'redis://localhost:6379/0',
    'debug': False,
    'pagination': {
        'per_page': 10,
        'limit': 20,

print config.export("yaml")


debug: false
environment: DEV
pagination: {limit: 20, per_page: 10}
redis_uri: redis://localhost:6379/0

print config.export("json")

outputs unindented json. .export accepts kwargs which pass into json.dumps.

print config.export("json", indent=4)


    "environment": "DEV",
    "debug": false,
    "pagination": {
        "per_page": 10,
        "limit": 20
    "redis_uri": "redis://localhost:6379/0"

config.export('yaml') also supports the kwargs for pyyaml.

New in Version 0.5.7: config.export('yaml', safe=True) will use .safe_dump.


exporting (defaults to json)

$ echo "environment: DEV" > config.yaml
$ kaptan config.yaml --export json > config.json
$ cat config.json
{"environment": "DEV"}

getting a value

$ kaptan config.yaml --key environment

specifying the handler

$ mv config.yaml config.settings
$ kaptan config.settings:yaml --export json
{"environment": "DEV"}

config from stdin

$ echo '{"source": "stdin"}' | kaptan -
{"source": "stdin"}
$ echo 'source: stdin' | kaptan -:yaml
{"source": "stdin"}

merging configs

$ echo "environment: PROD" > config.settings
$ echo '{"source": "stdin"}' | kaptan - config.json config.settings:yaml
{"environment": "PROD", "source": "stdin"}

setting default handler

$ echo "source: stdin" | kaptan --handler yaml - config.settings
{"environment": "PROD", "source": "stdin"}

writing json with yaml

$ kaptan -:yaml -e json
<type yaml here>
<Ctrl + D>
<get json here>

running tests

with py.test:

$ py.test

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
kaptan-0.5.10.tar.gz (10.1 kB) Copy SHA256 hash SHA256 Source None Jul 6, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page