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.
Parallelism
Larger runs are sorted across parallel worker processes. Use --jobs/-j to control how many:
sdsort --jobs 4 <directory_path>
0 (the default) picks one worker per available CPU; 1 disables parallelism and sorts every file in the current process. Runs of fewer than 50 files always stay serial regardless of this setting, since spawning workers costs more than it saves at that scale.
Files that cannot be parsed
If sdsort cannot parse a file, it reports the file on stderr and moves on. The rest of the files are still sorted, and the exit code is unaffected.
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.2.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sdsort-1.2.0.tar.gz.
File metadata
- Download URL: sdsort-1.2.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df51ebdc89e9683078d8828bb80eefda9418856877abf375f69950139c5f5b82
|
|
| MD5 |
9514a3c4b61aa23041e3aed5870cda17
|
|
| BLAKE2b-256 |
f52d5f5fa69a0e6a7a962a22af403bcfe517dee013966112a75c6eb364879538
|
Provenance
The following attestation bundles were made for sdsort-1.2.0.tar.gz:
Publisher:
publish.yml on eirikurt/sdsort
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sdsort-1.2.0.tar.gz -
Subject digest:
df51ebdc89e9683078d8828bb80eefda9418856877abf375f69950139c5f5b82 - Sigstore transparency entry: 2385988424
- Sigstore integration time:
-
Permalink:
eirikurt/sdsort@67208567d516b1b151ee4b9224498852dc42f9b7 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/eirikurt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67208567d516b1b151ee4b9224498852dc42f9b7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sdsort-1.2.0-py3-none-any.whl.
File metadata
- Download URL: sdsort-1.2.0-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4604f09fdc2b5e789c4299716f64dd913d7d299ff0c400d539c7cd97e5f9c85e
|
|
| MD5 |
65401dd8e5f3e6740f9647a8c3efdeab
|
|
| BLAKE2b-256 |
f8517a4ac7387d5e5b5b46160c9a4b37e88e7d8c674a0c47b40c2b62835e9b66
|
Provenance
The following attestation bundles were made for sdsort-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on eirikurt/sdsort
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sdsort-1.2.0-py3-none-any.whl -
Subject digest:
4604f09fdc2b5e789c4299716f64dd913d7d299ff0c400d539c7cd97e5f9c85e - Sigstore transparency entry: 2385988429
- Sigstore integration time:
-
Permalink:
eirikurt/sdsort@67208567d516b1b151ee4b9224498852dc42f9b7 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/eirikurt
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@67208567d516b1b151ee4b9224498852dc42f9b7 -
Trigger Event:
release
-
Statement type: