python-natsort
Port variant v13
Summary Simple yet flexible natural sorting (3.13)
Package version 8.4.0
Homepage https://github.com/SethMMorton/natsort
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v14
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 20 JUN 2026, 20:59:57 UTC
Port created 20 JUN 2026, 20:59:57 UTC
Subpackage Descriptions
single natsort ======= Simple yet flexible natural sorting in Python. - Source Code: https://github.com/SethMMorton/natsort - Downloads: https://pypi.org/project/natsort/ - Documentation: https://natsort.readthedocs.io/ - `Examples and Recipes`_ - `How Does Natsort Work?`_ - `API`_ - `Quick Description`_ - `Quick Examples`_ - `FAQ`_ - `Requirements`_ - `Optional Dependencies`_ - `Installation`_ - `How to Run Tests`_ - `How to Build Documentation`_ - `Dropped Deprecated APIs`_ - `History`_ **NOTE**: Please see the `Dropped Deprecated APIs`_ section for changes. Quick Description ----------------- When you try to sort a list of strings that contain numbers, the normal python sort algorithm sorts lexicographically, so you might not get the results that you expect: .. code-block:: pycon >>> a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in'] >>> sorted(a) ['1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '2 ft 7 in', '7 ft 6 in'] Notice that it has the order ('1', '10', '2') - this is because the list is being sorted in lexicographical order, which sorts numbers like you would letters (i.e. 'b', 'ba', 'c'). `natsort`_ provides a function `natsorted()`_ that helps sort lists "naturally" ("naturally" is rather ill-defined, but in general it means sorting based on meaning and not computer code point). Using `natsorted()`_ is simple: .. code-block:: pycon >>> from natsort import natsorted >>> a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in'] >>> natsorted(a) ['1 ft 5 in', '2 ft 7 in', '2 ft 11 in', '7 ft 6 in', '10 ft 2 in'] `natsorted()`_ identifies numbers anywhere in a string and sorts them naturally. Below are some other things you can do with `natsort`_ (also see the `Examples and Recipes`_ for a quick start guide, or the `API`_ for complete details). **Note**: `natsorted()`_ is designed to be a drop-in replacement for the built-in `sorted()`_ function. Like `sorted()`_, `natsorted()`_ `does not sort in-place`. To sort a list and assign the output to the same variable, you must explicitly assign the output to a variable: .. code-block:: pycon >>> a = ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in'] >>> natsorted(a) ['1 ft 5 in', '2 ft 7 in', '2 ft 11 in', '7 ft 6 in', '10 ft 2 in'] >>> print(a) # 'a' was not sorted; "natsorted" simply returned a sorted list ['2 ft 7 in', '1 ft 5 in', '10 ft 2 in', '2 ft 11 in', '7 ft 6 in'] >>> a = natsorted(a) # Now 'a' will be sorted because the sorted list was assigned to 'a' >>> print(a) ['1 ft 5 in', '2 ft 7 in', '2 ft 11 in', '7 ft 6 in', '10 ft 2 in'] Please see `Generating a Reusable Sorting Key and Sorting In-Place`_ for an alternate way to sort in-place naturally. Quick Examples -------------- - `Sorting Versions`_ - `Sort Paths Like My File Browser (e.g. Windows Explorer on Windows)`_ - `Sorting by Real Numbers (i.e. Signed Floats)`_ - `Locale-Aware Sorting (or "Human Sorting")`_ - `Further Customizing Natsort`_ - `Sorting Mixed Types`_ - `Handling Bytes`_ - `Generating a Reusable Sorting Key and Sorting In-Place`_ - `Other Useful Things`_ Sorting Versions
Configuration Switches (platform-specific settings discarded)
PY313 ON Build using Python 3.13 PY314 OFF Build using Python 3.14
Package Dependencies by Type
Build (only) python313:dev:std
python-pip:single:v13
autoselect-python:single:std
Build and Runtime python313:primary:std
Download groups
main mirror://PYPIWHL/ef/82/7a9d0550484a62c6da82858ee9419f3dd1ccc9aa1c26a1e43da3ecd20b0d
Distribution File Information
4732914fb471f56b5cce04d7bae6f164a592c7712e1c85f9ef585e197299521c 38268 python-src/natsort-8.4.0-py3-none-any.whl
Ports that require python-natsort:v13
python-xml2rfc:v13 Request For Comment authoring with XML (3.13)