Skip to main content

Super-fast and clean conversions to numbers.

Project description

https://img.shields.io/pypi/v/fastnumbers.svg https://img.shields.io/pypi/pyversions/fastnumbers.svg https://img.shields.io/pypi/l/fastnumbers.svg https://img.shields.io/travis/SethMMorton/fastnumbers/master.svg?label=travis-ci https://ci.appveyor.com/api/projects/status/5ahtcvmt3aoui3mw/branch/master?svg=true https://codecov.io/gh/SethMMorton/fastnumbers/branch/master/graph/badge.svg https://api.codacy.com/project/badge/Grade/7221f3d2be3147e9a975d604f1770cfb

Super-fast and clean conversions to numbers.

fastnumbers is a module with the following three objectives:

  1. Provide drop-in replacements for the Python built-in int and float that on average are up to 2x faster. These functions should behave identically to the Python built-ins except for a few specific corner-cases as mentioned in the API documentation.

  2. Provide a set of convenience functions that wrap the above int and float replacements and provides easy, concise, powerful, fast and flexible error handling.

  3. Provide a set of functions that can be used to rapidly identify if an input could be converted to int or float.

Examples

The below examples showcase the fast_float function, which is a fast conversion function with error-handling. Please see the API Documentation for other functions that are available from fastnumbers.

>>> from fastnumbers import fast_float, float as fnfloat
>>> # Convert string to a float
>>> fast_float('56.07')
56.07
>>> # Unconvertable string returned as-is by default
>>> fast_float('bad input')
'bad input'
>>> # Unconvertable strings can trigger a default value
>>> fast_float('bad input', default=0)
0
>>> # 'default' is also the first optional positional arg
>>> fast_float('bad input', 0)
0
>>> # Integers are converted to floats
>>> fast_float(54)
54.0
>>> # One can ask inf or nan to be substituted with another value
>>> fast_float('nan')
nan
>>> fast_float('nan', nan=0.0)
0.0
>>> fast_float(float('nan'), nan=0.0)
0.0
>>> fast_float('56.07', nan=0.0)
56.07
>>> # The default built-in float behavior can be triggered with
>>> # "raise_on_invalid" set to True.
>>> fast_float('bad input', raise_on_invalid=True) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
  ...
ValueError: invalid literal for float(): bad input
>>> # A key function can be used to return an alternate value for invalid input
>>> fast_float('bad input', key=len)
9
>>> fast_float(54, key=len)
54.0
>>> # Single unicode characters can be converted.
>>> fast_float(u'\u2164')  # Roman numeral 5 (V)
5.0
>>> fast_float(u'\u2466')  # 7 enclosed in a circle
7.0

NOTE: If you need locale-dependent conversions, supply the fastnumbers function of your choice to locale.atof.

import locale
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
print(atof('468,5', func=fast_float))  # Prints 468.5

Timing

Just how much faster is fastnumbers than a pure python implementation? Please see the following Jupyter notebooks for timing information on various Python versions.

Installation

Use pip!

$ pip install fastnumbers

How to Run Tests

Please note that fastnumbers is NOT set-up to support python setup.py test.

The recommended way to run tests is with tox. Suppose you want to run tests for Python 3.6 - you can run tests by simply executing the following:

$ tox -e py36

tox will create virtual a virtual environment for your tests and install all the needed testing requirements for you.

If you want to run testing on all of Python 2.7, 3.4, 3.5, 3.6, and 3.7 you can simply execute

$ tox

If you do not wish to use tox, you can install the testing dependencies and run the tests manually using pytest - fastnumbers contains a Pipfile for use with pipenv that makes it easy for you to install the testing dependencies:

$ pipenv install --dev
$ pipenv install -e .
$ pipenv run pytest

Author

Seth M. Morton

History

Please visit the changelog.

Download files

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

Source Distribution

fastnumbers-2.0.3.tar.gz (370.9 kB view details)

Uploaded Source

Built Distributions

fastnumbers-2.0.3-cp36-cp36m-win_amd64.whl (21.1 kB view details)

Uploaded CPython 3.6m Windows x86-64

fastnumbers-2.0.3-cp36-cp36m-win32.whl (19.9 kB view details)

Uploaded CPython 3.6m Windows x86

fastnumbers-2.0.3-cp36-cp36m-manylinux1_x86_64.whl (59.0 kB view details)

Uploaded CPython 3.6m

fastnumbers-2.0.3-cp36-cp36m-manylinux1_i686.whl (55.9 kB view details)

Uploaded CPython 3.6m

fastnumbers-2.0.3-cp36-cp36m-macosx_10_6_intel.whl (36.2 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

fastnumbers-2.0.3-cp35-cp35m-win_amd64.whl (21.0 kB view details)

Uploaded CPython 3.5m Windows x86-64

fastnumbers-2.0.3-cp35-cp35m-win32.whl (19.7 kB view details)

Uploaded CPython 3.5m Windows x86

fastnumbers-2.0.3-cp35-cp35m-manylinux1_x86_64.whl (58.0 kB view details)

Uploaded CPython 3.5m

fastnumbers-2.0.3-cp35-cp35m-manylinux1_i686.whl (52.8 kB view details)

Uploaded CPython 3.5m

fastnumbers-2.0.3-cp35-cp35m-macosx_10_6_intel.whl (35.4 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

fastnumbers-2.0.3-cp34-cp34m-win_amd64.whl (18.2 kB view details)

Uploaded CPython 3.4m Windows x86-64

fastnumbers-2.0.3-cp34-cp34m-win32.whl (18.1 kB view details)

Uploaded CPython 3.4m Windows x86

fastnumbers-2.0.3-cp34-cp34m-manylinux1_x86_64.whl (57.5 kB view details)

Uploaded CPython 3.4m

fastnumbers-2.0.3-cp34-cp34m-manylinux1_i686.whl (52.5 kB view details)

Uploaded CPython 3.4m

fastnumbers-2.0.3-cp34-cp34m-macosx_10_6_intel.whl (35.3 kB view details)

Uploaded CPython 3.4m macOS 10.6+ intel

fastnumbers-2.0.3-cp27-cp27mu-manylinux1_x86_64.whl (56.7 kB view details)

Uploaded CPython 2.7mu

fastnumbers-2.0.3-cp27-cp27mu-manylinux1_i686.whl (54.0 kB view details)

Uploaded CPython 2.7mu

fastnumbers-2.0.3-cp27-cp27m-win_amd64.whl (18.5 kB view details)

Uploaded CPython 2.7m Windows x86-64

fastnumbers-2.0.3-cp27-cp27m-win32.whl (18.6 kB view details)

Uploaded CPython 2.7m Windows x86

fastnumbers-2.0.3-cp27-cp27m-manylinux1_x86_64.whl (56.5 kB view details)

Uploaded CPython 2.7m

fastnumbers-2.0.3-cp27-cp27m-manylinux1_i686.whl (53.9 kB view details)

Uploaded CPython 2.7m

fastnumbers-2.0.3-cp27-cp27m-macosx_10_6_intel.whl (36.5 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

Details for the file fastnumbers-2.0.3.tar.gz.

File metadata

  • Download URL: fastnumbers-2.0.3.tar.gz
  • Upload date:
  • Size: 370.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fastnumbers-2.0.3.tar.gz
Algorithm Hash digest
SHA256 cdd60a87877814124b10d66fe23042fcefe3e6e4a0ccc1bfef1ee34ec10875c5
MD5 e1c9518111901a9dbfbb7a087b23ec97
BLAKE2b-256 04438cd45dfbdf2421abacdb9cd5350f11f55fed7ea5f261954a5d74ef699c97

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 1baa6522843183ee363de9e37e94f806a2098722f3072fcf64d06f8d42c51a43
MD5 d179ff42aaef249cfd6c69af2409e915
BLAKE2b-256 6297b98c52ba54ab5460642e8217e84b02864ca4abe9e49e41b6fe86c9ac41d2

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 714f6b12bd6649a94b252c640aa72806a9ee7d9ac52be78f235408376f59f6f0
MD5 a529332b321945412ebf0eaca6ae3b79
BLAKE2b-256 9ce4b3919e11ed16387228a6196041200c0ef1b35ce94a9ec5c384d0845983f2

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b410b787de98c5ae26e23aac13bc9825f8c3561201ffb20554afae80d449c574
MD5 b9854dcfa658e570a6d354bd36d6ad5c
BLAKE2b-256 1e771f9e99b59d7f64e618dd4d0f4c18f25094a25e829150da6665b589d50354

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a3dfef4179cb68a571a773e502bda77baf936010d4eabca3655744bac1113f75
MD5 2c0b0ba5b6855e1ed4d7ab21678988cb
BLAKE2b-256 34adf517013b71271640da7f02d12c615c8987400a704506189dd8d0c9674c58

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 f51a70c60335f3b818b4d5c92aaca0bdf56699e704af49ec63e8a6bf2487c6e4
MD5 e2d2a46ee63d77594d57dc7e28b14f8c
BLAKE2b-256 24ad439da64f4ce7ea2b0ecc9929bf0a8986100df25b2b830c9fd6ba239011bc

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 c7f616415c021f5b54520cc00a949d374ecce3b7a562cf816ce847137168ea22
MD5 dddf074c9b2a166f93a66dd08fc6a0a1
BLAKE2b-256 b1a3d782b14c96c3496dc64e24488c25a48b1cf683e0960eb4aa091e9e5ff6d9

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 163baf0feb74592ed1d93dd9c470a119775d38dc2ac92c2cb9347595b9884203
MD5 1db9d0cef1d75837d4eb4ceb563d0f21
BLAKE2b-256 3ce33ead94dd857f2fb40a4f8be5a86408ce9efb3c579b9726686d39d284fd1f

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7ec3ad598efa997bb76b03749828db2460239b10d09f9885d3de19431e633bba
MD5 f50c3dc7da43b87634a3d591a74ef738
BLAKE2b-256 9c304294a57cb9c45e756da1ee2b21f972d3693c5a49970c5e5112e5e6264af3

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1ae6e2b7344639dfed0d4252bb6eec01b025f7569ae2eee5dfbcdf4028d7c345
MD5 4d099edda0549c97f9d85f6db42609de
BLAKE2b-256 f6ae585c77f6beb643495a98606a117fb30a569d1649a95397713a5bef037a98

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 061d1c0619cc8a4ba048e132fe9723291e9dc3aa3607e46ec7e152d7c6d307a8
MD5 0dbc49e5ef32309ee6297e897988f7d5
BLAKE2b-256 91ee9c8db0317653439a87c547c47ddf32e07217c541671101a10e0c9e55d2d9

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 2a43c85cc6c25e8681f62c183adcb59a13edde3c6e748ce43a977e2e2b219902
MD5 b6230412e562ea10b5097b53b6cb48fd
BLAKE2b-256 57a25fa0656ba017455df1566f859d1b1c3bdefdba97423768edf9a68bcc8533

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 b951c3632b1e8e0bffd65682860dc723b5569121b9a65601ab3d9b10cf620d60
MD5 cdc18874a67ce067b661fc49141c1033
BLAKE2b-256 b9dd45821988519293a68034e4cd14d01a537650273fd360fc5dd74d520464c9

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5d746e6907d1539f921f42026197c349f198d301a52298b818a99e5cd1b3fa00
MD5 f0e6b2c1cbc8057eccc76dccc704325c
BLAKE2b-256 4e99d2c7380c9c7e9114a8569c39f9b31556b7bb33c801c62feb02d936838cf8

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1605a7c594e866252967776198509126460f4197a46eb4eb5c604f344e2590db
MD5 e8e1f19c0fea2b13b48ee6aca2e3eed9
BLAKE2b-256 a64ca1af6c3a24065c88b3a4178c090c54592e430832b48d15aeefe4002445df

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b251b050dd28b88afbdfe2ece31988b726903948ca425686fa92740cee6f4a63
MD5 24dd7f6924c060c7b8e6fe5110f5e0cc
BLAKE2b-256 4376f2a38ecb8afdca71a16f91924997cbeceed0bae2c8c41612ee6556504284

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aa06e6d21b117ecc6ed61f75f512fbaff06f9649a01b87cbca8263027e0b2ae3
MD5 c72ca44d2e833dd79c2c4d1339652bee
BLAKE2b-256 c3e44025cd23cdedc0642584295d404f418170763efde37b5366ce5b73eda2fb

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 bc2d11cc3027f9a328be151f43203d64d645f186741f41abdff91acf87b7d203
MD5 31b2aacedf267e20b283c1a33ee0bed8
BLAKE2b-256 f1b99ab09a535703bc0b248c2ce424df3de85cc4c56b1c8020c6fffed6a27a4d

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 2d5e5a26be0e1791f87581a01c6706917644809b52ac6fea216a8f2a9e0bc14a
MD5 faafac19f3809a16d893849ae8460eb9
BLAKE2b-256 aa3c836b1978f107e65ad4d2b4409c6609a107174071c1dc3a1c5a7e7e28dab2

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 9bb4bf3d342d7d03d76aa29fcbe9ed4bbcc5751b6ebad348b86b63a0dd303991
MD5 c1995f5910c46f28cb2939825e28ba2d
BLAKE2b-256 b1d8300ec9bb10fd2b01e544b8e5b0ffb2b67e59a3b5167cba48c66e4ff5880f

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 06c06cc26b5fea6a7f2ff0ab8244f12d9f97a2f91acb5eff6a9050155c6c195a
MD5 4a8bd3dea8cc6503790a07b85cf2b509
BLAKE2b-256 0ecaf598ed1b7cf90098ebdea48652b4d1af45e41cf46e9305846fd2d86898c0

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 57245208e24a2ef97e3e3859c263159f4688eee56b22750bb647c921cc6aa23f
MD5 c13dcac652c2d5d973a704315380abce
BLAKE2b-256 e569ef071ebc0638ade1208cbd6134a8b9925d228923b730d581fcb8968b0af1

See more details on using hashes here.

File details

Details for the file fastnumbers-2.0.3-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for fastnumbers-2.0.3-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 2b3bf40d43ed04a5a3023bc6dcc2704b2883a4d55831a4ce2760b1813a99ae8c
MD5 21cf12a2ffeb43280bd100b608d8ee6c
BLAKE2b-256 7a2f4f0461127102bf83df688f36db2004a2d5249e5f156f3e993ea565ee4b03

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