Skip to content

Commit

Permalink
Updated version, CHANGELOG and README.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocaccamo committed Jul 9, 2019
1 parent b9c41c1 commit 449da2a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
Expand All @@ -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'
Expand All @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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).
3 changes: 1 addition & 2 deletions benedict/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
__email__ = '[email protected]'
__license__ = 'MIT'
__title__ = 'benedict'
__version__ = '0.4.1'

__version__ = '0.5.0'

0 comments on commit 449da2a

Please sign in to comment.