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.

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 Distribution

natsort_rs-0.1.19.tar.gz (10.6 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.19-cp314-cp314t-win_amd64.whl (128.5 kB view details)

Uploaded CPython 3.14tWindows x86-64

natsort_rs-0.1.19-cp314-cp314t-win32.whl (124.3 kB view details)

Uploaded CPython 3.14tWindows x86

natsort_rs-0.1.19-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.2 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.19-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (219.2 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.19-cp314-cp314t-macosx_11_0_arm64.whl (205.6 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

natsort_rs-0.1.19-cp314-cp314t-macosx_10_12_x86_64.whl (211.6 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

natsort_rs-0.1.19-cp313-cp313t-win_amd64.whl (128.5 kB view details)

Uploaded CPython 3.13tWindows x86-64

natsort_rs-0.1.19-cp313-cp313t-win32.whl (124.4 kB view details)

Uploaded CPython 3.13tWindows x86

natsort_rs-0.1.19-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (231.1 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.19-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (219.3 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.19-cp313-cp313t-macosx_11_0_arm64.whl (205.8 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

natsort_rs-0.1.19-cp313-cp313t-macosx_10_12_x86_64.whl (211.7 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

natsort_rs-0.1.19-cp311-abi3-win_amd64.whl (131.7 kB view details)

Uploaded CPython 3.11+Windows x86-64

natsort_rs-0.1.19-cp311-abi3-win32.whl (127.3 kB view details)

Uploaded CPython 3.11+Windows x86

natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (235.7 kB view details)

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

natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (222.5 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

natsort_rs-0.1.19-cp311-abi3-macosx_11_0_arm64.whl (208.6 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

natsort_rs-0.1.19-cp311-abi3-macosx_10_12_x86_64.whl (215.1 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for natsort_rs-0.1.19.tar.gz
Algorithm Hash digest
SHA256 be912b7605a657d05ff43823708a22c9cf7e98875faa2c740c0db78c0f421ffa
MD5 9993dbb76ad5aa8700b94d0716c1312c
BLAKE2b-256 05a1f35706f265b3b783f77dd77d93cd12895b7dfacba9360b4b239c90e9da03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 5e9035aa93aec013f4dcad2ad0b60fd972c6386d3a611c963edfd60525b1d0f5
MD5 ea844ba5fe841718c84701074f9b5d3d
BLAKE2b-256 b92c4080cf721f8263a95129c768be2ca3d980ebc560d7514978a37ce0a6ad87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 a1b8518162fd3bd700d65da20c05dabf1a5a0239a8e211dd4f37efa47fd7d3b4
MD5 d548c5ed748092d6e043a5b5d4b929c9
BLAKE2b-256 64b18ab3d045d0306b03501983f64b2f9f115a481d110be0f4d5558135119ef0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59dc9e5b16ea64a81460cdb42a60c4f9353eeff6ee431724a21783e760a4a457
MD5 94b0433ef9cad33998d667e41d6796a3
BLAKE2b-256 f58c1a9b2fbf312b780ce15e54b26cd90e789f8665e47a6c4abf0c6279fcf56b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5cf22504e2818d0606eea4fb98246a34382e78aaba74b1e1e84faffcc4ae5d82
MD5 03e2772308fb88533810487f8a848ffd
BLAKE2b-256 43ebd847e25e080e9bdec1583d0f9783488bbf5b54897c8aedfbc3a20b244125

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb9bd412eceed1d23e125475e4733a3f80094d4f25bb8a7d5095b9816237f74d
MD5 dc63bac857f60aee70bd4f8d36151386
BLAKE2b-256 1b4a795823e839883a455a574a427ef40483c360c2784c54666a84196b1b16b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c3f27768467df3f060551432a3b433e9f3424f6878e40cf6f9b863beb8e52b47
MD5 d375371058af372c688666640530979f
BLAKE2b-256 b6fc17429ad20b3874e3cf868348e41971e09266f4aeea972b0e40e259febd34

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 7581e0c7b957945a4a755a70b47a5f264a8c57ad2f7f7a946cc7d5e1a7611457
MD5 79a283d5213402c7f51cf14bad249819
BLAKE2b-256 a26c1d4e1ad9a9bee303944967e2ad7387158173e678f06f89893e3996b69723

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-win32.whl
Algorithm Hash digest
SHA256 43d67a2fb2b91c3fb3f7de15b9fe34a18cb8c590dca5828eed30251760c611a3
MD5 ed7a674bc300536f21e2da50d2e04d4b
BLAKE2b-256 44084ec2389eacdd2b50f25b036d304f2e3b5741b3dcfd6cf4d1e623c5737816

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64222a83530205e83f876b90b256be90b2471c58ae18e310c3fb39914e12616a
MD5 a87b5555aa79445a99385f97e42080d5
BLAKE2b-256 cab54a1b1d5e44ed58a0d08496e302bc1c7043e8db0f0dab644e721d736961ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d9420d64be84c6437cc9d6c9a1637874b7198df908685787431bae61a753ede4
MD5 56d8bd4ca715fb2ab0cdeb3389633688
BLAKE2b-256 1d726c761f09eb4623c06e7096eab25d494ac03e044d87d9832a8c731bdad82b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bba498ef2c6f401ba167bf352978a4f0293d8bf06d88451c2ac6eb90edf4d5d6
MD5 34b2757de591bcc513f80b11363768ad
BLAKE2b-256 79a60f7161f350ba5b37c03d1c3ce5e860c7a89cf26845a5d6d177464949ffc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 422a59d778f95739d94521b8db5fbb7f545d4250e70e1aab70c46c78cb1e731a
MD5 bf921c1c4358e256c95ea88f17bd686d
BLAKE2b-256 a16b64b3e31d06e7abfb144f298b1ece1cf19cbcf1306bbc031d5275e697d696

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5da06dc9ef008aad43106f54405470b06a58506d18d37ca69bef40c726e87b8b
MD5 7287d5ad0026edce5d017f00d057d459
BLAKE2b-256 bb242d610dd5df71b4fddd47843eb2612a4ea2581d32dcff4683e0f05b40ad0b

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-win32.whl.

File metadata

  • Download URL: natsort_rs-0.1.19-cp311-abi3-win32.whl
  • Upload date:
  • Size: 127.3 kB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 b7bcea0abb4501a71dfb3141c0d6d0da326ce182b631ea8cec930471e5481719
MD5 50fa81eefd016e1358952e7d4eb93450
BLAKE2b-256 566c3ff5a8f3bd430288ad2eff53a8bbb877f4eef98e5881ab4908f0ea2abdbf

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 927fc139425545d0a48f924f271e14df57fb774de47e97c93a1210320f332414
MD5 af0f9c0b1f1d638831fc6acf9f850339
BLAKE2b-256 01801cdf79b7b177004378a96aad3d058cff9a66efd9285949adadda9a0b0bdd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 daa301ed94c3a5c6672ef276cb163beb4ce131a290c6940acb9d2ff04e88233c
MD5 e25dcea0074ef215aca96b0bc7cc3577
BLAKE2b-256 50e097523cca3068c1ff92ebc435e27cc83327e5aeff61fb0929b15c53b62f9c

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5cd4201af7554d56a0d4e9d9d531fa7527eb5c231030fc58b31f4566e3d6d9d7
MD5 b1bbbb68816fea827c03a45a77104381
BLAKE2b-256 562f982bdd39854a3979b2df2bdb0fcaeb09dab2aec924d7d5d10f9df28a0337

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.19-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.19-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 689f48dcac74855cf316e49deb67a2fab74ef7ddbc4c018ff864d12d883c0a94
MD5 2ef2134870ab11cb1e925deddd139b62
BLAKE2b-256 b37c2633744a2c7426568f170edb8e1ca71a3349162585c36127cc168fc392a1

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