Skip to main content

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

Metadata

Release files for natsort-rs 0.1.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for natsort-rs 0.1.22
File
natsort_rs-0.1.22-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
natsort_rs-0.1.22-cp314-cp314t-win32.whl CPython 3.14 CPython 3.14 free-threading Windows x86-32 Details
natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
natsort_rs-0.1.22-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
natsort_rs-0.1.22-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
natsort_rs-0.1.22-cp313-cp313t-win_amd64.whl CPython 3.13 CPython 3.13 free-threading Windows x86-64 Details
natsort_rs-0.1.22-cp313-cp313t-win32.whl CPython 3.13 CPython 3.13 free-threading Windows x86-32 Details
natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ x86-64 Details
natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64 Details
natsort_rs-0.1.22-cp313-cp313t-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 free-threading macOS 11.0+ ARM64 Details
natsort_rs-0.1.22-cp313-cp313t-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 free-threading macOS 10.12+ x86-64 Details
natsort_rs-0.1.22-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details
natsort_rs-0.1.22-cp312-abi3-win32.whl CPython 3.12 abi3 Windows x86-32 Details
natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 abi3 Linux glibc 2.17+ x86-64 Details
natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.12 abi3 Linux glibc 2.17+ ARM64 Details
natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details
natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl CPython 3.12 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.7 MB

Release files / natsort_rs-0.1.22-cp314-cp314t-win_amd64.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-win_amd64.whl
Size 150.0 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
209fe4db4f05159d110c851c04a2861796a8b9424cb99ccdb295b9427c6d03de
BLAKE2b-256 checksum
How to use checksums
e2b467e6a837aacae6d3958bf51cad7b0471e55c049b3d6a210b3fe13d3d4fc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp314-cp314t-win32.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-win32.whl
Size 144.9 kB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-32
SHA-256 checksum
How to use checksums
2879ee6a39e292731ef5c9d4e7e9317c02a34887fb77d7bffd711bd7a43050d4
BLAKE2b-256 checksum
How to use checksums
e7b7ff9cf0d7e189d7ec7548d0fd96cc4002d19ff0198585374e1beb3d37cbb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 251.6 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
30faf0f3e0acd525723c2eb8d0ab15163321fdcdfa32f2e2c810380651d7fa52
BLAKE2b-256 checksum
How to use checksums
d51bc7582aaf538638a9d627b8407bf41ec70badad77c63ed63825996699771f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 238.9 kB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
4deca61f992f8359843c7855b79247352d179847d2a18cf388a0db8194d29760
BLAKE2b-256 checksum
How to use checksums
1ef61c71c933503f85160c2cdc55ebdf31cf478045f18a046934311f477125ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp314-cp314t-macosx_11_0_arm64.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-macosx_11_0_arm64.whl
Size 225.5 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9eb1465e8c22b16f264ef3a247bfba63d112f471ee3001d3b33455f82c4a2dd1
BLAKE2b-256 checksum
How to use checksums
387713c8af36d6f0803c55b61592a38e2cebebf71e399db00e1db16bcacbc67b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL natsort_rs-0.1.22-cp314-cp314t-macosx_10_12_x86_64.whl
Size 232.2 kB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
8346e9d5322edbe7cabc4e88d5e36f78bda771418b8a46ba36d0d5ebc15a14dc
BLAKE2b-256 checksum
How to use checksums
312a60179f1e77d7f4c5813a892fc7991e0feeae39795451e7ec801549f541a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-win_amd64.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-win_amd64.whl
Size 149.9 kB
Tags CPython 3.13 CPython 3.13 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
8a9eeccd43debbd765674d029cdf35ff9d9b83b716bddb19d54acdd55e64d2e3
BLAKE2b-256 checksum
How to use checksums
15c3e60c2fe8cc6900d01307830b9130c274fdc5315ef6adaa6dcc61ac0909bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-win32.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-win32.whl
Size 144.8 kB
Tags CPython 3.13 CPython 3.13 free-threading Windows x86-32
SHA-256 checksum
How to use checksums
bab2b12938067ed3e580195604eed1ffd8ede9ddbd433abe89229ec6fb16bfda
BLAKE2b-256 checksum
How to use checksums
eebedc57bcc5c576ba3759454a538eee6f785e87e8dc994098ea981988729396
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 251.3 kB
Tags CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e58a3927b38188e67ec40e47732e39fc916880116660bae988532bcca1cc70e3
BLAKE2b-256 checksum
How to use checksums
0715a66df2bdc56aad0eb0be1ab3c67fee995e7cb346a3233803111349b5a495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 238.9 kB
Tags CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
080871bbbbbd641f17fd59a326028115e3e2c1429c9b5fb607e4193b22fde6d6
BLAKE2b-256 checksum
How to use checksums
4aab05f836a5736be67040b6821f4c215e4163f919b36ad414fb6a4f7be49e01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-macosx_11_0_arm64.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-macosx_11_0_arm64.whl
Size 225.6 kB
Tags CPython 3.13 CPython 3.13 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c61d525980ebb1001464934daa305a8939c027904be6453773ccebcaba18fd9b
BLAKE2b-256 checksum
How to use checksums
aade68d6e6ff263655706c10cd7d262ef631bb930182c671c32868eaeea608b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp313-cp313t-macosx_10_12_x86_64.whl

Download URL natsort_rs-0.1.22-cp313-cp313t-macosx_10_12_x86_64.whl
Size 232.4 kB
Tags CPython 3.13 CPython 3.13 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
377ca83aff0d48be45f2bd9dee3274f3ef4272cf8efac65830890c91574da742
BLAKE2b-256 checksum
How to use checksums
88cdd21e33861345f32b5fff8845fd9f79eb076da3547c3dc5d64b48044f85af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-win_amd64.whl

Download URL natsort_rs-0.1.22-cp312-abi3-win_amd64.whl
Size 151.5 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1a9297d657e2884df13ed84bd04f016cdf315e807c6bdace1d51571dd15a6352
BLAKE2b-256 checksum
How to use checksums
9d5f811312ec6bb92e17db68d8aca91722a0f61e7fcab7fd8b0ff912df279f9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-win32.whl

Download URL natsort_rs-0.1.22-cp312-abi3-win32.whl
Size 145.6 kB
Tags CPython 3.12 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
fb86479a3d96e1e21f0ae7f12e2c1528dd71fc11c87b0c19bdf5c01eb543348b
BLAKE2b-256 checksum
How to use checksums
e4b3f7d5c99df23941401ac62464222fc317aa66246c85c20ed9f99d654dca7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 253.8 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a1c47c5969b838d20fbcad88b0f50ed057c4f978a91a76ad3985930b41fb071a
BLAKE2b-256 checksum
How to use checksums
d861f71f37e4336ecfe3a415a58183f5f68404ff68bb0ed449941d620efd2fc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL natsort_rs-0.1.22-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 240.3 kB
Tags CPython 3.12 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
55d5780d0bd5245ab3c9909794c8d7a457a9b6a7c1c135befab2061f6b390df1
BLAKE2b-256 checksum
How to use checksums
8844bc0508e4549e09ad8a8b3d30cea4c5c78f62ac884a7ce0075291280b196a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl

Download URL natsort_rs-0.1.22-cp312-abi3-macosx_11_0_arm64.whl
Size 227.5 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c2b62e8dae5b926cfe643112a4b85eb8c606509becb5ac3cb5c3af56af074570
BLAKE2b-256 checksum
How to use checksums
dd69e43aedb6cf3797a25f3331db5f6f05953f7c740503e93d59a6108a22e4ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl

Download URL natsort_rs-0.1.22-cp312-abi3-macosx_10_12_x86_64.whl
Size 234.1 kB
Tags CPython 3.12 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
37274d2895fc3260a9cba5219837662dd1130c12b2b2ac80f76bea679704a08a
BLAKE2b-256 checksum
How to use checksums
ff9779f212f63d18c45a9ce82c6c4c675b0a3a01afeb189c764642fc48afa480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page