Skip to content

Commit d2da6a2

Browse files
committed
Updated README, CHANGELOG and version.
1 parent 4f86048 commit d2da6a2

File tree

3 files changed

+54
-20
lines changed

3 files changed

+54
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ 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.13.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.13.0) - 2019-11-07
8+
- Added `csv` I/O support.
9+
- Refactored I/O dict class and utils.
10+
- Improved tests.
11+
712
## [0.12.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.12.0) - 2019-10-29
813
- Added `standardize` utility method.
914
- Added `traverse` utility method.

README.md

Lines changed: 47 additions & 18 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 (`Base64`, `JSON`, `TOML`, `XML`, `YAML`, `query-string`) and many **utilities**... for humans, obviously.
12+
python-benedict is a dict subclass with **keypath** support, **I/O** shortcuts (`Base64`, `CSV`, `JSON`, `TOML`, `XML`, `YAML`, `query-string`) and many **utilities**... for humans, obviously.
1313

1414
## Index
1515
- [Features](#features)
@@ -42,12 +42,14 @@ python-benedict is a dict subclass with **keypath** support, **I/O** shortcuts (
4242
- [`unique`](#unique)
4343
- [I/O](#io)
4444
- [`from_base64`](#from_base64)
45+
- [`from_csv`](#from_csv)
4546
- [`from_json`](#from_json)
4647
- [`from_query_string`](#from_query_string)
4748
- [`from_toml`](#from_toml)
4849
- [`from_xml`](#from_xml)
4950
- [`from_yaml`](#from_yaml)
5051
- [`to_base64`](#to_base64)
52+
- [`to_csv`](#to_csv)
5153
- [`to_json`](#to_json)
5254
- [`to_query_string`](#to_query_string)
5355
- [`to_toml`](#to_toml)
@@ -78,7 +80,7 @@ python-benedict is a dict subclass with **keypath** support, **I/O** shortcuts (
7880

7981
## Features
8082
- Full **keypath** support using **keypath-separator** *(dot syntax by default)* or **list of keys**.
81-
- Easy **I/O operations** with most common formats: `Base64`, `JSON`, `TOML`, `XML`, `YAML`, `query-string`
83+
- Easy **I/O operations** with most common formats: `Base64`, `CSV`, `JSON`, `TOML`, `XML`, `YAML`, `query-string`
8284
- Many **utility** and **parse methods** to retrieve data as needed *(all methods listed below)*
8385
- Well **tested**, check the badges ;)
8486
- 100% **backward-compatible** *(you can replace existing dicts without pain)*
@@ -333,30 +335,45 @@ d.unique()
333335

334336
### I/O
335337

336-
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.
338+
It is possible to create a `benedict` instance directly from data source (filepath, url or data-string) by passing the data source and the data format (default 'json') in the constructor.
337339

338340
```python
339341
# filepath
340-
d = benedict('/root/data.yml')
342+
d = benedict('/root/data.yml', format='yaml')
341343

342344
# url
343-
d = benedict('https://localhost:8000/data.xml')
345+
d = benedict('https://localhost:8000/data.xml', format='xml')
344346

345347
# data-string
346348
d = benedict('{"a": 1, "b": 2, "c": 3, "x": 7, "y": 8, "z": 9}')
347349
```
348350

349-
These methods simplify I/O operations with most common formats: `base64`, `json`, `toml`, `xml`, `yaml`, `query-string`
351+
These methods simplify I/O operations with most common formats: `base64`, `csv`, `json`, `toml`, `xml`, `yaml`, `query-string`
352+
353+
In all `from_*` methods, the first argument can be: **url**, **filepath** or **data-string**.
354+
355+
In all `to_*` methods, if `filepath='...'` kwarg is specified, the output will be also **saved** at the specified filepath.
350356

351357
- #### from_base64
352358

353359
```python
354360
# Try to load/decode a base64 encoded data and return it as benedict instance.
355361
# Accept as first argument: url, filepath or data-string.
356-
# It's possible to choose the format used under the hood ('json', 'toml', 'xml', 'yaml') default 'json'.
357-
# It's possible to pass decoder specific options using kwargs.
362+
# It's possible to choose the subformat used under the hood (`csv`, `json`, `query-string`, `toml`, `xml`, `yaml`), default: 'json'.
363+
# It's possible to choose the encoding, default 'utf-8'.
358364
# A ValueError is raised in case of failure.
359-
d = benedict.from_base64(s, format='json', **kwargs)
365+
d = benedict.from_base64(s, subformat='json', encoding='utf-8', **kwargs)
366+
```
367+
368+
- #### from_csv
369+
370+
```python
371+
# Try to load/decode a csv encoded data and return it as benedict instance.
372+
# Accept as first argument: url, filepath or data-string.ù
373+
# It's possible to specify the columns list, default: None (in this case the first row values will be used as keys).
374+
# It's possible to pass decoder specific options using kwargs: https://docs.python.org/3/library/csv.html
375+
# A ValueError is raised in case of failure.
376+
d = benedict.from_csv(s, columns=None, columns_row=True, **kwargs)
360377
```
361378

362379
- #### from_json
@@ -411,11 +428,22 @@ d = benedict.from_yaml(s, **kwargs)
411428
- #### to_base64
412429

413430
```python
414-
# Return the dict instance encoded in base64 format and optionally save it at the specified filepath.
415-
# It's possible to choose the format used under the hood ('json', 'toml', 'xml', 'yaml') default 'json'.
431+
# Return the dict instance encoded in base64 format and optionally save it at the specified 'filepath'.
432+
# It's possible to choose the subformat used under the hood ('csv', json', `query-string`, 'toml', 'xml', 'yaml'), default: 'json'.
433+
# It's possible to choose the encoding, default 'utf-8'.
416434
# It's possible to pass decoder specific options using kwargs.
417435
# A ValueError is raised in case of failure.
418-
s = d.to_base64(filepath='', format='json', **kwargs)
436+
s = d.to_base64(subformat='json', encoding='utf-8', **kwargs)
437+
```
438+
439+
- #### to_csv
440+
441+
```python
442+
# Return a list of dicts encoded in csv format and optionally save it at the specified filepath.
443+
# It's possible to specify the key of the item (list of dicts) to encode, default: 'values'.
444+
# It's possible to specify the columns list, default: None (in this case the keys of the first item will be used).
445+
# A ValueError is raised in case of failure.
446+
d = benedict.to_csv(key='values', columns=None, columns_row=True, **kwargs)
419447
```
420448

421449
- #### to_json
@@ -424,15 +452,15 @@ s = d.to_base64(filepath='', format='json', **kwargs)
424452
# Return the dict instance encoded in json format and optionally save it at the specified filepath.
425453
# It's possible to pass encoder specific options using kwargs: https://docs.python.org/3/library/json.html
426454
# A ValueError is raised in case of failure.
427-
s = d.to_json(filepath='', **kwargs)
455+
s = d.to_json(**kwargs)
428456
```
429457

430458
- #### to_query_string
431459

432460
```python
433461
# Return the dict instance as query-string and optionally save it at the specified filepath.
434462
# A ValueError is raised in case of failure.
435-
s = d.to_query_string(filepath='', **kwargs)
463+
s = d.to_query_string(**kwargs)
436464
```
437465

438466
- #### to_toml
@@ -441,7 +469,7 @@ s = d.to_query_string(filepath='', **kwargs)
441469
# Return the dict instance encoded in toml format and optionally save it at the specified filepath.
442470
# It's possible to pass encoder specific options using kwargs: https://pypi.org/project/toml/
443471
# A ValueError is raised in case of failure.
444-
s = d.to_toml(filepath='', **kwargs)
472+
s = d.to_toml(**kwargs)
445473
```
446474

447475
- #### to_xml
@@ -450,16 +478,17 @@ s = d.to_toml(filepath='', **kwargs)
450478
# Return the dict instance encoded in xml format and optionally save it at the specified filepath.
451479
# It's possible to pass encoder specific options using kwargs: https://github.com/martinblech/xmltodict
452480
# A ValueError is raised in case of failure.
453-
s = d.to_xml(filepath='', **kwargs)
481+
s = d.to_xml(**kwargs)
454482
```
455483

456484
- #### to_yaml
457485

458486
```python
459-
# Return the dict instance encoded in yaml format and optionally save it at the specified filepath.
487+
# Return the dict instance encoded in yaml format.
488+
# If filepath option is passed the output will be saved ath
460489
# It's possible to pass encoder specific options using kwargs: https://pyyaml.org/wiki/PyYAMLDocumentation
461490
# A ValueError is raised in case of failure.
462-
s = d.to_yaml(filepath='', **kwargs)
491+
s = d.to_yaml(**kwargs)
463492
```
464493

465494
### Parse

benedict/metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
__author__ = 'Fabio Caccamo'
44
__copyright__ = 'Copyright (c) 2019 Fabio Caccamo'
5-
__description__ = 'python-benedict is a dict subclass with keypath support, I/O shortcuts (Base64, JSON, TOML, XML, YAML, query-string) and many utilities... for humans, obviously.'
5+
__description__ = 'python-benedict is a dict subclass with keypath support, I/O shortcuts (Base64, CSV, JSON, TOML, XML, YAML, query-string) and many utilities... for humans, obviously.'
66
__email__ = 'fabio.caccamo@gmail.com'
77
__license__ = 'MIT'
88
__title__ = 'benedict'
9-
__version__ = '0.12.0'
9+
__version__ = '0.13.0'

0 commit comments

Comments
 (0)