pystreamliner
Automatically clean up messy Python files — without breaking anything.
pystreamliner uses Python's AST (abstract syntax tree) to safely detect and fix common code issues. It operates on two tiers: things it can fix automatically with zero risk, and things it flags for you to review manually.
Supports single files, multiple files, and recursive directory cleaning with a tight summary mode for large runs. Emits JSON and SARIF 2.1.0 for CI. Optional mtime cache for repeated local runs.
Discord: https://discord.gg/Z6cXxhSKS
What it does
Auto-fixes (Tier 1 — applied immediately):
- Removes unused imports, or trims partially unused
from x import ystatements - Removes consecutive duplicate lines
- Caps excessive blank lines
Warnings (Tier 2 — reported, never auto-changed):
- Unused variables
- Unused top-level functions
- Unused classes
- Vague variable names (
x,tmp,foo,bar, etc.) - Shadowed built-ins
- Dangerous calls (
eval,exec,pickle,os.system,subprocess(..., shell=True), unsafeyaml.load) - Possible hardcoded secrets
- Assert statements
- Broad
except:/except Exception
pystreamliner never touches code it isn't certain about. If there's any doubt, it warns you instead.
Install
pip install pystreamliner
No dependencies. Runs on Python 3.13+.
Usage
Single file:
pystreamliner your_file.py
Multiple files:
pystreamliner file1.py file2.py utils/*.py
Entire project (recursive):
pystreamliner .
# or
pystreamliner src/ tests/
Directories are walked recursively. Common junk directories (.git, __pycache__, venv, node_modules, etc.) are automatically skipped when they appear as sub-directories.
Preview without modifying:
pystreamliner --dry-run .
CI mode (exit non-zero on issues):
pystreamliner --check --quiet .
SARIF for Code Scanning / security dashboards:
pystreamliner --sarif --dry-run . > results.sarif
JSON for scripts:
pystreamliner --json --dry-run .
Faster repeated local runs (mtime cache):
pystreamliner --cache .
# optional custom cache path
pystreamliner --cache --cache-file /tmp/ps-cache.json .
Parallelism:
# default is sequential (-j 1) — safest for small trees
pystreamliner .
# auto (capped workers)
pystreamliner -j 0 .
# explicit workers; prefer threads on many small files
pystreamliner -j 4 --threads .
Cross-file unused functions / classes (opt-in):
pystreamliner --project --dry-run src/
Name-based: if another file in the same run imports or references the name, the unused_function / unused_class warning is dropped. Default remains per-file. Zero extra dependencies.
Big runs / Summary mode
When you process 5 or more files (configurable with --summary-threshold), pystreamliner switches to a compact summary instead of dumping a full report for every file.
CLI reference (high-signal flags)
| Flag | Purpose |
|---|---|
-d, --dry-run |
Analyze / report only; do not write |
-c, --check |
Exit 1 if changes or warnings (CI) |
-q, --quiet |
Suppress human report |
--json |
Machine-readable JSON (includes import_details) |
--sarif |
SARIF 2.1.0 report on stdout |
--cache |
Skip unchanged files (mtime + size) |
--cache-file PATH |
Cache location (default .pystreamliner_cache.json) |
-j, --jobs N |
Workers; default 1; 0 = auto (capped) |
--threads |
Use threads instead of processes when jobs > 1 |
--project |
Suppress unused function/class warnings if the name is referenced in another file in this run |
-w, --warn-only |
Report only; never rewrite |
--fix-only |
Tier-1 fixes only; suppress Tier-2 warnings |
--select / --ignore |
Filter warning categories |
--exclude-path |
Glob path excludes (repeatable) |
--aggressive |
Stricter blank-line collapsing |
Config file support (zero deps): .pystreamliner.toml or [tool.pystreamliner] in pyproject.toml. CLI always wins.
Limitations / By design
These behaviours are intentional. They keep the tool zero-dependency, fast, and conservative.
Unused function / class detection is per-file by default
By default pystreamliner analyses each file independently using only that file's AST.
It does not follow imports across modules unless you pass --project.
Consequence without --project: a function or class that is defined in one file and imported + used in another file will be reported as unused when you run the tool on the definition file alone.
--project (also project = true in config) builds a cheap name index over every file in the current run and suppresses unused_function / unused_class when the name is referenced elsewhere (imports, attribute access, identifier strings, __all__). Still zero third-party deps. It is not a full import resolver: it does not understand types, import *, or dynamic getattr beyond literal strings.
This stays opt-in so the default remains conservative and single-pass cheap.
Work-arounds without --project:
- Put public API names in
__all__— they are automatically treated as used. - Use
--ignore unused_function,unused_class(or the config equivalent). - Run with
--projecton the whole package so definitions and call sites share one index.
Directory name collisions with the ignore list
The built-in ignore list contains common junk directories (__pycache__, .git, venv, coverage, htmlcov, etc.).
These are only skipped when they appear as sub-directories of a path you gave the tool.
If you explicitly pass a directory that happens to be named one of those (e.g. pystreamliner coverage/), its contents are processed. (This was fixed in 1.19.1.)
Nested junk directories inside that tree are still skipped as expected.
Summary mode vs detailed reports
When ≥ 5 files are processed (configurable), output switches to a compact summary that shows counts only.
Detailed per-file reports (with every warning message) appear only for smaller runs. This is intentional so large projects stay readable.
Parallelism defaults
Default is sequential (-j 1). Process pools have non-trivial spawn cost; for many small files prefer --threads or leave the default alone. Use -j 0 only when you know you want capped multi-core.
Contributing
See CONTRIBUTING.md.
Metadata
Release files for pystreamliner 1.21.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pystreamliner-1.21.1.tar.gz | 28.9 kB | With provenance | Details for pystreamliner-1.21.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pystreamliner-1.21.1-py3-none-any.whl | Python 3 | none | any | Details for pystreamliner-1.21.1-py3-none-any.whl |
Total release size: 59.0 kB
Release files / pystreamliner-1.21.1.tar.gz
| Download URL | pystreamliner-1.21.1.tar.gz |
|---|---|
| Size | 28.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ae7a22b533bef65180f63ba356dbf3cd2f4f3a29ea2295a3e71edd38bd92e58
|
|
BLAKE2b-256 checksum How to use checksums |
80d6276b15b77f27b0b3ee127f355046bc672dad348312dfcab0feaaa8f553ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.
Transparency logRelease files / pystreamliner-1.21.1-py3-none-any.whl
| Download URL | pystreamliner-1.21.1-py3-none-any.whl |
|---|---|
| Size | 30.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
616120818adc693c3b6d8f7b205b9db480ddfa0ed14bac940532bb6627780095
|
|
BLAKE2b-256 checksum How to use checksums |
b319d0851dca5af749ec936fd23316a5bf78fd460254777d09ea9e5516416837
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.
Transparency logSecurity for pystreamliner 1.21.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pystreamliner-1.21.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 10, 2026.
Transparency logA 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.