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]

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.11-cp311-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (223.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.11-cp311-cp311-macosx_11_0_arm64.whl (191.3 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.11-cp311-cp311-macosx_10_7_x86_64.whl (200.5 kB view details)

Uploaded CPython 3.11 macOS 10.7+ x86-64

natsort_rs-0.1.11-cp310-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (223.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.11-cp310-cp310-macosx_11_0_arm64.whl (191.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.11-cp310-cp310-macosx_10_7_x86_64.whl (200.5 kB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

natsort_rs-0.1.11-cp39-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (223.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.11-cp39-cp39-macosx_10_7_x86_64.whl (200.3 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

natsort_rs-0.1.11-cp38-none-win_amd64.whl (122.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (223.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.11-cp38-cp38-macosx_10_7_x86_64.whl (200.5 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

File details

Details for the file natsort_rs-0.1.11-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 7e75f100ff8a05c4402bbef27f0470373bfd43a6175f6288429cb958c1646167
MD5 2c5d3836fb1df738d4dc49dcf0995285
BLAKE2b-256 67ed9d57ac5597c42a8606d91378aad1c2ef8f554332293bb49af67f9238d106

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 704609f068e091006f97f5aaa0d3b4ec18d33f94df71bda876d2b4aea628ce7a
MD5 7bea6cb0155ed5bd21302de32fb0ab3b
BLAKE2b-256 710af140657783c3ce987ae16716d587cbea907842e6f1dcbad53e98fe216b72

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f78c8a87cc0c82b8a5535f691d430c1a8b51f75af27d2ef5c8b2cea7ba9282c
MD5 5e672489e41733fc8bc701c369934903
BLAKE2b-256 03e1942fa68a303f9f56f356ac8df329fdc20ae17565ac8d2b7e61c2dbe9a3a9

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp311-cp311-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 81f05dba6034d4557ba072dd322e062dbcb70e2299a44075600a56fb29493d3a
MD5 35820957608b9c12dae30001c288dc72
BLAKE2b-256 2d9a977b4b18ac634e29c3ec3b72ba6cd64a2d8a7a544dc7efb749bad9e5af28

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 4113f4254aa3645b13f76688f10b602f6c8db6b9ff6770b4b1822250bc5096ac
MD5 0d31805d24356a9709ac0cbe5205a0fa
BLAKE2b-256 aac1eca2df8358ff93a025a44cd731cfb3b4f8c637fc4edde50b2f542c8aed3a

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e5a54249ba6d8f9ffc2a3d61550574a2684703f8da3153f2fb4b13d2f8cd522c
MD5 0646eb78aa74186f197de41abf870a1e
BLAKE2b-256 1669958077b275694cfcba2180860a94614799ecd02ad79663c93cde774a428f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71a11f20db7b9c14b6ca209a228ca4264941c2b9b3acb838d17d2326024c21c5
MD5 1a0fc26840335cfd7028320178ecc8ae
BLAKE2b-256 2bf69557c4982d71a3dd3caba94824b276cc73ec71716c7e0d97294bae0db0bd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 cd143d5f6a78041c18209e07d86eb6bdc812c15c3848e8000e0f6a0ad3e468c8
MD5 7890fd8268615dc70f63d5a93fb6af9a
BLAKE2b-256 af187740a35a3743fefac76f1d9a665d93fe7b30b7d82a43a49b3524845bbff5

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 e3471543b3ce6a3f7e3ee3da2eef30f038806b45c9699e0ad917fa112a4434dd
MD5 3cd171eb91193e1c316222bbc61391f7
BLAKE2b-256 73d83b70b54c4e99fee3b3230f83fb66f1768230d0deaec8aa84fe8a176bcab2

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11b0b0cf956932aaec201166e08ce1982d32fae0dffa7a2a5e7d4289f81f3b5a
MD5 cba80418b41de6f3a8232c13f31527d0
BLAKE2b-256 484a50ffb176aad3ec70fcabb0c96febf9c28bcb923dddcfc57a8c07efb2d12f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 bece345fc8c8da5c1d154f411793ad3ddea3ccc7fa799a5b348d468027a20fb3
MD5 43a7bc7252b5f4b1605e1084e4ee8d23
BLAKE2b-256 2c9415c89443e319a8ecc660824f744434fa79eaf38f712e2b5bb2ad0de22caf

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 b149c7493b0b92865beeb0e0afffa69b8896964248b24a189d3c01a9431f0a9f
MD5 14a7dae0ab3c4f2bffa02d5982c3c4ae
BLAKE2b-256 9e6da34c00da36657e07375ebde36f4d5a4c10b83e465b82a5e8e6b0f996a9c7

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8c5a710b98164d8c6a8ab0b201c5a0239082416972c18fa119cafafa3d59b6a6
MD5 75310cd4ac78e184d8eb7cc9f0a9d6eb
BLAKE2b-256 6fa4cc81e59ea341bebc9ab993bb7f424f668c7cce3d77a571bffee40bd427f0

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.11-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.11-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 758fd5fde90736eaf4c17da63851daa502ab372d0205705130bf2473757feb82
MD5 a9defc05b851050a99470394eef8f420
BLAKE2b-256 767ecf0aa937d7d61458f271753135633d313f38e8bc4e915831ca920e0cbd35

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