Skip to main content

pystepdowner

A tool to enforce the Stepdown Rule (from Uncle Bob's Clean Code) in your Python files.

The Stepdown Rule states that code should be readable from top to bottom. Every function should be followed by those at the next level of abstraction so that we can read the program, descending one level of abstraction at a time as we read down the list of functions.

pystepdowner analyzes your Python files and rearranges functions and methods to adhere to this rule, prioritizing source-code call order and correctly handling complex dependency graphs.

Installation

You can install pystepdowner as a global CLI tool using uv (recommended):

# Install from PyPI
uv tool install pystepdowner

# Or install from source locally
uv tool install .

Alternatively, you can install it into any Python environment using standard pip:

pip install pystepdowner

Usage

The CLI provides two main commands: fmt and rw.

1. fmt: Format and Print to Output

Use the fmt command to format a single file and output the result to your terminal. This is useful for previewing changes without modifying the actual file.

pystepdowner fmt -i my_script.py

2. rw: Rewrite Files

Use the rw command to format and rewrite files. You can rewrite a single file or an entire directory recursively.

Rewrite a Single File In-Place

pystepdowner rw -i my_script.py

Rewrite a Single File and Save to a New Location

pystepdowner rw -i my_script.py -o formatted_script.py

Rewrite an Entire Directory In-Place

This will recursively find and format all .py files inside the target directory.

pystepdowner rw -i src/

Example

pystepdowner transforms bottom-up code into top-down code, putting high-level logic before the helpers it calls.

Before:

def load_user(user_id: int) -> dict:
    return {"id": user_id, "name": "Alice"}


def format_user(user: dict) -> str:
    return f"{user['id']}: {user['name']}"


def user_controller(user_id: int) -> dict:
    user = load_user(user_id)
    return {"body": format_user(user)}

After running pystepdowner rw -i my_script.py:

def user_controller(user_id: int) -> dict:
    user = load_user(user_id)
    return {"body": format_user(user)}


def load_user(user_id: int) -> dict:
    return {"id": user_id, "name": "Alice"}


def format_user(user: dict) -> str:
    return f"{user['id']}: {user['name']}"

Metadata

Release files for pystepdowner 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pystepdowner 1.0.0
File Size Uploaded Provenance Actions
pystepdowner-1.0.0.tar.gz 56.1 kB Without provenance Details for pystepdowner-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pystepdowner 1.0.0
File Interpreter ABI Platform Actions
pystepdowner-1.0.0-py3-none-any.whl Python 3 none any Details for pystepdowner-1.0.0-py3-none-any.whl

Total release size: 63.3 kB

Release files / pystepdowner-1.0.0.tar.gz

Download URL pystepdowner-1.0.0.tar.gz
Size 56.1 kB
Tags Source
SHA-256 checksum
How to use checksums
63ec1839f53c21b2663edf7fcb8e4d43f5b4fb808f195b8bf83b8c951975f356
BLAKE2b-256 checksum
How to use checksums
8fc7ec0146bd079a5e8eae36edbee173631271dc03377bacd8c2ce8ac7f5b2ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pystepdowner-1.0.0-py3-none-any.whl

Download URL pystepdowner-1.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dc33f1343815f1655bb0f8f03992839ab82863f313b229cda1fb6e908aba2e1
BLAKE2b-256 checksum
How to use checksums
2f6aa8acc51a33c62bbac18c8460d7ba2b47a3a624ead597323c160ff2a37bc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pystepdowner 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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