Skip to main content

sdsort

Sorts top-level functions and class methods in Python files according to the step-down rule, as described in Robert C. Martin's Clean Code. More concretely, functions and methods are ordered in a depth-first-traversal order of the dependency tree, so higher-level code appears before lower-level code.

Installation

pip install sdsort

Or run directly with uv:

uvx sdsort <path>

Usage

To target individual files, run the sdsort command, followed by the paths to the files that should be sorted:

sdsort <file_1> <file_2>

To sort all *.py files in a directory, and all of its subdirectories, run the sdsort command followed by the directory path:

sdsort <directory_path>

To check if files are already sorted without modifying them, use the --check flag:

sdsort --check <file_or_directory>

This will exit with code 1 if any files would be re-arranged, making it suitable for CI pipelines and pre-commit hooks.

Configuration

Skipping a file

To prevent sdsort from modifying a particular file, add a # sdsort: skip_file comment somewhere within the file.

pre-commit

sdsort can be used as a pre-commit hook. Add the following to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/eirikurt/sdsort
    rev: v1.1.0
    hooks:
      - id: sdsort

Maturity

It's early days. Consider this a beta for now.

Download files

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

Source Distribution

sdsort-1.1.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

sdsort-1.1.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file sdsort-1.1.0.tar.gz.

File metadata

  • Download URL: sdsort-1.1.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sdsort-1.1.0.tar.gz
Algorithm Hash digest
SHA256 1c38f27a3093b2598f6180828d920075c2389d85ea96ff777b2e3a9fafddd819
MD5 3863179432b2f3e9110ea43fb84b9d9d
BLAKE2b-256 11ed54ec41a8e36631bcc7a7310db3ea81e0708a3e0afd2b2ecfaa99b0629fc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sdsort-1.1.0.tar.gz:

Publisher: publish.yml on eirikurt/sdsort

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

File details

Details for the file sdsort-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: sdsort-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sdsort-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d9f452780e22ab550b7da754ac92641dd20f98abcb52cb91b4c8342a7fcfb59
MD5 9f7b1b313632aace942b0bcccaac2a7d
BLAKE2b-256 ca02d2430205984f0f7ba2c90895ffd54c4e5b8829e66029605970abb1324b9f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sdsort-1.1.0-py3-none-any.whl:

Publisher: publish.yml on eirikurt/sdsort

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

Release history Release notifications | RSS feed

1.2.0

2 files

This release

1.1.0 This release

2 files

1.0.0

2 files

0.5.2

2 files

0.5.0

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page