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.12-cp312-none-win_amd64.whl (122.4 kB view details)

Uploaded CPython 3.12 Windows x86-64

natsort_rs-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.9 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.12-cp312-cp312-macosx_11_0_arm64.whl (190.6 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

natsort_rs-0.1.12-cp312-cp312-macosx_10_7_x86_64.whl (199.7 kB view details)

Uploaded CPython 3.12 macOS 10.7+ x86-64

natsort_rs-0.1.12-cp311-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.12-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.12-cp311-cp311-macosx_11_0_arm64.whl (191.3 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.12-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.12-cp310-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.12-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.12-cp310-cp310-macosx_11_0_arm64.whl (191.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.12-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.12-cp39-none-win_amd64.whl (122.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.12-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.12-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.12-cp38-none-win_amd64.whl (122.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.12-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.12-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.12-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 964f972a7fd608e664ab8bca2ed5f007f1f336899689089275f5f0c365f594fd
MD5 d1c218d42c4757f19928cb467faf775e
BLAKE2b-256 8bf3d218d3e767abc0ee956a5fafd6888dd9e82dd859ec99598b63ea6ac7388f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9f69a160aeac7a9de4e4b2bee6b64c14598415bd7cdc75bd01b86a67d3dda213
MD5 456979748d997a2443dc5a73096d2079
BLAKE2b-256 6bc3fa51ec209332d218597c5f42d27bf6e094eb83ed91a2e170e5a8540aa9ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ca5a82538133d4868d2af1208ff981edd659f14f00ac71b0228822431f5bc68
MD5 c4c01c922f759e76606a5874f9c92a2b
BLAKE2b-256 a468c00c25513b96eca68a71ae2fb6bf145daf1fe639cbcd6dac37484024cb06

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.12-cp312-cp312-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp312-cp312-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 42fc51bee22c30b5855ab05d1e6e7525d469b16735e76008230d21e635926593
MD5 171fe4dbdfdd4658c406b985bbf33253
BLAKE2b-256 98518ae6962a26cdc56d8e4407d3df87afd44174331ed34382793120e85a9777

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 d01152204eb999e19e6bd59b73250e04a45f43672b3da2229a047c7ae628a172
MD5 92cd70e3c8145b1f31f15e09da6a4df7
BLAKE2b-256 24b879521a084d1c285ca761683525f44b02fa11019507472fb8f2c6cd7a9847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d96d2997e592fbf1e839534f909f736b87044d76ea0496341a687ed88cbba447
MD5 89000d455144cc262a5c51a5816b2cb6
BLAKE2b-256 52becfb881ca8a6ecb70743d76681469ffa3029e827ecd160384402353485782

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d98eec1fa206479a70d44c087be832480ba61efd504449976a0c5d5a00dab67
MD5 55e6514976c5a4cfe875f8838dff0218
BLAKE2b-256 4a9cf7dc9dd2abd6a1bf6aa244666ee79acfa4f6f750bddbf870d969fc405489

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 38988d4dd1fa101d8a14d8795c2319ac018c253b63276da92f642a2bd099f03f
MD5 4052aaf8ad3739817b3500b6f1788780
BLAKE2b-256 cf12e71f63f69a4906b1383f3f6f9495012bf02ade02b695a0fbd72322b012e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 7e6a47b72841d7e11d188f6ac9406b1a03d68c0a4636fdc21e27f6f47f4d5673
MD5 b8d5fe105ac3e4225006c35a279955a9
BLAKE2b-256 69a8aa04bc637f151298a734e32eef5bcfa59d7c28c20c95d8e41eb9f9061d98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 404418ccceb010754f08cb3beb8eb3d51a7b3e04799eda5c91e110d3c30b019c
MD5 8ea114c7cf63fb14003b9fd01f125f12
BLAKE2b-256 e50deafd357bcf17d4a7a2bb3a0444c313409c2a1187b8cba779ba67d577bf31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c56c6bd51e0efc4cea3c651f1499258e5ef8c16ddca7e0f6a7e0a8f8debe2bc
MD5 96cf00c7327db0eed12fafef10ae414c
BLAKE2b-256 4286571adf50b75e5afc92f3fb0edf57d6fcdc3d9ce20f6e47e0c0f176616206

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1fd0054cea461155ffaf0a6bb01b9f4354016b045cefe22738753ed90f67dbb5
MD5 33d03856d699a194afbf68a6a0b5961d
BLAKE2b-256 93a4f2f26ecaae869c7b5353a5598642ccaf5dfd392476b479b39daa267a240f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 136121794c883cc7d07aaea5b75b6549fa3935b1478c865982c5500b61cc13e9
MD5 d0db6e23ab901f565e0369712388db03
BLAKE2b-256 b8c57087f3dce5e943cd3452adb55345c720bf5bf3f9578e9a353e7aba77953a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d32898d4a4002e38ed4dc621c2d6e00d9b66af0a29aa8754a0104d95332e004a
MD5 a5e48ddf6edc4e7ac4e3f1a5629703ff
BLAKE2b-256 71d5c9122687c2c3f1657016d0756e7d9438100febdf56441c26bfb9c5659ccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 9acc9e8208908e3ed4a1573cf5e91b783e1003d25517bfcb91ada4c0a60f83a7
MD5 4a08f6e268fedf8a86e050e7d238e42e
BLAKE2b-256 9d9b3e932392fe219a9b94b6f40bac41309e907613550d8ee34709cac81844a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 d255d0f75758aa69df868858b8c6eb7d29f77a20b2c8bd2b46d50cd6ea5a0d3a
MD5 fa8c429a189e9f8e018a73cb6c52aec0
BLAKE2b-256 60422c8df844e7ec28a043bcac99f4786eaf5f3b9dc040bff17edb9c505e5683

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4337fbda0ee2d622fc4218f0fd948ed31de4bb11beda988499caed32c7fd9f45
MD5 bd9e9227480aaea32a319c5e6405ecd4
BLAKE2b-256 53d96010e8db96610b3b4a971773411dcc1aad6c1e53e90041ee6e17188af9d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.12-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 d575ca9a293f51cb8fd1cf98aa304a7659e72fb9999f9971f79796ffcecb1d55
MD5 e61da3462b4fd5fde00a668940f0433d
BLAKE2b-256 985a317e653e13eca2f99ad320a13978871b1363957fd6d8d89aff90ee8ab265

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