-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b43446b
commit bb402bf
Showing
1 changed file
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
[![Build Status](https://travis-ci.org/simongarisch/yamlsettings.svg?branch=master)](https://travis-ci.org/simongarisch/yamlsettings) | ||
[![Coverage Status](https://coveralls.io/repos/github/simongarisch/yamlsettings/badge.svg?branch=master)](https://coveralls.io/github/simongarisch/yamlsettings?branch=master) | ||
|
||
# yamlsettings | ||
|
||
Flyweight pattern for loading yaml settings files in Python. | ||
A Flyweight pattern for loading yaml files in Python. | ||
|
||
## Installation | ||
yamlsettings is python 2 and 3 compatible. | ||
```bash | ||
pip install yamlsettings | ||
``` | ||
|
||
## Overview | ||
There is a YamlSettings class exposed by the package that allows you to load and query yaml files. | ||
Suppose we have a yaml file with the structure: | ||
``` | ||
att1: 42 | ||
att2: "This is a string" | ||
level1: | ||
a: 1 | ||
b: 2 | ||
level2: | ||
a: 3 | ||
b: 4 | ||
``` | ||
|
||
We can load this file | ||
```python | ||
import os | ||
import yamlsettings | ||
|
||
yaml_file_path = os.path.join("tests", "test_yaml_file.yaml") | ||
settings = yamlsettings.YamlSettings(yaml_file_path) | ||
``` | ||
|
||
And read particular items with: | ||
```python | ||
result = settings.get_data("att1") | ||
print(result) # 42 | ||
|
||
result = settings.get_data("level1", "level2", "b") | ||
print(result) # 4 | ||
``` |