Skip to main content

A blazing fast natural sorting library for Python

Project description

natsort-rs

🚀 A blazing fast natural sorting library for Python written in Rust 🦀

Installation

pip install natsort-rs

Usage

from natsort_rs import natsort

Sort a list of strings

items = ['item 1', 'item 10', 'item 3']
print(natsort(items))  
# ['item 1', 'item 3', 'item 10']

Sort case insensitively

items = ['Item 1', 'Item 3', 'item 2']
print(natsort(items, ignore_case=True))
# ['Item 1', 'item 2', 'Item 3']

Sort complex objects based on property

items = [
    {'name': 'item 1', 'id': 1},
    {'name': 'item 3', 'id': 3},
    {'name': 'item 2', 'id': 2}
]
print(natsort(items, key=lambda d: d['name']))
# [{'name': 'item 1', 'id': 1}, {'name': 'item 2', 'id': 2}, {'name': 'item 3', 'id': 3}]

Return the sorting indices

This can be helpful if you only want to get the sorted indices returned, that makes the performance-critical part useful for custom sorting use cases:

items = ['item 1', 'item 10', 'item 3']
print(natsort(items, return_indices=True))  
# [0, 2, 1]

Turn off multithreading

Multithreading is enabled by default and can be turned off by setting parallel = False.

Benchmark

No. of items Duration natsort [s] Duration natsort-rs [s] Relative speedup
10 0.00006 0.00000 16.8
100 0.00094 0.00002 44.3
1000 0.00281 0.00022 12.7
10000 0.02835 0.00262 10.8
100000 0.29712 0.03334 8.9
1000000 3.31207 0.45333 7.3

Execute benchmark.py to reproduce the results.

Credits

This Python module is build on top of the natord crate and inspired by natsort.

License

MIT License

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

natsort_rs-0.1.10a1-cp311-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.10a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10a1-cp311-cp311-macosx_11_0_arm64.whl (235.8 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.10a1-cp311-cp311-macosx_10_7_x86_64.whl (248.5 kB view details)

Uploaded CPython 3.11 macOS 10.7+ x86-64

natsort_rs-0.1.10a1-cp310-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.10a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10a1-cp310-cp310-macosx_11_0_arm64.whl (235.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.10a1-cp310-cp310-macosx_10_7_x86_64.whl (248.5 kB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

natsort_rs-0.1.10a1-cp39-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.10a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10a1-cp39-cp39-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

natsort_rs-0.1.10a1-cp38-none-win_amd64.whl (168.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.10a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10a1-cp38-cp38-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

File details

Details for the file natsort_rs-0.1.10a1-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 562419e25a6bd986fa066bfb3c88ddf63f220c317dd7e3ea7f7ec3d636e095e5
MD5 bfc31f121e3e5253c1362f2735c68158
BLAKE2b-256 128ec976798f7deddbfde2748c3b7ff799f4626b2c56e0bba9af8989f99d3bb2

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a19ceb925828d3ed878018fba67c715640a3ca9b18f9b14ae89730165855fd66
MD5 c0792b782796bb065a1ff8ec10f1c9b3
BLAKE2b-256 4b7e2a9f3890ef26f0a3568d8c470cb335db71e011652380fefe3e8833ab658e

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40a3394c8d41de39e2a4a580250cd18ed497e4061fc7c691785b8c1021eae4b3
MD5 de385e5617eaf29a7bc67c223090359c
BLAKE2b-256 bfaba099ed588e593826a32172f18ebdf3ded9b13f49d27a4a26d30f20058c6a

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp311-cp311-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b787db46c351429f1ad03834e988d0d9ed332593ead8f3f511c70f46a0deb0fb
MD5 fc7bf656394284095ef9af976679400e
BLAKE2b-256 502f4e553cba89065c89806071cd9afccf8d505cff07a24d4ca4b57e5df18731

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 2f504a92c9fef26ac692a5242d647cbb10aef959b22e273fe4cbf114bc3bdc05
MD5 e5a37f2831fffc3cea6dff8d0e442ff0
BLAKE2b-256 19faebe5d170b79a1034735cb5636e1e3ee0ac5ab13663273947f6222c83d85a

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a48d366e15d7f249010800c1581ed91745bc1d0dae605b5cb893674a22b14562
MD5 dd4c04fbc587be7bfc6019dd6150e104
BLAKE2b-256 29a172f18c04f770d484288edf3b32786039c242d01d05ddbe6ca7837ba677ae

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3c3a8939da6fe43db7e69cd69866b0e20ebd0ad223e1a7502616063abbdd7faa
MD5 28683ef0e32aa50d650f57d353bba12c
BLAKE2b-256 1c2c511b1d7ffd435a476e28dcc174bcac75bd5739b47256c62de1d6c002392c

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b8bff1add829bafffb82eb698a58bbaefb71f1a0d09fe84391cf2ed2fcf20c20
MD5 b328042a7529825b10f14dfbaf05df61
BLAKE2b-256 93c26395f7037a459c22d186b5dbb5a70db1bf678eb91eaa7bbd54c85b3d21f3

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 4ce6c0dbfca5772ce4f5fb9ff69f718503600c031ec3f7673893c962c708c629
MD5 d1d1944160e688f77f87f218a97e97be
BLAKE2b-256 fddf45de885d69d4871990cd7630fb71b4bd7f9b095655e1fd0176bd87998d60

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8aaaa95f9d94c98d87faaa3c1b315e722f18e0c717f744c0a95ed52da7497c3f
MD5 221fbc5d265918d7980cec540c871177
BLAKE2b-256 7afb82dd54b18a2b651b77cf656e4ce899d7ecddf7bb4d00c3a831271fd9b684

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a224663264468a11df8822e2fb0e97b69ae6ae42ed094604e5596e0bb00552dc
MD5 affe456a9cfa10025ea4deab9af07c06
BLAKE2b-256 1146cff697bb650ea93761209cfccc3a1b71171fb7c6e67d7c2ec1033fec0b17

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 b2ca6f9b76c2d6334d2daf60e3b21f35c0e4a9cf94283b9fe3a5ba16da32ba15
MD5 321ccf179f6077c2a7230d14dd7e2227
BLAKE2b-256 d3a0999191ef1bf9d005a8e6976f0b78d18fe445a6329574cfd40be59265d885

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0f2861d2f0a7c6321e9c09cd3ce7117d6006a59205433504e36456cf7842eae
MD5 c2d3f095eca4b89e6dd6a652b09f361f
BLAKE2b-256 c18842a47f187f490b8be3b15b59e787a3f92d0f5eca60d0f475da9a71040128

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10a1-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10a1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 e78020e4ba23c7442a03ff25039d77086cecb84ebc02063d4b76b1cb0ae5cd29
MD5 8add321b5a602c2f44386125b60dd488
BLAKE2b-256 4bf63a3c3d5cb489116b21d36f5975610051a96d537ae57dec2cb98b388e612e

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