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}]

Type-safe sorting

The return type is inferred based on the input list type, so no casting is needed:

items: list[str] = ['item 1', 'item 10', 'item 3']
result = natsort(items)
# result is list[str]

items_int: list[int] = [10, 3, 1]
result_int = natsort(items_int)
# result_int is list[int]

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.

Run tests

uv run -m unittest discover tests

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

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

natsort_rs-0.1.22-cp314-cp314t-win_amd64.whl (150.0 kB view details)

Uploaded CPython 3.14tWindows x86-64

natsort_rs-0.1.22-cp314-cp314t-win32.whl (144.9 kB view details)

Uploaded CPython 3.14tWindows x86

natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (251.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (238.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.22-cp314-cp314t-macosx_11_0_arm64.whl (225.5 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

natsort_rs-0.1.22-cp314-cp314t-macosx_10_12_x86_64.whl (232.2 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

natsort_rs-0.1.22-cp313-cp313t-win_amd64.whl (149.9 kB view details)

Uploaded CPython 3.13tWindows x86-64

natsort_rs-0.1.22-cp313-cp313t-win32.whl (144.8 kB view details)

Uploaded CPython 3.13tWindows x86

natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (251.3 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (238.9 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.22-cp313-cp313t-macosx_11_0_arm64.whl (225.6 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

natsort_rs-0.1.22-cp313-cp313t-macosx_10_12_x86_64.whl (232.4 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

natsort_rs-0.1.22-cp312-abi3-win_amd64.whl (151.5 kB view details)

Uploaded CPython 3.12+Windows x86-64

natsort_rs-0.1.22-cp312-abi3-win32.whl (145.6 kB view details)

Uploaded CPython 3.12+Windows x86

natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.8 kB view details)

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

natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (240.3 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl (227.5 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl (234.1 kB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 209fe4db4f05159d110c851c04a2861796a8b9424cb99ccdb295b9427c6d03de
MD5 19eee69895fd2d16e4b81ff2b553dd80
BLAKE2b-256 e2b467e6a837aacae6d3958bf51cad7b0471e55c049b3d6a210b3fe13d3d4fc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 2879ee6a39e292731ef5c9d4e7e9317c02a34887fb77d7bffd711bd7a43050d4
MD5 ed193421ca33a4d0c6edbf1f27c9190b
BLAKE2b-256 e7b7ff9cf0d7e189d7ec7548d0fd96cc4002d19ff0198585374e1beb3d37cbb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30faf0f3e0acd525723c2eb8d0ab15163321fdcdfa32f2e2c810380651d7fa52
MD5 db2c4aaf6191dffbeaa48b643391e691
BLAKE2b-256 d51bc7582aaf538638a9d627b8407bf41ec70badad77c63ed63825996699771f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4deca61f992f8359843c7855b79247352d179847d2a18cf388a0db8194d29760
MD5 92627d87e7443a32683ee8516fbde402
BLAKE2b-256 1ef61c71c933503f85160c2cdc55ebdf31cf478045f18a046934311f477125ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9eb1465e8c22b16f264ef3a247bfba63d112f471ee3001d3b33455f82c4a2dd1
MD5 7b5180a76b85e3bb9bdf9d1854021e0a
BLAKE2b-256 387713c8af36d6f0803c55b61592a38e2cebebf71e399db00e1db16bcacbc67b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8346e9d5322edbe7cabc4e88d5e36f78bda771418b8a46ba36d0d5ebc15a14dc
MD5 a3f5fa6a59146af04d7b471f11f8035c
BLAKE2b-256 312a60179f1e77d7f4c5813a892fc7991e0feeae39795451e7ec801549f541a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 8a9eeccd43debbd765674d029cdf35ff9d9b83b716bddb19d54acdd55e64d2e3
MD5 77b51248959c9e94b434b6dd57d2b76f
BLAKE2b-256 15c3e60c2fe8cc6900d01307830b9130c274fdc5315ef6adaa6dcc61ac0909bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-win32.whl
Algorithm Hash digest
SHA256 bab2b12938067ed3e580195604eed1ffd8ede9ddbd433abe89229ec6fb16bfda
MD5 ad540bef484b25910fd8ccb453bf783b
BLAKE2b-256 eebedc57bcc5c576ba3759454a538eee6f785e87e8dc994098ea981988729396

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e58a3927b38188e67ec40e47732e39fc916880116660bae988532bcca1cc70e3
MD5 3228de461c9f375f68da07620dbe5b9f
BLAKE2b-256 0715a66df2bdc56aad0eb0be1ab3c67fee995e7cb346a3233803111349b5a495

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 080871bbbbbd641f17fd59a326028115e3e2c1429c9b5fb607e4193b22fde6d6
MD5 f22ef1ab367ad5a5075f0a0e48fc9417
BLAKE2b-256 4aab05f836a5736be67040b6821f4c215e4163f919b36ad414fb6a4f7be49e01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c61d525980ebb1001464934daa305a8939c027904be6453773ccebcaba18fd9b
MD5 e0e12c81047b50d4becdd9ee3ddb67c8
BLAKE2b-256 aade68d6e6ff263655706c10cd7d262ef631bb930182c671c32868eaeea608b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 377ca83aff0d48be45f2bd9dee3274f3ef4272cf8efac65830890c91574da742
MD5 959c93b5fa1c8a7ba5aaeb4ca155d7a1
BLAKE2b-256 88cdd21e33861345f32b5fff8845fd9f79eb076da3547c3dc5d64b48044f85af

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1a9297d657e2884df13ed84bd04f016cdf315e807c6bdace1d51571dd15a6352
MD5 0631f1bae99b4b949841e3920fb96c4e
BLAKE2b-256 9d5f811312ec6bb92e17db68d8aca91722a0f61e7fcab7fd8b0ff912df279f9f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-win32.whl.

File metadata

  • Download URL: natsort_rs-0.1.22-cp312-abi3-win32.whl
  • Upload date:
  • Size: 145.6 kB
  • Tags: CPython 3.12+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-win32.whl
Algorithm Hash digest
SHA256 fb86479a3d96e1e21f0ae7f12e2c1528dd71fc11c87b0c19bdf5c01eb543348b
MD5 3b29ae7c89c333cce49673a9dc5b260c
BLAKE2b-256 e4b3f7d5c99df23941401ac62464222fc317aa66246c85c20ed9f99d654dca7c

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1c47c5969b838d20fbcad88b0f50ed057c4f978a91a76ad3985930b41fb071a
MD5 76b005635cf372e8758ce0e9ae3de5b0
BLAKE2b-256 d861f71f37e4336ecfe3a415a58183f5f68404ff68bb0ed449941d620efd2fc2

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 55d5780d0bd5245ab3c9909794c8d7a457a9b6a7c1c135befab2061f6b390df1
MD5 ae0650059310fd2846b329a6e7658d3e
BLAKE2b-256 8844bc0508e4549e09ad8a8b3d30cea4c5c78f62ac884a7ce0075291280b196a

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c2b62e8dae5b926cfe643112a4b85eb8c606509becb5ac3cb5c3af56af074570
MD5 26afe51eaed199c84397326edcc60c4f
BLAKE2b-256 dd69e43aedb6cf3797a25f3331db5f6f05953f7c740503e93d59a6108a22e4ef

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 37274d2895fc3260a9cba5219837662dd1130c12b2b2ac80f76bea679704a08a
MD5 18483956e7fe1a3781a645b3af6fb889
BLAKE2b-256 ff9779f212f63d18c45a9ce82c6c4c675b0a3a01afeb189c764642fc48afa480

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