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 --skip-lock --dev
$ pipenv install --skip-lock -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.5.tar.gz (371.1 kB view details)

Uploaded Source

Built Distributions

fastnumbers-2.0.5-cp36-cp36m-win_amd64.whl (20.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

fastnumbers-2.0.5-cp36-cp36m-win32.whl (19.6 kB view details)

Uploaded CPython 3.6m Windows x86

fastnumbers-2.0.5-cp36-cp36m-manylinux1_x86_64.whl (59.1 kB view details)

Uploaded CPython 3.6m

fastnumbers-2.0.5-cp36-cp36m-manylinux1_i686.whl (55.8 kB view details)

Uploaded CPython 3.6m

fastnumbers-2.0.5-cp36-cp36m-macosx_10_6_intel.whl (35.9 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

fastnumbers-2.0.5-cp35-cp35m-win_amd64.whl (20.7 kB view details)

Uploaded CPython 3.5m Windows x86-64

fastnumbers-2.0.5-cp35-cp35m-win32.whl (19.4 kB view details)

Uploaded CPython 3.5m Windows x86

fastnumbers-2.0.5-cp35-cp35m-manylinux1_x86_64.whl (57.9 kB view details)

Uploaded CPython 3.5m

fastnumbers-2.0.5-cp35-cp35m-manylinux1_i686.whl (52.9 kB view details)

Uploaded CPython 3.5m

fastnumbers-2.0.5-cp35-cp35m-macosx_10_6_intel.whl (35.1 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

fastnumbers-2.0.5-cp34-cp34m-win_amd64.whl (17.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

fastnumbers-2.0.5-cp34-cp34m-win32.whl (17.8 kB view details)

Uploaded CPython 3.4m Windows x86

fastnumbers-2.0.5-cp34-cp34m-manylinux1_x86_64.whl (57.4 kB view details)

Uploaded CPython 3.4m

fastnumbers-2.0.5-cp34-cp34m-manylinux1_i686.whl (52.6 kB view details)

Uploaded CPython 3.4m

fastnumbers-2.0.5-cp34-cp34m-macosx_10_6_intel.whl (35.0 kB view details)

Uploaded CPython 3.4m macOS 10.6+ intel

fastnumbers-2.0.5-cp27-cp27mu-manylinux1_x86_64.whl (56.4 kB view details)

Uploaded CPython 2.7mu

fastnumbers-2.0.5-cp27-cp27mu-manylinux1_i686.whl (53.6 kB view details)

Uploaded CPython 2.7mu

fastnumbers-2.0.5-cp27-cp27m-win_amd64.whl (18.2 kB view details)

Uploaded CPython 2.7m Windows x86-64

fastnumbers-2.0.5-cp27-cp27m-win32.whl (18.2 kB view details)

Uploaded CPython 2.7m Windows x86

fastnumbers-2.0.5-cp27-cp27m-manylinux1_x86_64.whl (56.2 kB view details)

Uploaded CPython 2.7m

fastnumbers-2.0.5-cp27-cp27m-manylinux1_i686.whl (53.5 kB view details)

Uploaded CPython 2.7m

fastnumbers-2.0.5-cp27-cp27m-macosx_10_6_intel.whl (36.2 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

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

File metadata

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

File hashes

Hashes for fastnumbers-2.0.5.tar.gz
Algorithm Hash digest
SHA256 632a9cfc33e6dc33fe665b16241dca34f84c5361ba510db210b76976f70d8762
MD5 4e3e37f82c47f47e15ddc35c277ba1b3
BLAKE2b-256 b7d01a19cd1894c8f1318e1a02d32a5ec1eb3b2b37ef39dae967e2289570a98a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 a45b7f19ac8a674ada1ae9f3fd7db49c29aa1f16e87abfd08c6c901a5964dca2
MD5 6b88168432e458bc081b33ef20bf8ed1
BLAKE2b-256 9fb822125ad1b067e1d8b913c0088d9829f3a7e8234ef5723ca26471fcdd074c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 5c39d780f89bb1bc8474fdfbfe2c1267291c8fc1b42bbe2ca5f77f7fd57ecaa6
MD5 6c61dc86a5b64b3d0e9abc01a26d0991
BLAKE2b-256 50c832493287e012dee0c83a8206c58577b46246160a347872e6c72c480080fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 87f99675e8ab8c8e23408bd8c34c930fd21abd67c5f170d1be19bb24ccaf8fde
MD5 324abd0ae35b936b2b3f5fefae51a820
BLAKE2b-256 e14bbc5a37855862f4f10d14b4664f80251bd99ffa8773229ae321de622efa8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5c7d9e57ab31680cff3d4531821e7cc23b10cca832a946cf460330dce3708d83
MD5 61a214dce958ce3a427ad67342d08db6
BLAKE2b-256 e6bae4809205754c24f4bf6c5659deb73a38ac99f95b06dbe9692e2ca6daf9a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 6a94c01ec7f98dcbb88309a4c4562ec497989df6f158b847d3b39c4828f83e33
MD5 366c21d4ffe57c9504691622d0ac3bab
BLAKE2b-256 e592ae6e2e2ce5620efcd5ea646bc3bb95b5ada49ca86e4299ab2728dfac9f24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 f7069b02b2f6c0ebdc7629b0b1fa69f1263a723ad087f041addf45087e19f1f2
MD5 bdfa4d3d975bfc524b13747bc462d782
BLAKE2b-256 92c42cdecb912af681ca8c1f62e996ff9de840636b77f5ca9750957c27a582a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 2b2afa540cf36965654c1c8cbe2ec03f551d2b57a241c0f39ca62f3f5dca6347
MD5 e8db85c380f3d8cd0682b3119580e147
BLAKE2b-256 77a3abb0b00b95069c245aafe287e3accedd66e6f75c0a27cd429223bde80496

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b548bb92825759a4d065770dffed3806618cad571d6f25f096e9e5ab0d1a9e12
MD5 2d84923048f09f86eabcdb333a2f5a21
BLAKE2b-256 de8c1c8ec92503010aaaaac0a25fbf8e9d97e34fcdf4c34d71173c518b5e9b08

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b0b2a269429e4fc612186d20dae6f7ac65ee2ef16d705e1d87d748955f8530ae
MD5 441557b695e0fd7296cac6ff56851f5a
BLAKE2b-256 36d7e29e1c3e9a199077297ce7c785eb214e11fa39601eaedf72971e02fca0b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 61e181f24105f5573ac3db8c864ebf499f728d7af63b59026b728b5f1da79516
MD5 f1a01d226e2045cecd6424290fc9baaf
BLAKE2b-256 0eafb6b3494490bda7f8e6715b6cea31f8852c135bb11e188ecf2106e100df26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 a5a21cd50de36a063aaae0f9a8b2d59e14cd77d74373e3bec8ee9b7077916594
MD5 0773cb9ae42b2bb148d44528be64ce5e
BLAKE2b-256 3febd4e4bced4b87ddd6d4cc2eefd74d56d47d2466097d87dfe4514f954bda2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 bdd6527eb093f7ed0a2db4406efd9f713f6304ce6dc183cf5b69a21fec59d5c4
MD5 4cd590dd2b76b565e8bf6d05f6c7a2d3
BLAKE2b-256 bd03b31084f304f21448334b6f8378ea3402d623a8d9dcb75dd04b34ed2e3595

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ef96e4450087cb23f5036c5a705bb6d61389c4e15ce972088a98c0be16f4260c
MD5 6b25f6ba2ecafa44b383489c3e452d9d
BLAKE2b-256 696c3667fdbe2e0ccf15657f76e85e9a6c869d33158d29b7af29c58bffad21bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e25508429d0a1493eae5095f1d0167677136e4ab1449ee20e889ce95009d9b68
MD5 539f17d0ef139300f9ac62369c7c7f89
BLAKE2b-256 0b62be2b0bf13a8deaac2a0092b055c7be9d30c284771ee032e97b46d89cbce4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b52510a4aab1fa1f743ae9fd98cd54f8a5ba658a81a3e86185860086a8961d44
MD5 1e10958ac72d819ad3b03a875a70358e
BLAKE2b-256 4fc4ebbb1fe05fa6fb4bf265e135ca2659231964deb54af0ba61378bbd2f33c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 467d867b62e94941fa92e7373aba45bb882a57f586aab8ddc64fb0dc32f63ee3
MD5 064bc7197ddfb121b78159265d0e5745
BLAKE2b-256 8e557d5cd4145a72eb116707ea193c0113065f65109d015c8bb017d24266ae34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d0cb4d1db65ec7cbcd85e1cb51a152c08e26466fa916c5164b4e7e705e39d71d
MD5 3877f45806167e834ee08c667837d192
BLAKE2b-256 02acd5d7db741a0fc19e3649d69bc8c474aefa4d10210f5bd0ebda233c198c58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 09755977b59dcd965065ba705fad1691a9782d49afde96ee16ea308034d7fe03
MD5 ae1e799e1d20ced2c53cb031a2eb8d92
BLAKE2b-256 4afaf0e89a8008335e138335a478c17b082674025b4539a3df1325356192ff4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 2f7ca985e56163c1276dae78e07ccf9c5c6946df20b57de1769a77008663a700
MD5 bdbc1834baadb8940342cff25dee7518
BLAKE2b-256 f8c8bf610309a618758bba52c4e799ce96bf990ddcb94ab32d6192492d51cdcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c1f22f90a12d58fc5ed5268101308504eb497d942b26b11718a963b1111ec86a
MD5 c026e3cd67fc6d621bf027a0a61eb9ab
BLAKE2b-256 bd4412bcaf9962856a288b33b2d17616f9bb960015b5711b141f57118446df7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 3fc8466a7bc5868ad5231b4b5c1d0cf49e6aeadcd4f5aaf6e7fdf5600b14cda0
MD5 0010be5f5ceb1adad07cc8bd3cf02267
BLAKE2b-256 fed26ab47e7831b8304fafbd82707515f349450657a9902bf3a830d27c6fb4c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastnumbers-2.0.5-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 e49142e256a1b74a133a35e2254112b57575b4ecbccde8c89af7b36873207584
MD5 9da2171e649e0f0b63c92feeadc5c0ad
BLAKE2b-256 e7b930dc48d40d7029a2351d0f248e6bff255d07ea28b92d6ada23cfc4db046e

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