https://github.com/roverdotcom/snagsby-py
https://github.com/roverdotcom/snagsby-py
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/roverdotcom/snagsby-py
- Owner: roverdotcom
- License: mit
- Created: 2016-10-19T02:34:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-07-09T18:56:02.000Z (almost 5 years ago)
- Last Synced: 2025-05-20T19:29:35.064Z (about 1 year ago)
- Language: Python
- Size: 32.2 KB
- Stars: 2
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Snagsby(py) [](https://travis-ci.org/roverdotcom/snagsby-py)
Python module implementing snagsby - https://github.com/roverdotcom/snagsby
Snagsby reads configuration from a json object in s3, formats it in a way
that can easily be injected into `os.environ`, and injects the keys and values
into the destination of your choice, `os.environ` being the default.
## Usage
```javascript
// An example configuration file uploaded to S3
// s3://test-bucket/config.json
{
"will_upcase": "Keys will be upper cased",
"wil ignore with spaces": "Keys with spaces will be ignored",
"NUM": 7.777,
"YES": true,
"NO": false,
"NESTED": {
"OBJECT": "nested"
}
}
```
Load s3://test-bucket/config.json with snagsby
```python
import os
import pprint
import snagsby
out = {}
os.environ['SNAGSBY_SOURCE'] = "s3://test-bucket/config.json"
# The default dest is os.environ
snagsby.load(dest=out)
pprint.pprint(out)
```
The following is what would be injected into `out`:
```python
{'NO': '0',
'NUM': '7.777',
'WILL_UPCASE': 'Keys will be upper cased',
'YES': '1'}
```
Source is a whitespace separated list of s3 locations
```python
import snagsby
snagsby.load(
source="s3://bucket/one.json, s3://bucket/two.json",
)
```
By default snagsby loads the source specified in the `SNAGSBY_SOURCE` environment variable into `os.environ`
```python
import os
import snagsby
snagsby.load()
print(os.environ['NUM']) => u'7.777'
```