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.14-cp313-none-win_amd64.whl (119.7 kB view details)

Uploaded CPython 3.13 Windows x86-64

natsort_rs-0.1.14-cp313-cp313-manylinux_2_34_x86_64.whl (213.6 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp313-cp313-macosx_11_0_arm64.whl (187.7 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp313-cp313-macosx_10_12_x86_64.whl (193.4 kB view details)

Uploaded CPython 3.13 macOS 10.12+ x86-64

natsort_rs-0.1.14-cp312-none-win_amd64.whl (119.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

natsort_rs-0.1.14-cp312-cp312-manylinux_2_34_x86_64.whl (213.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp312-cp312-macosx_11_0_arm64.whl (187.7 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp312-cp312-macosx_10_12_x86_64.whl (193.4 kB view details)

Uploaded CPython 3.12 macOS 10.12+ x86-64

natsort_rs-0.1.14-cp311-none-win_amd64.whl (119.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.14-cp311-cp311-manylinux_2_34_x86_64.whl (214.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp311-cp311-macosx_11_0_arm64.whl (188.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp311-cp311-macosx_10_12_x86_64.whl (194.1 kB view details)

Uploaded CPython 3.11 macOS 10.12+ x86-64

natsort_rs-0.1.14-cp310-none-win_amd64.whl (119.3 kB view details)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.14-cp310-cp310-manylinux_2_34_x86_64.whl (214.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp310-cp310-macosx_11_0_arm64.whl (188.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp310-cp310-macosx_10_12_x86_64.whl (194.1 kB view details)

Uploaded CPython 3.10 macOS 10.12+ x86-64

natsort_rs-0.1.14-cp39-none-win_amd64.whl (119.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.14-cp39-cp39-manylinux_2_34_x86_64.whl (214.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp39-cp39-macosx_11_0_arm64.whl (188.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp39-cp39-macosx_10_12_x86_64.whl (194.1 kB view details)

Uploaded CPython 3.9 macOS 10.12+ x86-64

natsort_rs-0.1.14-cp38-none-win_amd64.whl (119.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.14-cp38-cp38-manylinux_2_34_x86_64.whl (214.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.14-cp38-cp38-macosx_11_0_arm64.whl (188.3 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

natsort_rs-0.1.14-cp38-cp38-macosx_10_12_x86_64.whl (194.0 kB view details)

Uploaded CPython 3.8 macOS 10.12+ x86-64

File details

Details for the file natsort_rs-0.1.14-cp313-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp313-none-win_amd64.whl
Algorithm Hash digest
SHA256 b07620a0d612d5af33bdc98068d55775f11b50bfdf82e42f95598b730e8ae043
MD5 76bf2e59f5f68b478d947df87e50d0b4
BLAKE2b-256 e50c5c2f6d75623a7c796ee521c0213aecfbec91039aaffe7eccf608d04747a0

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f00ddcbb9472c0be041581fdbbfc040bc9124b019bd40d7946166b3e378ebdf
MD5 338a0e665ecf355dc896e270a97232eb
BLAKE2b-256 9fd4f5309b74022f974cae868b125e0b09ba0b31d4f2f4e5b4a8fb32bd0f9338

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cc15b422e6d2bd50b11174c0cc743e7888df4e637e9a5fd75bb5384ae3f18aad
MD5 3da7eee8192cf7580d27ae33570b77d4
BLAKE2b-256 5422534324b0140256a66372dafa132395f679123826c7b76c7bc80c29abb34f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c96634bd1357f9447250b46690e1d081a8c79de91348a80a8373f3db70b5dac8
MD5 2d114415723ae5ce2344d1dc980ddd41
BLAKE2b-256 52fe18eac84a2524631658dbb2abee7b7cc76a03ae1a74305415e41bb48fcfcd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 07a84059131db460a66d352c6f1a46b9bbfc63fcf5cd4f3ba553bf8e6707c608
MD5 8f2823bc610b4f6df0df0f6741b39dd0
BLAKE2b-256 99668cafb0cd91ca52b78c0f3dbd0466b69bb3a8ae93bc7428923fd174474a2c

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 64db2392f61371f52c0e34fbd9112d19d1f263fb42bc6d1779c3d8da8873254f
MD5 9ea5280bcc0e4ef66103d294c0765ab5
BLAKE2b-256 b2453a22aa65569a09773012cf837a0d5f73a2a38df561c31de04fb2370df850

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b66c97282421426d1e1db2c21eeb2f74bc111636373c894beca7a58300845a0
MD5 6fb2297b9d4710f7c253b4e10329ac68
BLAKE2b-256 f4be5ea335eec3c973323ee6bfe17148e2b34abe16475e250b91da92596a2bd6

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e09700ef3bc1ce82da9ab1322cabcc2c49f8609a07724b0b6c009cdcc6287977
MD5 b3c94106f63570df4fdc8317a78ea27c
BLAKE2b-256 19e1659af2514526dd49e62a54dd08eea2fb81945bcd2a6927389c06da8eecaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 799e84ca18bfb094b951203d906b92e36fc6c1d6065e81bf3bf951596ae29ba7
MD5 d6caaa338a93e6504a4288ff3815b3e2
BLAKE2b-256 e5cb7ad2aa32c8827617eb0ee76f28b96f8ee6175237d9251a6a77f336d400f7

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fc1c78cba7db57343ae5f8ef270fec1098a4a06b92dd1a47744a97adbe888743
MD5 fd4164d4cfece613c714f256a49240b0
BLAKE2b-256 7f7170065a35203ede50c5d735c9ff707c1ee289576d303e61c29960041f51a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 110cf7ec2f36559cfc9949e4fd98849661f5a667b5a04173e4b3a75af245fca2
MD5 e9078f0cfaee027f6643e71b5acbdac4
BLAKE2b-256 b157eb0872711a9f6b63d5dbc1317146f565cab941138f7f69149b5eb42594f8

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f36eb3fe2fef6972fa665e6f6d4196f9df8ee51b1ddff4c5b07c79fc978d4fe3
MD5 478b095523c26ac7449dfb276ab5fda1
BLAKE2b-256 68289276df39eefb1af5e7eece6dce5b84a5b2d978b7d8b05abb3dff0457de2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 bdab52c2ec4206c3bd3ff1d7a5ae0410fb31f03b4d7a11cf25a82071ff927570
MD5 3500085244cc04563624103553a80f24
BLAKE2b-256 3bbe6abc217a6c3e90043cb52c8d04d82aed853e80d0e0e1043f62d3a20e2f05

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7f5dca2896e6a197e29df87251158bc5fe638d0344456093e2de4846640fa352
MD5 47d1a3151821cef25129f772d0086f9a
BLAKE2b-256 ec21002637a35797b5493aa5555a334123a71ae69a349e9bd7b3193203a15bbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8c64e364a90a60d4f2d56868f4e45460cb01d1eb0c1d8ebdc1e7d52f13a8081
MD5 115a4b694fd539afb048cb4a199a29cc
BLAKE2b-256 b85bb3ecfff95dd63587105078a1e67a1f796a29e2d9a05fa48ffcb7caca16ec

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2c78579b712cd4e4bcb2b638bff30d6dd8a84677e7061451462fc0b930b198b4
MD5 44a47e7f5dce43d7c9e00fac0a38792e
BLAKE2b-256 d338232ea5bad9d5a5b8150a0f9b903c54ef3cecec7e23506fc686c2f803fc7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 283107b951263f3c330418b030b50d4589847027bc32ac62b9a445e3cfbfa78b
MD5 69b8e36d6b8268651f2358b23fe4fdb9
BLAKE2b-256 54c656479356ffdb61027ac3b401ca464de56a0a49c9bac2d6c5053a044ad8bd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 517ce296e06ab3a0e0be16cd025b1fab13215924433d3a4e993767aecc9c6f12
MD5 9c91e628df40c50b901397288a3c1e1a
BLAKE2b-256 3eaf42397442e232802192e253ccb1b9c50ef6846fecd0f885920c11d680d665

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6cf4a483857b960fdcdc0a9ebc74c3171013d2bb6acb582b040ca1293b349134
MD5 d8ce6159e9fb001ef9099558fa6cccd5
BLAKE2b-256 5bdd979546147388997b02b1fbcdc132904cdc094bd85c52738f12efe540ba98

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 35e3890e47e9a92873e4f9ed967c5a2257e64621965e55e668292f50a2e38b30
MD5 568f9ca8864e0528d5e543fd60686f03
BLAKE2b-256 40f49c4d4e6e5dbe6f11d391b2d9cca11184e61278f6c03497953f4e0e0fd425

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 c6ec922be7568fcc31fa44887fd1a7a224c45bcc0f2d7e103bcfc89f5100bc58
MD5 75475045e44668ec0e8de639575b8c7c
BLAKE2b-256 aeaf0b9f93ba0cfa78722a65190a965628126c82f19c4a6b647224f0e43adb14

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 4efca640b6dc33cb451a5c88f63a4412588682365b20c66a10a7a72854f32f8d
MD5 d43d3ff2a7b966fd4981c9faff341841
BLAKE2b-256 7839fdf957f0ad3954c4d9532b9c57944a1e1a708dc7609e8b4400834e6cba7f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a70a24b14802c2a0bd6107cede10d78d9da8e17ae077ecf203ac916473837757
MD5 0ea684cb7b0598e07350fcdcfa0f1e61
BLAKE2b-256 fa91dc25b9eb4c9b52564d5f32f87c75294fbc5f61267950c4b0bd494ba27274

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.14-cp38-cp38-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.14-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7f50e3e417232837da57952d78ed76dd00ca55dde4d49516d89197877a9c2aa4
MD5 c65921eb30c959b539438b961c2e5125
BLAKE2b-256 293e2c3244c67e6a9d26476b5567c4a2d0114bf98a60366d5be655a541d246c9

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