Skip to content

Commit c597867

Browse files
committed
Updated README, CHANGELOG and version.
1 parent 07e6476 commit c597867

3 files changed

Lines changed: 134 additions & 81 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.10.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.10.0) - 2019-10-03
8+
- Added `base64` I/O support.
9+
- Added `invert` utility method.
10+
- Added `items_sorted_by_keys` utility method.
11+
- Added `items_sorted_by_values` utility method.
12+
- Refactored `benedict` class and utilies.
13+
714
## [0.9.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.9.0) - 2019-09-23
815
- Added `xml` I/O support.
916

README.md

Lines changed: 126 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[![License](https://img.shields.io/pypi/l/python-benedict.svg)](https://img.shields.io/pypi/l/python-benedict.svg)
1010

1111
# python-benedict
12-
python-benedict is a dict subclass with keypath support, I/O shortcuts (json, toml, xml, yaml) and many utilities... for humans, obviously.
12+
python-benedict is a dict subclass with **keypath* support, **I/O** shortcuts (BASE64, JSON, TOML, XML, YAML) and many **utilities**... for humans, obviously.
1313

1414
## Index
1515
- [Features](#features)
@@ -22,11 +22,25 @@ python-benedict is a dict subclass with keypath support, I/O shortcuts (json, to
2222
- [Custom keypath separator](#custom-keypath-separator)
2323
- [Disable keypath functionality](#disable-keypath-functionality)
2424
- [API](#api)
25+
- [Utility](#utility)
26+
- [`clean`](#clean)
27+
- [`clone`](#clone)
28+
- [`dump`](#dump)
29+
- [`filter`](#filter)
30+
- [`flatten`](#flatten)
31+
- [`invert`](#invert)
32+
- [`items_sorted_by_keys`](#items_sorted_by_keys)
33+
- [`items_sorted_by_values`](#items_sorted_by_values)
34+
- [`merge`](#merge)
35+
- [`remove`](#remove)
36+
- [`subset`](#subset)
2537
- [I/O](#io)
38+
- [`from_base64`](#from_base64)
2639
- [`from_json`](#from_json)
2740
- [`from_toml`](#from_toml)
2841
- [`from_xml`](#from_xml)
2942
- [`from_yaml`](#from_yaml)
43+
- [`to_base64`](#to_base64)
3044
- [`to_json`](#to_json)
3145
- [`to_toml`](#to_toml)
3246
- [`to_xml`](#to_xml)
@@ -51,15 +65,7 @@ python-benedict is a dict subclass with keypath support, I/O shortcuts (json, to
5165
- [`get_slug_list`](#get_slug_list)
5266
- [`get_str`](#get_str)
5367
- [`get_str_list`](#get_str_list)
54-
- [Utility](#utility)
55-
- [`clean`](#clean)
56-
- [`clone`](#clone)
57-
- [`dump`](#dump)
58-
- [`filter`](#filter)
59-
- [`flatten`](#flatten)
60-
- [`merge`](#merge)
61-
- [`remove`](#remove)
62-
- [`subset`](#subset)
68+
6369
- [Testing](#testing)
6470
- [License](#license)
6571

@@ -91,7 +97,7 @@ d = benedict()
9197
# or cast an existing dict
9298
d = benedict(existing_dict)
9399

94-
# or create from data source (filepath, url or data-string) in a supported format (json, toml, xml, yaml)
100+
# or create from data source (filepath, url or data-string) in a supported format (base64, json, toml, xml, yaml)
95101
d = benedict('https://localhost:8000/data.json')
96102

97103
# or in a Django view
@@ -147,6 +153,97 @@ d = benedict(existing_dict, keypath_separator=None)
147153

148154
## API
149155

156+
#### Utility
157+
These methods are common utilities that will speed up your everyday work.
158+
159+
- ##### clean
160+
161+
```python
162+
# Clean the current dict removing all empty values: None, '', {}, [], ().
163+
# If strings, dicts or lists flags are False, related empty values will not be deleted.
164+
d.clean(strings=True, dicts=True, lists=True)
165+
```
166+
167+
- ##### clone
168+
169+
```python
170+
# Return a clone (deepcopy) of the dict.
171+
c = d.clone()
172+
```
173+
174+
- ##### dump
175+
176+
```python
177+
# Return a readable representation of any dict/list.
178+
# This method can be used both as static method or instance method.
179+
s = benedict.dump(d.keypaths())
180+
print(s)
181+
# or
182+
d = benedict()
183+
print(d.dump())
184+
```
185+
186+
- ##### filter
187+
188+
```python
189+
# Return a filtered dict using the given predicate function.
190+
# Predicate function receives key, value arguments and should return a bool value.
191+
predicate = lambda k, v: v is not None
192+
f = d.filter(predicate)
193+
```
194+
195+
- ##### flatten
196+
197+
```python
198+
# Return a flatten dict using the given separator to concat nested dict keys.
199+
f = d.flatten(separator='_')
200+
```
201+
202+
- ##### invert
203+
204+
```python
205+
# Return an inverted dict swapping values with keys.
206+
# Since multiple keys could have the same value, each value will be a list.
207+
# If flat is True each value will be a single value.
208+
i = d.invert(flat=False)
209+
```
210+
211+
- ##### items_sorted_by_keys
212+
213+
```python
214+
# Return items ((key, value, ) list) sorted by keys, if reverse is True, the list will be reversed.
215+
items = d.items_sorted_by_keys(reverse=False)
216+
```
217+
218+
- ##### items_sorted_by_values
219+
220+
```python
221+
# Return items ((key, value, ) list) sorted by values, if reverse is True, the list will be reversed.
222+
items = d.items_sorted_by_values(reverse=False)
223+
```
224+
225+
- ##### merge
226+
227+
```python
228+
# Merge one or more dictionary objects into current instance (deepupdate).
229+
# Sub-dictionaries keys will be merged toghether.
230+
d.merge(a, b, c)
231+
```
232+
233+
- ##### remove
234+
235+
```python
236+
# Remove multiple keys from the dict.
237+
d.remove(['firstname', 'lastname', 'email'])
238+
```
239+
240+
- ##### subset
241+
242+
```python
243+
# Return a dict subset for the given keys.
244+
s = d.subset(['firstname', 'lastname', 'email'])
245+
```
246+
150247
### I/O
151248

152249
It is possible to create a `benedict` instance directly from data source (filepath, url or data-string) by passing the data source as first argument in the constructor.
@@ -162,7 +259,16 @@ d = benedict('https://localhost:8000/data.xml')
162259
d = benedict('{"a": 1, "b": 2, "c": 3, "x": 7, "y": 8, "z": 9}')
163260
```
164261

165-
These methods simplify I/O operations with most common formats: `json`, `toml`, `xml`, `yaml`
262+
These methods simplify I/O operations with most common formats: `base64`, `json`, `toml`, `xml`, `yaml`
263+
264+
- ##### from_base64
265+
266+
```python
267+
# Try to load/decode a base64 encoded data and return it as benedict instance.
268+
# Accept as first argument: url, filepath or data-string.
269+
# A ValueError is raised in case of failure.
270+
d = benedict.from_base64(s, **kwargs)
271+
```
166272

167273
- ##### from_json
168274

@@ -204,6 +310,14 @@ d = benedict.from_xml(s, **kwargs)
204310
d = benedict.from_yaml(s, **kwargs)
205311
```
206312

313+
- ##### to_base64
314+
315+
```python
316+
# Return the dict instance encoded in base64 format and optionally save it at the specified filepath.
317+
# A ValueError is raised in case of failure.
318+
s = d.to_base64(filepath='', **kwargs)
319+
```
320+
207321
- ##### to_json
208322

209323
```python
@@ -398,74 +512,6 @@ d.get_str(key, default='', options=[])
398512
d.get_str_list(key, default=[], separator=',')
399513
```
400514

401-
#### Utility
402-
These methods are common utilities that will speed up your everyday work.
403-
404-
- ##### clean
405-
406-
```python
407-
# Clean the current dict removing all empty values: None, '', {}, [], ().
408-
# If strings, dicts or lists flags are False, related empty values will not be deleted.
409-
d.clean(strings=True, dicts=True, lists=True)
410-
```
411-
412-
- ##### clone
413-
414-
```python
415-
# Return a clone (deepcopy) of the dict.
416-
c = d.clone()
417-
```
418-
419-
- ##### dump
420-
421-
```python
422-
# Return a readable representation of any dict/list.
423-
# This method can be used both as static method or instance method.
424-
s = benedict.dump(d.keypaths())
425-
print(s)
426-
# or
427-
d = benedict()
428-
print(d.dump())
429-
```
430-
431-
- ##### filter
432-
433-
```python
434-
# Return a filtered dict using the given predicate function.
435-
# Predicate function receives key, value arguments and should return a bool value.
436-
predicate = lambda k, v: v is not None
437-
f = d.filter(predicate)
438-
```
439-
440-
- ##### flatten
441-
442-
```python
443-
# Return a flatten dict using the given separator to concat nested dict keys.
444-
f = d.flatten(separator='_')
445-
```
446-
447-
- ##### merge
448-
449-
```python
450-
# Merge one or more dictionary objects into current instance (deepupdate).
451-
# Sub-dictionaries keys will be merged toghether.
452-
d.merge(a, b, c)
453-
```
454-
455-
- ##### remove
456-
457-
```python
458-
# Remove multiple keys from the dict.
459-
d.remove(['firstname', 'lastname', 'email'])
460-
```
461-
462-
- ##### subset
463-
464-
```python
465-
# Return a dict subset for the given keys.
466-
s = d.subset(['firstname', 'lastname', 'email'])
467-
```
468-
469515
## Testing
470516
- Run `tox` / `python setup.py test`
471517

benedict/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
__email__ = 'fabio.caccamo@gmail.com'
77
__license__ = 'MIT'
88
__title__ = 'benedict'
9-
__version__ = '0.9.0'
9+
__version__ = '0.10.0'

0 commit comments

Comments
 (0)