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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file natsort_rs-0.1.21.tar.gz.
File metadata
- Download URL: natsort_rs-0.1.21.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bf674c2dc356ec96a0428c788249fb777cfe6e434b157223a0df121d4f67aeb
|
|
| MD5 |
b8f2a92c99603189a0140fbce8db4c2d
|
|
| BLAKE2b-256 |
b038675418b46e3bfb3994949b558c392f0aa296b568ff023b8a7d8640a62184
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-win_amd64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-win_amd64.whl
- Upload date:
- Size: 150.2 kB
- Tags: CPython 3.14t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17783cb6918042b384f4e86da10bc948fbabd05433800097b3a54e6244b711d3
|
|
| MD5 |
c91293d3e43a39bc4c1b2ce226a4f1c5
|
|
| BLAKE2b-256 |
d0e17a7e5faf1e11e5f7d00bcc55f4eb4a0214d5f69db0f185e46c40dba64379
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-win32.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-win32.whl
- Upload date:
- Size: 145.1 kB
- Tags: CPython 3.14t, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d271e5650cb93ef5a2247895dd6c6b2d29f58884460e97985299234469a5f7b6
|
|
| MD5 |
3b071f91e7f3f6cd64a597fc1c9e4b59
|
|
| BLAKE2b-256 |
0ac77eea61ae4337a004a5258e76844b9e21e2e0feffc89d3e89148eda2efdc6
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 254.0 kB
- Tags: CPython 3.14t, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
844ca8de7a2f64d9627581c3b2ec46401673b9f01566b9049ed09553dd8d6c01
|
|
| MD5 |
e0e3aefa2c33ae7d401e28b7c81efc96
|
|
| BLAKE2b-256 |
aea8c5f8fd4c8721b3cea11484f486f207afb048e5354bb3ae83175d955ae3be
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 238.2 kB
- Tags: CPython 3.14t, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c2d6141158993ab9177fc900118ca5fd6d826ae51b7282b1ab06a3d1789d05a
|
|
| MD5 |
e068f89f57a0f5e4f04ee3a4941295da
|
|
| BLAKE2b-256 |
d3805ee8f6c67dea854e0c74b7149a7133d10e693832322ff0122cfe4a0beea4
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-macosx_11_0_arm64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-macosx_11_0_arm64.whl
- Upload date:
- Size: 225.3 kB
- Tags: CPython 3.14t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6614a0fb502eaa9f4cb5bd42161369847c592f29f1abc7e7ec3f6b40da1738d8
|
|
| MD5 |
3edbace715c4751e2105968c4531dc7d
|
|
| BLAKE2b-256 |
458379c317c483fc7e32c5e96faf5eefa308d12641c24df9d4dcaca11f27c59b
|
File details
Details for the file natsort_rs-0.1.21-cp314-cp314t-macosx_10_12_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp314-cp314t-macosx_10_12_x86_64.whl
- Upload date:
- Size: 234.1 kB
- Tags: CPython 3.14t, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
281e9cb2054362a3aaef72196d077d9688198888b47274a1afba12d3bd8baad0
|
|
| MD5 |
ef69a297086d410c971612b26d146983
|
|
| BLAKE2b-256 |
481193c1afcdf46e104921490e7bf519b53fac7962010f3c2555d07784089ba6
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-win_amd64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-win_amd64.whl
- Upload date:
- Size: 150.3 kB
- Tags: CPython 3.13t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96daefbfeb8e441b5151c8a8f43867097fa4b4fe75a39465940c4edd5f17684a
|
|
| MD5 |
d258a084aca2e4ce5c46e18869c16d0b
|
|
| BLAKE2b-256 |
f633ddb677c0fcc1661822c44a263fdf879fdc7688d2a3f6a4c1edf0d0fe8b72
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-win32.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-win32.whl
- Upload date:
- Size: 145.1 kB
- Tags: CPython 3.13t, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2bd0260e6b8bcd83f2a832667edf77ec05cb20c4471fa49257a96aff3f87236
|
|
| MD5 |
bbf9a8b270fb2885301340e05e4ba741
|
|
| BLAKE2b-256 |
b10d0eab9f29890e10fe283ec46ee85dba8c7737b1c5980e6375acc6f2deb845
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 254.0 kB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc11df3c18147dc60a13ad2e7e5fa04c38b52b4deb48ae188a831d3aeac5a934
|
|
| MD5 |
200207a3d0d2a122a3812a79db77f581
|
|
| BLAKE2b-256 |
dc21ab0de6a00a6af3caf356141dfc10da93447acd0a1e36e8c5f1b39a148906
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 238.3 kB
- Tags: CPython 3.13t, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
902899d32140e621aa2c2d755ae798df1f04d61fec314518580ac9d6206018ac
|
|
| MD5 |
b277de3f8fd52d6c388e1571d97a18da
|
|
| BLAKE2b-256 |
f91fa16c8580448b69e69c71323ffa81c8433f3992461e632411d6088c331e72
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-macosx_11_0_arm64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-macosx_11_0_arm64.whl
- Upload date:
- Size: 225.5 kB
- Tags: CPython 3.13t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32b31c83017caef73c922e5cadb296508bed173dc59a5b25f80d6e56d6eb5b67
|
|
| MD5 |
f01e99d8cda4d8ae8e704fd6aa0b070c
|
|
| BLAKE2b-256 |
2902e72ad13964f286c018bb061a1c14ca2dcb742f849b19d948a6bf95c61e6c
|
File details
Details for the file natsort_rs-0.1.21-cp313-cp313t-macosx_10_12_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp313-cp313t-macosx_10_12_x86_64.whl
- Upload date:
- Size: 234.1 kB
- Tags: CPython 3.13t, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80880b99d8edd17ace94c5c9b73b16576d0035478050788a09c5d4013cb2a2bc
|
|
| MD5 |
5129c1e684a47bc02d20fc3bf187f2f9
|
|
| BLAKE2b-256 |
f8c0696550385200492bdfa8b794074f93c3d6e2f18184e9c4f53ba78173c656
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-win_amd64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-win_amd64.whl
- Upload date:
- Size: 152.8 kB
- Tags: CPython 3.11+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4be50a18b9de2d242c9c3adc2a88ff6fbb0aaf3e7f3efc433583a6271acca5b0
|
|
| MD5 |
b554c0f1032276c86a2fb686ce6057c0
|
|
| BLAKE2b-256 |
fcf44d6f48e9f8db05a09e83cbde316caa06cb24b089dfda83906ba3020c8aba
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-win32.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-win32.whl
- Upload date:
- Size: 147.6 kB
- Tags: CPython 3.11+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
690ad21eb23dbc57efa9e5b248cd1361345e502c7c0853b95be2bff603dbfd4f
|
|
| MD5 |
7b6c7804147dfb04e31e9fb0fd762c03
|
|
| BLAKE2b-256 |
5cf14740fd4257d06108a24d30493280710afbeda73fe8d63ac7f533ff45be36
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 257.8 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a498e7d21dd569ee50ba94139790f243aaea75b0a1770a2939df76b44556fc
|
|
| MD5 |
9d80da2092205efe9816f44158444ac2
|
|
| BLAKE2b-256 |
8219697838ed19bd833ebc8273b5de4a3566a1b072889ccb78460c66d8e007d2
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 240.5 kB
- Tags: CPython 3.11+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09d5ad74874515d03075ee823515530a27c2cf125c54ffb37f68ff0641f41709
|
|
| MD5 |
ba89ea31d6bf7139a2f422577bdf7e3e
|
|
| BLAKE2b-256 |
af6880a225a50d377d6cc9b4b34d67d600d0fe6b318f109ebdb527bc877c8262
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 227.6 kB
- Tags: CPython 3.11+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8113e32bcf42581ae6ba099aa75bff9aeed63d51d2853b2ce1efe20dcbc4377
|
|
| MD5 |
4149df70e9a2e68b497e9ffbc70697fe
|
|
| BLAKE2b-256 |
a617c6e595cc477862fd667749b21dc7bac54787ac5b5b63b153f0ee477542b2
|
File details
Details for the file natsort_rs-0.1.21-cp311-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: natsort_rs-0.1.21-cp311-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 236.5 kB
- Tags: CPython 3.11+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b246721481d6f67f04a70608b416c1c5347de5c660b029f076cd7434da4422f7
|
|
| MD5 |
050b85b1357b08dc3bec38dcf22c52ca
|
|
| BLAKE2b-256 |
a4380b463ef960b43257b04d7eab827ae76ec1ac338f3698cfd7651aebb49a30
|