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 🚀

Warning: This is a pre-alpha library. It should not yet be used for production code.

Installation

Find package files on PyPI.

Examples

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}]

Benchmark

No. of items natsort [s] natsort-rs [s] speedup [-]
10 0.00006 0.00000 17.0
100 0.00071 0.00003 24.6
1000 0.00285 0.00036 7.9
10000 0.02892 0.00462 6.3
100000 0.29960 0.06098 4.9
1000000 3.33878 0.80086 4.2

Execute benchmark.py to reproduce the results.

Credits

This Python module is build on top of the human-sort 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.6-cp311-none-win_amd64.whl (123.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

natsort_rs-0.1.6-cp311-cp311-manylinux_2_34_x86_64.whl (223.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.6-cp311-cp311-macosx_11_0_arm64.whl (192.0 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

natsort_rs-0.1.6-cp311-cp311-macosx_10_7_x86_64.whl (200.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

natsort_rs-0.1.6-cp310-none-win_amd64.whl (123.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

natsort_rs-0.1.6-cp310-cp310-manylinux_2_34_x86_64.whl (223.0 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.6-cp310-cp310-macosx_11_0_arm64.whl (192.0 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

natsort_rs-0.1.6-cp310-cp310-macosx_10_7_x86_64.whl (200.7 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

natsort_rs-0.1.6-cp39-none-win_amd64.whl (123.0 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

natsort_rs-0.1.6-cp39-cp39-manylinux_2_34_x86_64.whl (223.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.6-cp39-cp39-macosx_10_7_x86_64.whl (200.5 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

natsort_rs-0.1.6-cp38-none-win_amd64.whl (122.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

natsort_rs-0.1.6-cp38-cp38-manylinux_2_34_x86_64.whl (223.1 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.34+ x86-64

natsort_rs-0.1.6-cp38-cp38-macosx_10_7_x86_64.whl (200.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

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