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]

Turn off multithreading

Multithreading is currently experimental and can be turned on by setting parallel = True.

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.

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

natsort_rs-0.1.10-cp311-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10-cp311-cp311-macosx_11_0_arm64.whl (235.8 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.10-cp311-cp311-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.11 macOS 10.7+ x86-64

natsort_rs-0.1.10-cp310-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10-cp310-cp310-macosx_11_0_arm64.whl (235.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.10-cp310-cp310-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

natsort_rs-0.1.10-cp39-none-win_amd64.whl (168.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10-cp39-cp39-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

natsort_rs-0.1.10-cp38-none-win_amd64.whl (168.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (275.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

natsort_rs-0.1.10-cp38-cp38-macosx_10_7_x86_64.whl (248.4 kB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

File details

Details for the file natsort_rs-0.1.10-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 573e7363ca29b2e9e27f3b873aa1661857751e016e8e562febe1a53573a00fd1
MD5 6cf478b030edc63b8cfe691679b648b6
BLAKE2b-256 23d00241132934460d697c75e528b2c5db61c25e400870f85eb1e92fbbbef4dd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0deb933d221191c0445eb198b7e5ad9b753ca5771db3db973110068eb44cace3
MD5 a7fd66ade31c70dac9dcd1a501aa727a
BLAKE2b-256 35f643576116c374e69890d5d1b88911c830b9c02857c0edc95562130caf3f37

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a334e13ff98172f9697df99d230ea857630c60e891ab25ed5a9797049dfa6d1
MD5 fc2bc0da5f674a4130b8e546a5e010f5
BLAKE2b-256 f56da2e76feca85e325fd0999607fc74d303ce69ac5fa88771c213ec411d121e

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp311-cp311-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 6a7aed301ffdf628245ded6e0d46c5d0e69f0b57998399f978d93814c3377517
MD5 ba59cb9847483b1d3132378cd5ac3a3f
BLAKE2b-256 65f4ba7081add3fc633042f1821acb291dd6c5a79f10ee5680f349b7322fcf03

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 b1e88c7d6ddfb1b8ebac1930881cf56e9d47f5b0620d5d085ed7770c566566c6
MD5 ddb5a41edc1704694bb54eef133a70db
BLAKE2b-256 fbbcce01c5e1d766da8fb90e2b328fd0955f7f3675f770e20d66a3878e8301a4

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e48c828ef6bc72515726cd13d3cd84154c18c2e62fadfb206d3fbc895258f9d1
MD5 89ca1ea4effdeeef9d6c9d82437597d7
BLAKE2b-256 895e51e42a8e87f96e53d100a181a02024a2fbfc33a22ca6df6f23ef6a67b4ab

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6b0a266d5c7169520f7ace3760532d7c5b989d4cd985c55bf3bd22e0c61118f
MD5 dee254fc6c520a014f86c69595e532b5
BLAKE2b-256 16a076857491d33dc8c0aaeb8cd96ddefd57f018b4ae7b369a8c8249fc00e042

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 186420dff3bead9e69b427bbf10627105a2251e43cf2a6f82ac96a26c217bc61
MD5 9e4897c33e28e5b45f3eb9ca756fbd78
BLAKE2b-256 71164189bc854e3c9efa98b29fabbde8ce50439c1c161b2f9d284b4f3e66e9e8

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ef4108007dbdf67ed7259a2d290aa2baebaba8ba56bca7e24ca1aff1171ccdfb
MD5 0add573991c1069ae51ad59cfa5c519b
BLAKE2b-256 20674ee256b09cc146b0448f48bc2cf6385df696ed745b3c3b1e573b1dda2ff5

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96b36533636f36755649c749ba8d978bb2cadb443c53d5194983ba951e8a9bdc
MD5 4d26006c84bf106a209f001120037c5f
BLAKE2b-256 fbb966f121d01a9a7ad08efe7873eed2e983547f3259554485b929789e09126d

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 28e5a0e63b3c0eacc3f5f91d2d6845685872efe4609e5a830de302d6dfd8ce39
MD5 ee4a441d8450c07d1e36bc92b7c90983
BLAKE2b-256 9bed797c6084e0eaa5a2b495f2ab0266e1f7ea9846a6f1c91b6d7bf6aff09c7f

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 b88c5aa52e1bbcb94a86f5a505a9afde8c4c6182a2a34e402c1bcf07418136a5
MD5 515128dd67eef673d26c1474b0a3aa29
BLAKE2b-256 29c9743216c74326296d86045215b1c09eaa5ba3bfa29cf605404bcf944e52bd

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 476a5c3f340f5799e706bd9a4115d705cb4c35a458be27b63338e05892f781b2
MD5 5ae27d4b7aa69d4fc71ce7307b1f50a8
BLAKE2b-256 2c89c482623e089471b57aab95b48c1029f963e66bc91a2310c3b0f6e1b990b8

See more details on using hashes here.

File details

Details for the file natsort_rs-0.1.10-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for natsort_rs-0.1.10-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c10c42a03c18e8b5b995e95bc14a42fdb2fbe509eca5e04d13fd804885b3de79
MD5 9453e04bf64e9c8b587755d05710db94
BLAKE2b-256 256093c5b8a234b7c364f1e6a3149d55edc07fa9524553a67f9459b22b5e74e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page