Skip to main content

Library for easy work with the python dictionary

Project description

What's the good of that?

PyPI version Supported Python versions License

  1. Validate and transform dict schema
  2. Get the dictionary value and cast it to data type
  3. Set default value if result is None
  4. Get the required dictionary value and cast it to data type
  5. Get the required dictionary value and raise error if value is empty

install

pip install power-dict

import

from power_dict.utils import DictUtils

Run unittest from console

python -m unittest discover -p "*_tests.py"

SchemaValidator.validate(context: dict, schema: list, sanitize_schema: bool = True) -> dict

Validation and transformation of 'context' dictionary in accordance with the rules of the scheme. See tests for examples.

DictUtils.get_value(properties: dict, key: str, **kwargs) -> object

Get the dictionary value and cast it to object. See tests for examples.

DictUtils.get_required_value(properties: dict, key: str, **kwargs) -> object

Get the required dictionary value and cast it to object. See tests for examples.

DictUtils.get_setting_by_path(properties: dict, path: str, **kwargs) -> object

Get the dictionary value and cast it to object by path. See tests for examples.

DictUtils.get_dict_property(properties: dict, key: str, default_value=None) -> object

Get the dictionary value. See tests for examples.

DictUtils.get_required_dict_property(properties: dict, key: str, required_error=None) -> object

Get the required dictionary value. See tests for examples.

DictUtils.get_str_dict_property(properties: dict, key: str, default_value='') -> str

Get the dictionary value and cast it to 'str'. See tests for examples.

DictUtils.get_required_str_dict_property(properties: dict, key: str, required_error=None) -> str

Get the required dictionary value and cast it to 'str'. See tests for examples.

DictUtils.get_int_dict_property(properties: dict, key: str, default_value=None) -> int

Get the dictionary value and cast it to 'int'. See tests for examples.

DictUtils.get_required_int_dict_property(properties: dict, key: str, required_error=None) -> int

Get the required dictionary value and cast it to 'int'. See tests for examples.

DictUtils.get_datetime_dict_property(properties: dict, key: str, default_value: datetime = None, format: str = None) -> datetime

Get the dictionary value and cast it to 'datetime'. See tests for examples. Format Codes.

DictUtils.get_required_datetime_dict_property(properties: dict, key: str, required_error=None, format: str = None) -> datetime

Get the required dictionary value and cast it to 'datetime'. See tests for examples. Format Codes.

DictUtils.get_date_dict_property(properties: dict, key: str, default_value=None, format: str = None) -> datetime.date

Get the dictionary value and cast it to 'date'. See tests for examples. Format Codes.

DictUtils.get_required_date_dict_property(properties: dict, key: str, required_error=None, format: str = None) -> datetime.date

Get the required dictionary value and cast it to 'date'. See tests for examples. Format Codes.

DictUtils.get_bool_dict_property(properties: dict, key: str, default_value=None) -> bool

Get the dictionary value and cast it to 'bool'. See tests for examples.

DictUtils.get_required_bool_dict_property(properties: dict, key: str, required_error=None) -> bool

Get the required dictionary value and cast it to 'bool'. See tests for examples.

DictUtils.get_decimal_dict_property(properties: dict, key: str, default_value=None) -> Decimal

Get the dictionary value and cast it to 'decimal'. See tests for examples.

DictUtils.get_required_decimal_dict_property(properties: dict, key: str, required_error=None) -> Decimal

Get the required dictionary value and cast it to 'decimal'. See tests for examples.

DictUtils.get_list_dict_property(properties: dict, key: str, default_value=None) -> list

Get the dictionary value and cast it to 'list'. See tests for examples.

DictUtils.get_required_list_dict_property(properties: dict, key: str, required_error=None) -> list

Get the required dictionary value and cast it to 'list'. See tests for examples.

DictUtils.get_float_dict_property(properties: dict, key: str, default_value=None) -> float

Get the dictionary value and cast it to 'float'. See tests for examples.

DictUtils.get_required_float_dict_property(properties: dict, key: str, required_error=None) -> float

Get the required dictionary value and cast it to 'float'. See tests for examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for power-dict, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size power_dict-0.0.4-py3-none-any.whl (15.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size power_dict-0.0.4.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page