From 449da2a332df23757a98a59cfa2a4a358766c5e8 Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Tue, 9 Jul 2019 16:04:36 +0200 Subject: [PATCH] Updated version, CHANGELOG and README. --- CHANGELOG.md | 5 +++++ README.md | 49 +++++++++++++++++++++++++++++++++++++------- benedict/metadata.py | 3 +-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7415e382..8a6be011 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.0](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.5.0) - 2019-07-09 +- Added custom or `None` keypath `separator` support. +- Added `filter` utility method. +- Improved tests and code quality. + ## [0.4.2](https://github.com/fabiocaccamo/python-benedict/releases/tag/0.4.2) - 2019-06-19 - Fixed `parse_str` UnicodeEncodeError on python 2. diff --git a/README.md b/README.md index aa7135e1..1b352916 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The Python dictionary for humans dealing with evil/complex data. ## Features -- Full **keypath** support *(using the dot syntax)* +- Full **keypath** support *(using the dot syntax by default)* - Many **utility** and **parse methods** to retrieve data as needed *(all methods listed below)* - Give **benediction to dict objects** before they are returned *(they receive benedict casting)* - 100% **backward-compatible** *(you can replace existing dicts without pain)* @@ -29,11 +29,32 @@ The Python dictionary for humans dealing with evil/complex data. ## Usage `benedict` is a dict subclass, so it is possible to use it as a normal dict *(you can just cast an existing dict)*. -### Basic get/set using keypath +### Import ```python from benedict import benedict +``` + +### Init +Create a new instance: +```python +d = benedict() +``` + +... or cast an existing `dict`: + +```python +d = benedict(existing_dict) +``` + +If the existing dict keys contain the keypath separator a `ValueError` will be raised. +In this case you need to use a [custom keypath separator](#custom-keypath-separator). + +### Keypath +`.` is the default keypath separator, you can customize it passing the `keypath_separator` argument in the constructor. + +```python d = benedict() d['profile.firstname'] = 'Fabio' d['profile.lastname'] = 'Caccamo' @@ -42,8 +63,24 @@ print(d['profile']) # -> { 'firstname':'Fabio', 'lastname':'Caccamo' } print('profile.lastname' in d) # -> True ``` +#### Custom keypath separator + +```python +d = benedict(existing_dict, keypath_separator='/') +``` + ### API +#### Keypath + +```python +# Return a list of all keypaths in the dict. +d.keypaths() +``` + +#### Utility +These methods are common utilities that will speed up your everyday work. + ```python # Clean the current dict removing all empty values: None, '', {}, [], (). # If strings, dicts or lists flags are False, related empty values will not be deleted. @@ -72,6 +109,9 @@ predicate = lambda k, v: v is not None d.filter(predicate) ``` +#### Parse methods +These methods are wrappers of the `get` method, and they will parse data trying to return it in the expected type. + ```python # Get value by key or keypath trying to return it as bool. # Values like `1`, `true`, `yes`, `on`, `ok` will be returned as `True`. @@ -189,10 +229,5 @@ d.get_str(key, default='', options=[]) d.get_str_list(key, default=[], separator=',') ``` -```python -# Return a list of all keypaths in the dict. -d.keypaths() -``` - ## License Released under [MIT License](LICENSE.txt). \ No newline at end of file diff --git a/benedict/metadata.py b/benedict/metadata.py index 26b054d8..47917d09 100644 --- a/benedict/metadata.py +++ b/benedict/metadata.py @@ -6,5 +6,4 @@ __email__ = 'fabio.caccamo@gmail.com' __license__ = 'MIT' __title__ = 'benedict' -__version__ = '0.4.1' - +__version__ = '0.5.0'