A command-line tool for automatically sorting your Plex collections into a custom and meaningful order.
Plex doesn't offer a built-in way to sort a large collection by premiere date, latest episode, or audience rating. The only "custom" sort option in the Plex UI requires dragging and dropping each item into place by hand which is slow, tedious, and buggy.
Plex Collection Sorter connects to your Plex server and reorders a collection for you in seconds, using one of several automatic sort modes.
Plex Collection Sorter supports four sort modes:
- By show premiere date — newest shows first
- By most recent episode air date — shows with the newest episodes first
- By audience rating — highest rated shows first
- Alternating — combines the latest episode and audience rating sort method into every other item
Before anything is changed on your server, the script shows you a preview of the new sort order and then asks for confirmation.
- Python 3.9+
- A Plex Media Server you can reach (locally or remotely) with an authentication token
-
Clone or download this repository.
-
Install the dependencies:
pip3 install -r requirements.txt
-
Create your
.envfile from the provided example:cp .env.example .env
-
Open
.envand fill in your Plex server details (see below).
Plex Collection Sorter reads its connection details from a .env file in the project directory. An example is provided in .env.example:
PLEX_URL=http://localhost:32400
PLEX_TOKEN=your_plex_token_here- PLEX_URL — the address of your Plex server, including port. Use
http://localhost:32400if running the script on the same machine as Plex, orhttp://<server-ip>:32400. - PLEX_TOKEN — your Plex authentication token. See Plex's official guide for how to find it.
Run the script with the name of the collection you want to sort:
python3 sort_collection.py "Collection Name"You'll be prompted to choose a sort mode:
Sort mode:
1. Auto (by show premiere date, newest first)
2. Auto (by most recent episode air date, newest first)
3. Auto (by audience rating, highest first)
4. Auto (alternating: latest episode + audience rating)
Enter 1, 2, 3, or 4:
After you pick a mode, the script prints a full preview of the new order for every item in the collection. This allows you to confirm the sort method before anything changes. Confirm with y to apply the sort to Plex, or n to cancel without making any changes.
If you'd rather not cd into the project directory and type python3 every time, set up a shortcut command for your shell.
macOS / Linux (zsh or bash)
Add an alias to ~/.zshrc (zsh) or ~/.bashrc (bash):
alias plexsort="python3 /path/to/plex-sorter/sort_collection.py"Reload your shell config (source ~/.zshrc) or open a new terminal window, then run:
plexsort "Collection Name"Windows (PowerShell)
Add a function to your PowerShell profile (open it with notepad $PROFILE, creating the file if it doesn't exist):
function plexsort { python C:\path\to\plex-sorter\sort_collection.py $args }Reload your profile (. $PROFILE) or open a new terminal window, then run:
plexsort "Collection Name"This project is licensed under the MIT License.
Plex Collection Sorter is an independent, unofficial tool and is not affiliated with, endorsed by, or sponsored by Plex Inc. "Plex" is a trademark of Plex Inc.