Skip to main content

Safe casting of Python base types

Project description

safe-cast

Safe casting of Python base types.

Badges

docs

Documentation Status License

info

Hit Count Contributors

tests

travis Code Coverage Status

package

PyPI Package latest release Supported versions

other

Requirements Status

Functions

Function

Purpose

safe_cast(val, to_type, default=None)

Cast value to requested type, if failed, then used default.

safe_str(val, default=None)

Cast value to type string, if failed, then used default.

safe_float(val, ndigits=2, default=None)

Cast value to type float, if failed, then used default.

safe_int(val, default=None)

Cast value to type int, if failed, then used default.

safe_dict(val, default=None)

Cast value to type dictionary, if failed, then used default.

safe_smart_cast(val)

Determine type based upon value, and cast to that type.

safe_cost(val)

Cast value to type float by 4 decimal points.

Usage

safe_cast(val, to_type, default=None)

Safely cast a value to type, and if failed, returned default if exists.

Optional: Pass default value. Returned if casting fails.

param val:

Value to be cast.

param to_type:

Safely cast to a specific type.

param default:

Default if casting fails.

return:

Return casted value or default.

safe_int(val, default=None)

Safely cast a value to an integer.

Optional: Pass default value. Returned if casting fails.

param val:

Value to be cast to int.

param default:

Default if casting fails.

return:

Return int casted value or default.

safe_float(val, ndigits=2, default=None)

Safely cast a value to float, remove ‘,’ if exists to ensure strings “1,234.5” are transformed to become “1234.5”.

Optional: Pass default value. Returned if casting fails.

param val:

Value to be cast to float.

param ndigits:

Number of digits in float.

param default:

Default if casting fails.

return:

Return float casted value or default.

safe_str(val, default=None)

Safely cast a value to a string.

Optional: Pass default value. Returned if casting fails.

param val:

Value to be cast to string.

param default:

Default if casting fails.

return:

Return string casted value or default.

safe_dict(val, default=None)

Safely cast a value to a dictionary.

Optional: Pass default value. Returned if casting fails.

param val:

Value to be cast to dictionary.

param default:

Default if casting fails.

return:

Return dictionary casted value or default.

safe_smart_cast(val)

Safely cast a value to the best matching type. Optional: Pass default value. Returned if casting fails.

param val:

Value to be smartly cast.

return:

Typed value

Release History

0.2.3 (2017-12-10)

  • readthedocs.org

0.2.0 (2017-12-05)

  • README

0.1.3 (2017-10-31)

  • Added comments.

0.1.2 (2017-10-19)

  • Update requirements.txt

0.1.1 (2017-03-15)

  • Handle empty string -> int/float/dict casting

  • Added relevant testing

0.1.0 (2017-03-14)

  • Production ready

  • Cleanup

0.0.9 (2017-03-14)

  • Handle None input

0.0.8 (2017-03-12)

  • Rename package to ‘safe-cast’

0.0.7 (2017-03-09)

  • Renamed inner package folder to underscore: ‘smart_cast. To comply with Python standard.

  • Updated casting logic

  • Updated testing

  • Activate Continues deployment and testing with Travis.CI

  • Activate coverage testing: Coveralls.io

0.0.6 (2017-03-08)

  • Renamed from ‘safecast’ to ‘smart-cast’

0.0.1 (2017-03-07)

  • Conception

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

safe-cast-0.2.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distributions

safe_cast-0.2.3-py3.6.egg (5.4 kB view details)

Uploaded Source

safe_cast-0.2.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file safe-cast-0.2.3.tar.gz.

File metadata

  • Download URL: safe-cast-0.2.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for safe-cast-0.2.3.tar.gz
Algorithm Hash digest
SHA256 075f2ddb510041e1e3f61b17e7c4f55a11b50d07755b0230388b407d3d77780a
MD5 e6c427c36408e45784a980ee7bd4ad7c
BLAKE2b-256 a2d1a30efb408a52049813ea98355bb2b77aa684d25abbf554c3ba7aa27c4096

See more details on using hashes here.

File details

Details for the file safe_cast-0.2.3-py3.6.egg.

File metadata

File hashes

Hashes for safe_cast-0.2.3-py3.6.egg
Algorithm Hash digest
SHA256 cc3b12e25fe72bba8e7bd553038f08a556650c21bbbfd08de88e94365ca91993
MD5 ca8d2a505fe0e66197e0eb76311fa239
BLAKE2b-256 f99b38873814c207cca3f442254f2cbf083c08bea286b058b2b7cef0858eaaa3

See more details on using hashes here.

File details

Details for the file safe_cast-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for safe_cast-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 efa09a6629ddcb2fbe0641b86a228e828879d2c64870c4dcecbcf7ce83f557ed
MD5 9463777d483cc094fad0d4f81d8e082e
BLAKE2b-256 4fc2d6db0f3379d5bc52ae7b5471fef8ba68ed70a0f0afcc13b5de9fe261b8c3

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