Skip to main content

A utility to sort files by type and date.

Project description

Sortium

PyPI version License: GPL v3

Sortium is a high-performance Python utility for rapidly organizing file systems. It emphasizes a safe, preview-first workflow that lets you plan and review categorized moves (by type, date, or regex) before anything changes on disk.

Designed for both speed and safety, it is memory-efficient for handling massive directories and automatically prevents file overwrites.


Table of Contents


Key Features

  • Plan-first workflow – Every sort emits an editable JSON plan so you can audit, tweak, version, or share the intended moves before running them.
  • Memory-efficient design – Uses generators and streaming I/O so it scales to very large trees without exhausting RAM.
  • Flexible sorting strategies – Built-in helpers for sorting by file type, modification date, or arbitrary regex patterns.
  • Collision-safe moves – Automatically generates unique destination names (e.g., image (1).jpg) to avoid overwriting files.
  • In-place or cross-volume moves – Choose to tidy a directory in situ or relocate everything into a dedicated archive folder.
  • Utility toolkitFileUtils exposes recursive scanners, directory flattening, tree export, and reversible plan execution.

Installation

From PyPI

To install the latest stable version from PyPI:

pip install sortium

From Source

To install the latest development version from the repository:

git clone https://github.com/Sarthak-G0yal/Sortium.git
cd Sortium
pip install -e .

Getting Started: Usage Examples

Here are a few examples to get you started quickly.

Example 1: Sort Files by Type

This is the most common use case. It now works in two phases: generate a plan, review/edit the JSON (optional), then apply it when you're ready.

from sortium.sorter import Sorter

# The folder you want to clean up
source_directory = "./my_messy_downloads_folder"

# Create a Sorter instance
sorter = Sorter()

# Phase 1: Generate an editable JSON plan
plan_path = sorter.sort_by_type(
  source_directory,
  recursive=True,  # include nested folders
)

# (Optional) Inspect / edit the JSON plan here
# ...

# Phase 2: Apply the plan when you're satisfied
sorter.file_utils.apply_move_plan(str(plan_path))
print(f"Applied plan {plan_path}")

# Need to undo? Re-use the same plan with reverse=True
sorter.file_utils.apply_move_plan(str(plan_path), reverse=True)

# Prefer a shallow cleanup? Drop recursive=True (it defaults to False).

Example 2: Sort Files to a Different Destination

Organize files from a source folder and move the categorized results to a completely different location.

from sortium.sorter import Sorter

source_dir = "./my_source_files"
destination_dir = "./organized_archive"

sorter = Sorter()

# Generate plan targeted at `destination_dir`
plan_path = sorter.sort_by_type(
  source_dir,
  dest_folder_path=destination_dir,
  plan_output="./sorting_plan.json",
  recursive=True,
)

# Review/edit sorting_plan.json if needed, then execute
sorter.file_utils.apply_move_plan(str(plan_path))

Example 3: Advanced Sorting with Regex

Recursively scan a directory and sort files based on custom patterns. This is great for organizing project files, logs, or datasets.

from sortium.sorter import Sorter

project_folder = "./my_data_science_project"
sorted_output = "./sorted_project_files"

# Define categories and their corresponding regex patterns
regex_map = {
    "Datasets": r".*\.csv$",
    "Notebooks": r".*\.ipynb$",
    "Python_Code": r".*\.py$",
    "Final_Reports": r"final_report_.*\.pdf$"
}

sorter = Sorter()
plan_path = sorter.sort_by_regex(project_folder, regex_map, sorted_output)
sorter.file_utils.apply_move_plan(str(plan_path))

Running Tests

To run the full test suite and generate a coverage report, first install the development dependencies:

pip install pytest pytest-cov

Then, from the project's root directory, run:

pytest --cov=sortium

For more details on the test structure, see the Test Suite README.


Documentation

This project uses Sphinx for documentation.

  • Online Documentation: View Documentation

  • To build the documentation locally:

    # Navigate to the docs directory
    cd docs
    # Install documentation requirements
    pip install -r requirements.txt
    # Build the HTML pages
    make html
    

    View the generated files at docs/_build/html/index.html.


Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or fix (feature/my-feature or fix/my-fix).
  3. Write tests that cover your changes.
  4. Commit your changes using clear, conventional messages.
  5. Open a pull request with a detailed description of your work.

Please follow the Conventional Commits specification. Ensure all code is linted and tested before submitting.


Author

Sarthak Goyal


License

This project is licensed under the GNU General Public License v3.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sortium-2.1.0.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sortium-2.1.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file sortium-2.1.0.tar.gz.

File metadata

  • Download URL: sortium-2.1.0.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sortium-2.1.0.tar.gz
Algorithm Hash digest
SHA256 1eb4f2ee3e16f8996595659fdfa60a60278cbbbb033f0e881973d3ab3eab28f0
MD5 ff511dda1640cf1037b4a36574f28543
BLAKE2b-256 fcb45eadf3c2c6afac0654f342eb33296bc03bc61f18b9f780de91ca3a545f8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sortium-2.1.0.tar.gz:

Publisher: release.yaml on Sarthak-G0yal/Sortium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sortium-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: sortium-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sortium-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24169dd1727233b850dc12c59dbf85953890f3f9c4b52190448ed25a3d8bd19e
MD5 8393a829f7be3db4ddbc27e2141100d8
BLAKE2b-256 97d8f1ad4b09421e85a9bcb2ff3b73614d4d849cece2b787fefd036b3c2aa98e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sortium-2.1.0-py3-none-any.whl:

Publisher: release.yaml on Sarthak-G0yal/Sortium

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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