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 an incoming dictionary based on schema rules
  2. Get the dictionary value and cast string representation to target data type
  3. Available types:

"object": raw object

"str": textual data

"int": integer numeric type

"float": float numeric type

"decimal": decimal numeric type

"list": list sequence type

"datetime": a datetime object is a single object containing all the information from a date object and a time object

"date": a date object represents a date (year, month and day)

"bool": boolean values are the two constant objects False and True

  1. Set default value if result is None
  2. Get the required dictionary value and cast it to data type
  3. 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.

Source Distribution

power_dict-0.0.13.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

power_dict-0.0.13-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file power_dict-0.0.13.tar.gz.

File metadata

  • Download URL: power_dict-0.0.13.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for power_dict-0.0.13.tar.gz
Algorithm Hash digest
SHA256 ef1ed0a53f99b714ed67daf01b2d2c39b8e52b7afb0252ce7e3eb90037ee6c81
MD5 ac18e3d4e28e4aeabdcab454832f45a6
BLAKE2b-256 96627f6e4db4e28d08cebc9d5ac59b2cdc8bfa15bd8c63dccd349396bf57c9fd

See more details on using hashes here.

File details

Details for the file power_dict-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: power_dict-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for power_dict-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 47a6ae34d17475f1e5992cab2cf904ccd058352c6cd3e903fce61f631b7020f0
MD5 8cf28761e5e0fae48cffe3c05f6629ec
BLAKE2b-256 377ace833a83e5a6230f5cf3d6b9ddda640bc58dc8d092b4f7a8e01109ced9eb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page