Skip to content

Latest commit

 

History

History
141 lines (95 loc) · 4.63 KB

api.rst

File metadata and controls

141 lines (95 loc) · 4.63 KB

py

natsort

natsort API

Standard API

~natsort.natsorted

natsorted

The ~natsort.ns enum

ns

~natsort.natsort_key

natsort_key

~natsort.natsort_keygen

natsort_keygen

~natsort.os_sort_key

os_sort_key

~natsort.os_sort_keygen

os_sort_keygen

Convenience Functions

~natsort.os_sorted

os_sorted

~natsort.realsorted

realsorted

~natsort.humansorted

humansorted

~natsort.index_natsorted

index_natsorted

~natsort.index_realsorted

index_realsorted

~natsort.index_humansorted

index_humansorted

~natsort.order_by_index

order_by_index

Help With Bytes

The official stance of natsort is to not support bytes for sorting; there is just too much that can go wrong when trying to automate conversion between bytes and str. But rather than completely give up on bytes, natsort provides three functions that make it easy to quickly decode bytes to str so that sorting is possible.

decoder

as_ascii

as_utf8

Help With Creating Function Keys

If you need to create a complicated key argument to (for example) natsorted that is actually multiple functions called one after the other, the following function can help you easily perform this action. It is used internally to natsort, and has been exposed publicly for the convenience of the user.

chain_functions

If you need to be able to search your input for numbers using the same definition as natsort, you can do so using the following function. Given your chosen algorithm (selected using the ~natsort.ns enum), the corresponding regular expression to locate numbers will be returned.

numeric_regex_chooser

Help With Type Hinting

If you need to explicitly specify the types that natsort accepts or returns in your code, the following types have been exposed for your convenience.

Type Purpose
natsort.NatsortKeyType Returned by natsort.natsort_keygen, and type of natsort.natsort_key
natsort.OSSortKeyType Returned by natsort.os_sort_keygen, and type of natsort.os_sort_key
natsort.KeyType Type of key argument to natsort.natsorted and natsort.natsort_keygen
natsort.NatsortInType The input type of natsort.NatsortKeyType
natsort.NatsortOutType The output type of natsort.NatsortKeyType
natsort.NSType The type of the ns enum