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.20.tar.gz (12.2 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.20-cp314-cp314t-win_amd64.whl (137.4 kB view details)

Uploaded CPython 3.14tWindows x86-64

natsort_rs-0.1.20-cp314-cp314t-win32.whl (132.1 kB view details)

Uploaded CPython 3.14tWindows x86

natsort_rs-0.1.20-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.9 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.20-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (226.6 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.20-cp314-cp314t-macosx_11_0_arm64.whl (213.1 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

natsort_rs-0.1.20-cp314-cp314t-macosx_10_12_x86_64.whl (220.7 kB view details)

Uploaded CPython 3.14tmacOS 10.12+ x86-64

natsort_rs-0.1.20-cp313-cp313t-win_amd64.whl (137.3 kB view details)

Uploaded CPython 3.13tWindows x86-64

natsort_rs-0.1.20-cp313-cp313t-win32.whl (132.2 kB view details)

Uploaded CPython 3.13tWindows x86

natsort_rs-0.1.20-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (239.8 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

natsort_rs-0.1.20-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (226.6 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ARM64

natsort_rs-0.1.20-cp313-cp313t-macosx_11_0_arm64.whl (213.2 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

natsort_rs-0.1.20-cp313-cp313t-macosx_10_12_x86_64.whl (220.7 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

natsort_rs-0.1.20-cp311-abi3-win_amd64.whl (140.1 kB view details)

Uploaded CPython 3.11+Windows x86-64

natsort_rs-0.1.20-cp311-abi3-win32.whl (135.4 kB view details)

Uploaded CPython 3.11+Windows x86

natsort_rs-0.1.20-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (244.3 kB view details)

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

natsort_rs-0.1.20-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (230.0 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

natsort_rs-0.1.20-cp311-abi3-macosx_11_0_arm64.whl (216.2 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

natsort_rs-0.1.20-cp311-abi3-macosx_10_12_x86_64.whl (224.4 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for natsort_rs-0.1.20.tar.gz
Algorithm Hash digest
SHA256 059bdfbcd8cc1b847f8dd150c1a1d7b07ab04b6dd749325375dc6aef6699a433
MD5 9ba86bc522debe8cbf195fc97039a7ef
BLAKE2b-256 0a562cf45bbe6e44dae5e5360b4a3c4ed1b86831464fae8b56a5773e6c960588

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 eb46b2499a29220e9c15036293da8e013ed77d8167648044f026f44dc46c0a49
MD5 81d32ecbae01b9fe4922f706f6f43107
BLAKE2b-256 528871cd306fbdbdd1ffd1ec61550df9660498d076f60b847fcdc4a38701daa8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 c8b05d77698ebfb3e5f4bea37dbb30f31091ea587cf6fa3c74df9c8c399acb85
MD5 f1cf3d5d6c5d5daa8ca6a963e0cd9ad4
BLAKE2b-256 7c2c09d0a0fce9d82e076e463eeb620fb2d18e77b973acafe9a522c90a70eda0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1c224e69b8969cae8cb9c60e31c315d293c6563bf3521698d8ac383107820083
MD5 ca9b9d1482e0dc0830c327c1ff157b82
BLAKE2b-256 97c7dd3faf0d5a5604d0435971428035f23415a4fe401f2271555de9b7ff36f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5a9c310116f95632956414a86fcb572c6c8b1ae39b40a7b86358fd8267f6393d
MD5 7c875383eca76210a7cee0068f62c916
BLAKE2b-256 6b7ea446b33605f277438d2805547484d0b005f35d02407a2f525a9a7afd3c60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ff5ef69aec031d59d7f0333996be6391deb31cac04a24e053c7e9b4c7fdb6a39
MD5 85b5053d278eeed0b638e26ec361d143
BLAKE2b-256 db2f2a06779bf8076eb6e708ac263f3689283151b7997da02daf47d2f55e68f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp314-cp314t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 250c8d54043eb2e3f0c15031b6b6150cda31ecacd310f53dfced58886f3fa50e
MD5 df24ea89ef493f28e1ab2ef534019e4c
BLAKE2b-256 0812f441f2c91e8981216d2a758e812250cf12d398f7ea9839431f2e90bda80a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 0863ddbf43d8f3f6b6994a18700fb37511e48b415e3d9e9bbcb330826aadf2a1
MD5 7ccd6dc4bebbbdc7853ee793d60ea181
BLAKE2b-256 56fe593d719532846c2a9272a519f3783eaa3126ca3b6905ef036841a93be812

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-win32.whl
Algorithm Hash digest
SHA256 9399237573299fdb10b5432503b999afd075a16afcf77543dd28f5a63ee3c8cf
MD5 d74133dc8042c6e0dd3802c65fbbe203
BLAKE2b-256 ea350198fcf8a0579ee717584f97822e02912170ef260d21f7fd7f228222c58c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a23c312113e02af512add9a7b5814598a4969cd5a2ace6fbc00fbeb3d6c1d4c
MD5 2c887db5208d8f3de5a30195bc70223c
BLAKE2b-256 6f281ab0da80bb1c5bb2aa2d0e5ff6f95ceb9ac045847cee7894146ace342f65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c07e3c56a78aed4bd4ab18aca1bc759756b77d5836db70e1f4592223c409b2c5
MD5 de7379fec34c59be28fbaeac846eff3d
BLAKE2b-256 6961c64c2c77a198e103befebe4957ca4aec745aa3475bf2720bccc7d4229be3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35b19a62443a4894bef666bc766b619704ab8231645026f610277e3d92630a41
MD5 8f2c12c35d7a20aad2231e9c3c3af381
BLAKE2b-256 db169df7b595983cb46ee60a99cd29797519f1fa717874f5d73603c9da30c6fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 736f15391a8c06ba17d4388aef8c369011c9e428be950fe9d2a3ac18d6a1f3b3
MD5 4e4d5075c6b8633f5eea6615d68ac803
BLAKE2b-256 d64410c0b5c1691c963beb74a4172f663cbcfb25983fba32a54a48fb73241aa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bcec2972865122b809da6689990bbb31165588e54e31428f50175eb15eb1d95a
MD5 2ff66237ee98ab086b474a514fc40404
BLAKE2b-256 4bad98e60de7c828ae86640a09d94dbfce4568b45896012e33207013de9ce0eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: natsort_rs-0.1.20-cp311-abi3-win32.whl
  • Upload date:
  • Size: 135.4 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.20-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 fa9697e72a2d0c4c9555f37a15fcb816251a083a6aed3c618b1b6fce13f02d62
MD5 baa658d55c8c4267be6e26d8d3dd03dd
BLAKE2b-256 34563f03c58932fd33ba6810b427be3ce12f352a113100e54b13b76fb5f1b5a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4f56de2abe6861926a89b7b92fd2bb896e0cc3315f995d87a78ad5ce6d295e4
MD5 18926625263bf307ec1317f041dfde03
BLAKE2b-256 4a44a0de23887a4f5cf55f70579f9dc67f4645c8bfd7a4bcc3ef53d49467f997

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3b4508df5c1109b2cef9631bd90518c17d07c85da15a87c5fb9299da5ce06f7c
MD5 150e6f49075e18f2cb95a77de79e941a
BLAKE2b-256 93c60bb2354184fae9e554da3197896ab535cf6c48d57b407fd8960b93ebdd68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 666b679690953137b85a93f718926bd3da9e64c732f7ca1f7fb4e1428aa802db
MD5 3df1e42ccc2ed2440894c712dac3ce16
BLAKE2b-256 b28da207b2b8993e4bacdf09a302f1da49fcbfc73e74fc751d70bd129fe31f5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for natsort_rs-0.1.20-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af467caaa52bba71acac135e65c551624bf15c2bab354aad92046b4797056a53
MD5 3841b3fd129ca040a053f52990938bee
BLAKE2b-256 23d01a27707f3fa0f5288dd3cc344e53d0b5bce9a0b8e72bc6e7ec68f8cd11f4

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