Updated README and setup.py keywords. [ci skip]
This commit is contained in:
parent
d39c13fd9c
commit
91966f228b
70
README.md
70
README.md
|
@ -14,7 +14,7 @@ The Python dictionary for humans dealing with evil/complex data.
|
|||
## Features
|
||||
- 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)*
|
||||
- Give **benediction** :) to `dict` values before they are returned *(they receive benedict casting)*
|
||||
- 100% **backward-compatible** *(you can replace existing dicts without pain)*
|
||||
|
||||
## Requirements
|
||||
|
@ -27,7 +27,7 @@ The Python dictionary for humans dealing with evil/complex data.
|
|||
- Run `tox` / `python setup.py test`
|
||||
|
||||
## Usage
|
||||
`benedict` is a dict subclass, so it is possible to use it as a normal dict *(you can just cast an existing dict)*.
|
||||
`benedict` is a `dict` subclass, so it is possible to use it as a normal dictionary *(you can just cast an existing dict)*.
|
||||
|
||||
### Import
|
||||
|
||||
|
@ -49,10 +49,11 @@ 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.
|
||||
`.` is the default keypath separator.
|
||||
|
||||
```python
|
||||
d = benedict()
|
||||
|
@ -64,6 +65,7 @@ print('profile.lastname' in d) # -> True
|
|||
```
|
||||
|
||||
#### Custom keypath separator
|
||||
You can customize the keypath separator passing the `keypath_separator` argument in the constructor.
|
||||
|
||||
```python
|
||||
d = benedict(existing_dict, keypath_separator='/')
|
||||
|
@ -73,6 +75,8 @@ d = benedict(existing_dict, keypath_separator='/')
|
|||
|
||||
#### Keypath
|
||||
|
||||
- ##### keypaths
|
||||
|
||||
```python
|
||||
# Return a list of all keypaths in the dict.
|
||||
d.keypaths()
|
||||
|
@ -81,27 +85,39 @@ d.keypaths()
|
|||
#### Utility
|
||||
These methods are common utilities that will speed up your everyday work.
|
||||
|
||||
- ##### clean
|
||||
|
||||
```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.
|
||||
d.clean(strings=True, dicts=True, lists=True)
|
||||
```
|
||||
|
||||
- ##### deepcopy
|
||||
|
||||
```python
|
||||
# Return a deepcopy of the dict.
|
||||
d.deepcopy()
|
||||
```
|
||||
|
||||
- ##### dump
|
||||
|
||||
```python
|
||||
# Return a readable representation of any dict/list.
|
||||
s = benedict.dump(d.keypaths())
|
||||
print(s)
|
||||
```
|
||||
|
||||
- ##### dump_items
|
||||
|
||||
```python
|
||||
# Return a readable representation of the dict for the given key (optional).
|
||||
s = d.dump_items(key=None)
|
||||
print(s)
|
||||
```
|
||||
|
||||
- ##### filter
|
||||
|
||||
```python
|
||||
# Return a filtered dict using the given predicate function.
|
||||
# Predicate function receives key, value arguments and should return a bool value.
|
||||
|
@ -112,18 +128,24 @@ 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.
|
||||
|
||||
- ##### get_bool
|
||||
|
||||
```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`.
|
||||
d.get_bool(key, default=False)
|
||||
```
|
||||
|
||||
- ##### get_bool_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of bool values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_bool_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_datetime
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as datetime.
|
||||
# If format is not specified it will be autodetected.
|
||||
|
@ -131,35 +153,39 @@ d.get_bool_list(key, default=[], separator=',')
|
|||
d.get_datetime(key, default=None, format=None, options=[])
|
||||
```
|
||||
|
||||
- ##### get_datetime_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of datetime values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_datetime_list(key, default=[], format=None, separator=',')
|
||||
```
|
||||
|
||||
- ##### get_decimal
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as Decimal.
|
||||
# If options and value is in options return value otherwise default.
|
||||
d.get_decimal(key, default=Decimal('0.0'), options=[])
|
||||
```
|
||||
|
||||
- ##### get_decimal_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of Decimal values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_decimal_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_dict
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as dict.
|
||||
# If value is a json string it will be automatically decoded.
|
||||
d.get_dict(key, default={})
|
||||
```
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as float.
|
||||
# If options and value is in options return value otherwise default.
|
||||
d.get_float(key, default=0.0, options=[])
|
||||
```
|
||||
- ##### get_email
|
||||
|
||||
```python
|
||||
# Get email by key or keypath and return it.
|
||||
|
@ -168,54 +194,80 @@ d.get_float(key, default=0.0, options=[])
|
|||
d.get_email(key, default='', options=None, check_blacklist=True)
|
||||
```
|
||||
|
||||
- ##### get_float
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as float.
|
||||
# If options and value is in options return value otherwise default.
|
||||
d.get_float(key, default=0.0, options=[])
|
||||
```
|
||||
|
||||
- ##### get_float_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of float values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_float_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_int
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as int.
|
||||
# If options and value is in options return value otherwise default.
|
||||
d.get_int(key, default=0, options=[])
|
||||
```
|
||||
|
||||
- ##### get_int_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of int values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_int_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_list_item
|
||||
|
||||
```python
|
||||
# Get list by key or keypath and return value at the specified index.
|
||||
# If separator is specified and list value is a string it will be splitted.
|
||||
d.get_list_item(key, index=0, default=None, separator=',')
|
||||
```
|
||||
|
||||
- ##### get_phonenumber
|
||||
|
||||
```python
|
||||
# Get phone number by key or keypath and return a dict with different formats (e164, international, national).
|
||||
# If country code is specified (alpha 2 code), it will be used to parse phone number correctly.
|
||||
d.get_phonenumber(key, country_code=None, default=None)
|
||||
```
|
||||
|
||||
- ##### get_slug
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as slug.
|
||||
# If options and value is in options return value otherwise default.
|
||||
d.get_slug(key, default='', options=[])
|
||||
```
|
||||
|
||||
- ##### get_slug_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of slug values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
d.get_slug_list(key, default=[], separator=',')
|
||||
```
|
||||
|
||||
- ##### get_str
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as string.
|
||||
# Encoding issues will be automatically fixed.
|
||||
|
@ -223,6 +275,8 @@ d.get_slug_list(key, default=[], separator=',')
|
|||
d.get_str(key, default='', options=[])
|
||||
```
|
||||
|
||||
- ##### get_str_list
|
||||
|
||||
```python
|
||||
# Get value by key or keypath trying to return it as list of str values.
|
||||
# If separator is specified and value is a string it will be splitted.
|
||||
|
|
5
setup.py
5
setup.py
|
@ -32,7 +32,10 @@ setup(
|
|||
url='{}/{}'.format(github_url, package_name),
|
||||
download_url='{}/{}/archive/{}.tar.gz'.format(
|
||||
github_url, package_name, __version__),
|
||||
keywords=['benedict', 'python', 'dict', 'keypath', 'parse', 'utility'],
|
||||
keywords=[
|
||||
'python', 'dictionary', 'dict', 'subclass', 'extended',
|
||||
'benedict', 'io', 'keypath', 'parse', 'utility', 'data',
|
||||
'base64', 'json', 'querystring', 'toml', 'yaml', 'xml'],
|
||||
install_requires=[
|
||||
'ftfy==4.4.3;python_version<"3.4"',
|
||||
'ftfy;python_version>"2.7"',
|
||||
|
|
Loading…
Reference in New Issue