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.

Development

Local build

To build and test the package locally using uv:

uv run maturin develop --release

Running benchmarks

To run benchmarks:

uv run benchmark.py

This will compare the performance of natsort-rs against the pure Python natsort library and display results in a table format.

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 Distribution

natsort_rs-0.1.18.tar.gz (13.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

natsort_rs-0.1.18-cp314-cp314t-win_amd64.whl (119.6 kB view details)

Uploaded CPython 3.14tWindows x86-64

natsort_rs-0.1.18-cp314-cp314t-win32.whl (116.5 kB view details)

Uploaded CPython 3.14tWindows x86

natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.4 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (211.0 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.18-cp314-cp314t-macosx_11_0_arm64.whl (196.7 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

natsort_rs-0.1.18-cp314-cp314t-macosx_10_12_x86_64.whl (203.3 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

natsort_rs-0.1.18-cp313-cp313t-win_amd64.whl (119.6 kB view details)

Uploaded CPython 3.13tWindows x86-64

natsort_rs-0.1.18-cp313-cp313t-win32.whl (116.6 kB view details)

Uploaded CPython 3.13tWindows x86

natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (222.2 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (210.8 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.18-cp313-cp313t-macosx_11_0_arm64.whl (196.8 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

natsort_rs-0.1.18-cp313-cp313t-macosx_10_12_x86_64.whl (203.2 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

natsort_rs-0.1.18-cp39-abi3-win_amd64.whl (125.9 kB view details)

Uploaded CPython 3.9+Windows x86-64

natsort_rs-0.1.18-cp39-abi3-win32.whl (123.2 kB view details)

Uploaded CPython 3.9+Windows x86

natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (230.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (217.2 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

natsort_rs-0.1.18-cp39-abi3-macosx_11_0_arm64.whl (201.6 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

natsort_rs-0.1.18-cp39-abi3-macosx_10_12_x86_64.whl (208.3 kB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file natsort_rs-0.1.18.tar.gz.

File metadata

  • Download URL: natsort_rs-0.1.18.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.3

File hashes

Hashes for natsort_rs-0.1.18.tar.gz
Algorithm Hash digest
SHA256 3e80ccfbeee0cf59f8bf4846e346ef3ad2f3d6e5bc9df5f5b71bee013effc8ba
MD5 9e56ba5d8f5a584f06147c866ef470ab
BLAKE2b-256 76dffaf6a3385b65c538089f783d6b2fe58ba11e92d848ef6a7171d17e2dfe57

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 3ae17bc179f169e6bd8199edebac9437f8887c8885db92bb33304158f4fe5271
MD5 f25b5634f39984bf865db15373c25087
BLAKE2b-256 b710330da1100de83da83bf4aa08e3194040d357e98c6dd7ca032c54f47a1245

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-win32.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 41d327961a0c4ea85432df3effd63a948746cdf36077987333957475182b23b6
MD5 9cda08f5c66102beea63cd6abe1db9d3
BLAKE2b-256 2e5ecd2198ff7174487c9141f25a04abc62e9834657d8cf7448e04296b6aa000

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8b042543988ba854f6a85def57cef1398ff8dcb652a0980d9fdc6d2123ff2690
MD5 9481ece58533091881793986932342e5
BLAKE2b-256 af83b5fa98c0454ba49a6337ed3d17c6a9b19cd534f5840761bfe7286ef14209

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 58223c775d7401d0bc01ed98e90f7d0c86f8a018886891c0ef0ed598ef0ead89
MD5 284158bec08662d5758aa76c3a0338e0
BLAKE2b-256 f255d0fd211a6d7aee5e6d5a1fa8c04f1a0469257c538706f9296a16f08d75de

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86aac0063e8aeef46ba48751eacbe1a9fd8a33ad5b4eb60b888436a1502d3402
MD5 571c0704c53eca3516eba6b2e5769c6f
BLAKE2b-256 2dc4f12b76b5988e786a3d69fce967928d02899566e570a25ec5251169bcbd2a

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp314-cp314t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 432ea87fa51ddeb1afde0a01b3fea72b8caaa63babb6f4b0b5ad092c375ec4f6
MD5 8f2608c4643d7834ab64017a22cae10d
BLAKE2b-256 f8a2cee2aed6b51da0e10bf6b15dfc5c97212dd599c2dc7a235eade51eac5789

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 78577fd4f35aab83b631ab032611ac1b9f87fb43931089e05ad382599474a0f7
MD5 fe38726a081c267f4deba6e73de7c2b3
BLAKE2b-256 26f0c7b32de3c65e5664e023d8ee307dbc21525b37489276b1108f0e475011cf

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-win32.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-win32.whl
Algorithm Hash digest
SHA256 3e4fa6f79a838c50ad027103bdd0943d20ed195b0a4aadf0351739dd440b234e
MD5 b5232e7ca5724b3918fbae4b1bc9a747
BLAKE2b-256 7eb0a2765056b73a36f3269a0de369cc27297877948b9438297c4c2f546319cf

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2c77351963ad38d53d0ab0776094f70bb2faadc370f999285e8c40b339d40cd2
MD5 f1dab601afa465cd9c7b6be9d8c27350
BLAKE2b-256 9158518681695acc818b45d64f535efdc12c91b6c1cf9816a850995e5404b772

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 505896e17f61232764a0efda8c1ccda93ef600aa05cd5b91c1db788f2c28c5a0
MD5 f370a27de166513ce77eb6950b7b38cd
BLAKE2b-256 83249f49f94331370a68403b4d4b57a92d484ed4ea62d0206447fb6fa8df5f6f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1de128ba6d180b9def75be29cfda5b3eee9fcf2f3439918bb9cf9f786b55ea60
MD5 7693c4f607507460968cac78ea7c5fe4
BLAKE2b-256 4d5023668fb4028fdeebe9a5d3c8f063a2e485991c1b9696af7bb529383db1c6

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c828d766922b71f1af9f5f27162254c59982c081c92b489d49eac1bb01f3354b
MD5 7f5404a5ea39ddd7a913dff2eb9fc325
BLAKE2b-256 7cbe325e2df38bd15693b44278e44c37b8aca1962a39f812ce47689f1b9a2b79

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 35ea6256c0b8e6444fbb426b52fa2f766587ba16f77334008def6db45711e545
MD5 8c4b814709995e705eeb15dca2b17bc2
BLAKE2b-256 849ba017de67082a6735716570fc789c5a619b76ce8a1b7740606b41bef7a75d

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-win32.whl.

File metadata

  • Download URL: natsort_rs-0.1.18-cp39-abi3-win32.whl
  • Upload date:
  • Size: 123.2 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.3

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 e83e3a0de5264abbbbbbf8eba0effa17f93641861ecce5a227e9c213918d0aba
MD5 87d18146fcdbc23ffed3491bd2599d6e
BLAKE2b-256 efe3ad3767710a1b09837f00275c490cc427bd426a5f7eceeb56e3a01c26e01d

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57b2de92826ad65f05d9d3f80aa0a08e1aa65b0241909666cb90f1bd67cfc788
MD5 1b11f48a20285b233b38ca6f2aa93a1c
BLAKE2b-256 532bf84f96b6f80b7bf3949e53b46b97ef34f96b3faf600f24dabe4843ce18d4

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9cfefafe9e81ef2b4794181446cf8d51d2db231889c6f7b9f0910d25f1a258e9
MD5 d56585cf206afa5fa67f4075c2de4844
BLAKE2b-256 f5a81a11271f41d60ffe626296ca90163b82b7103511386f7fce48d1a6a6fa5c

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecd118b83b0b163d5663228bef824ba904d74b697c5c607a99b38681a5ea9b71
MD5 99c7ab247ef13e0878042cd19eafab2d
BLAKE2b-256 e3461e0550a18a27d49581f918d456ea31bb443c1753d61870502abf6647d1fd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.18-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.18-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 234f3fa8ac0437bc5d43c00ddd2a674871f1cf587158865c5f1d9496a39f05a4
MD5 f0f117c2893c5386fa2431064e8b5393
BLAKE2b-256 8dcd8d01b5875d1b71fac227704b770c024a1ba945c2b18910487f2a327e2201

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page