Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 631ff55

Browse files
committed
Beautified Markdown.
1 parent 1885074 commit 631ff55

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ $ pip install kaptan
1313
or 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
2628
config = kaptan.Kaptan()
2729
config.import_config({
2830
'environment': 'DEV',
@@ -36,10 +38,12 @@ config.import_config({
3638

3739
print config.get("pagination.limit")
3840

39-
#output: 20
41+
# output: 20
4042
```
43+
4144
**json handler**
42-
```python
45+
46+
```py
4347
config = kaptan.Kaptan(handler="json")
4448
config.import_config('{"everything": 42}')
4549

@@ -48,7 +52,8 @@ print config.get("everything")
4852
```
4953

5054
**yaml handler**
51-
```python
55+
56+
```py
5257
config = kaptan.Kaptan()
5358
config.import_config("""
5459
product:
@@ -64,13 +69,14 @@ print config.get("product.price.currency_list.0")
6469

6570
or you can get from directly from the filename:
6671

67-
```python
72+
```py
6873
config.import_config("configuration.yaml")
6974
```
7075

7176
**.ini handler**
7277

7378
config.ini
79+
7480
```ini
7581
[development]
7682
database_uri = mysql://root:123456@localhost/posts
@@ -79,33 +85,38 @@ database_uri = mysql://root:123456@localhost/posts
7985
database_uri = mysql://poor_user:poor_password@localhost/poor_posts
8086
```
8187

82-
```python
88+
```py
8389
config = kaptan.Kaptan(handler="ini")
8490
config.import_config('config.ini')
8591

8692
print 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

9198
config.py
92-
```python
99+
100+
```py
93101
DATABASE = 'mysql://root:123456@localhost/posts'
94102
DEBUG = False
95103
PAGINATION = {
96104
'per_page': 10,
97105
'limit': 20,
98106
}
99107
```
100-
```python
108+
109+
```py
101110
config = kaptan.Kaptan(handler="file")
102111
config.import_config('config')
103112

104113
print config.get("DEBUG")
105114
# output: False
106115
```
107-
## exporting configuration ##
108-
```python
116+
117+
## exporting configuration
118+
119+
```py
109120
config = kaptan.Kaptan(handler="file")
110121
config.import_config({
111122
'environment': 'DEV',
@@ -119,28 +130,32 @@ config.import_config({
119130

120131
```
121132

122-
```python
133+
```py
123134
print config.export("yaml")
124135
```
136+
125137
**output**:
126-
```
138+
139+
```yaml
127140
debug: false
128141
environment: DEV
129142
pagination: {limit: 20, per_page: 10}
130143
redis_uri: redis://localhost:6379/0
131144
```
132145
133-
```python
146+
```py
134147
print 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
140154
print 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+
159175
exporting (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+
166184
getting a value
185+
167186
```sh
168187
$ kaptan config.yaml --key environment
169188
DEV
170189
```
190+
171191
specifying 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

183205
With `py.test`:
184206

0 commit comments

Comments
 (0)