@@ -13,16 +13,18 @@ $ pip install kaptan
1313or add kaptan directory to the your path.
1414
1515### usage ###
16+
1617** supported handlers**
1718
18- - dict
19- - json
20- - yaml
21- - .ini
22- - python file
19+ - dict
20+ - json
21+ - yaml
22+ - .ini
23+ - python file
2324
2425** default (dict) handler**
25- ``` python
26+
27+ ``` py
2628config = kaptan.Kaptan()
2729config.import_config({
2830 ' environment' : ' DEV' ,
@@ -36,10 +38,12 @@ config.import_config({
3638
3739print config.get(" pagination.limit" )
3840
39- # output: 20
41+ # output: 20
4042```
43+
4144** json handler**
42- ``` python
45+
46+ ``` py
4347config = kaptan.Kaptan(handler = " json" )
4448config.import_config(' {"everything": 42}' )
4549
@@ -48,7 +52,8 @@ print config.get("everything")
4852```
4953
5054** yaml handler**
51- ``` python
55+
56+ ``` py
5257config = kaptan.Kaptan()
5358config.import_config("""
5459product:
@@ -64,13 +69,14 @@ print config.get("product.price.currency_list.0")
6469
6570or you can get from directly from the filename:
6671
67- ``` python
72+ ``` py
6873config.import_config(" configuration.yaml" )
6974```
7075
7176** .ini handler**
7277
7378config.ini
79+
7480``` ini
7581[development]
7682database_uri = mysql://root:123456@localhost/posts
@@ -79,33 +85,38 @@ database_uri = mysql://root:123456@localhost/posts
7985database_uri = mysql://poor_user:poor_password@localhost/poor_posts
8086```
8187
82- ``` python
88+ ``` py
8389config = kaptan.Kaptan(handler = " ini" )
8490config.import_config(' config.ini' )
8591
8692print config.get(" production.database_uri" )
87- # output: mysql://poor_user:poor_password@localhost/poor_posts
93+ # output: mysql://poor_user:poor_password@localhost/poor_posts
8894```
95+
8996** file handler**
9097
9198config.py
92- ``` python
99+
100+ ``` py
93101DATABASE = ' mysql://root:123456@localhost/posts'
94102DEBUG = False
95103PAGINATION = {
96104 ' per_page' : 10 ,
97105 ' limit' : 20 ,
98106}
99107```
100- ``` python
108+
109+ ``` py
101110config = kaptan.Kaptan(handler = " file" )
102111config.import_config(' config' )
103112
104113print config.get(" DEBUG" )
105114# output: False
106115```
107- ## exporting configuration ##
108- ``` python
116+
117+ ## exporting configuration
118+
119+ ``` py
109120config = kaptan.Kaptan(handler = " file" )
110121config.import_config({
111122 ' environment' : ' DEV' ,
@@ -119,28 +130,32 @@ config.import_config({
119130
120131```
121132
122- ``` python
133+ ``` py
123134print config.export(" yaml" )
124135```
136+
125137** output** :
126- ```
138+
139+ ``` yaml
127140debug : false
128141environment : DEV
129142pagination : {limit: 20, per_page: 10}
130143redis_uri : redis://localhost:6379/0
131144` ` `
132145
133- ``` python
146+ ` ` ` py
134147print config.export("json")
135148```
136149
137- output unindented json. `` .export `` accepts kwargs which pass into [ json.dumps] ( http://docs.python.org/2/library/json.html#json.dump ) .
150+ output unindented json. `` .export `` accepts kwargs which pass into
151+ [ json.dumps] ( http://docs.python.org/2/library/json.html#json.dump ) .
138152
139- ``` python
153+ ``` py
140154print config.export(" json" , indent = 4 )
141155```
142156
143157** output** :
158+
144159``` json
145160{
146161 "environment" : " DEV" ,
@@ -155,20 +170,26 @@ print config.export("json", indent=4)
155170
156171`` config.export('yaml') `` also supports the [ kwargs for pyyaml] ( http://pyyaml.org/wiki/PyYAMLDocumentation#Dumper ) .
157172
158- ## cli ##
173+ ## cli
174+
159175exporting (defaults to json)
176+
160177``` sh
161178$ echo " environment: DEV" > config.yaml
162179$ kaptan config.yaml --export json > config.json
163180$ cat config.json
164181{" environment" : " DEV" }
165182```
183+
166184getting a value
185+
167186``` sh
168187$ kaptan config.yaml --key environment
169188DEV
170189```
190+
171191specifying the handler
192+
172193``` sh
173194$ mv config.yaml config.settings
174195$ kaptan config.settings --export json
@@ -178,7 +199,8 @@ RuntimeError: Unable to determine handler
178199$ kaptan config.settings --handler yaml --export json
179200{" environment" : " DEV" }
180201```
181- ## running tests ##
202+
203+ ## running tests
182204
183205With ` py.test ` :
184206
0 commit comments