safe-cast
Safe casting of Python base types.
Badges
docs |
|
|---|---|
info |
|
tests |
|
package |
|
other |
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. |
safe_fraction(val) |
Cast fraction to type float, if failed, then used default. |
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
safe_fraction(fraction, ndigits=2, default=None)
Safely cast a fraction string to float.
Optional: Pass default value. Returned if casting fails.
- param fraction:
Value of fraction 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.
Release History
0.3.4 (2018-04-20)
Update requirements.txt
0.3.2 (2018-02-16)
Python 2.7 supported
Travis CI testing both Python 2.7 and 3.6.
0.3.1 (2018-02-15)
migrate to github/TuneLab.
0.3.0 (2018-02-05)
Added safe_fraction.
Verbose exceptions handling.
More examples.
More tests.
0.2.4 (2018-01-25)
migrate to github/tuneinc.
LICENSE: MIT
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
Metadata
Release files for safe-cast 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| safe-cast-0.3.4.tar.gz | 6.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| safe_cast-0.3.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.6 kB
Release files / safe-cast-0.3.4.tar.gz
| Download URL | safe-cast-0.3.4.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
85138fe595f4502a90e8c1b4e7314e370752ed696a22f9a100f3503302f88884
|
|
BLAKE2b-256 checksum How to use checksums |
b7dafdcb123e8558d07560d23c3626eade79dadf2250cec182a3525ebccdca81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / safe_cast-0.3.4-py3-none-any.whl
| Download URL | safe_cast-0.3.4-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d5fb7860b39472b7969978a283241dd2168b470af7e9d913d46f0a55e3e4be0
|
|
BLAKE2b-256 checksum How to use checksums |
e1c6646da9c460924804418f08b9385b7c17aa9111e3061bf1900f8d4f2fd6f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for safe-cast 0.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.