Skip to main content

pystreamliner

PyPI version PyPI downloads

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 y statements
  • 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), unsafe yaml.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 .

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
-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 only

pystreamliner analyses each file independently using only that file's AST.
It does not follow imports across modules or build a whole-project symbol table.

Consequence: 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.

This is by design. Full inter-module analysis would require either a much heavier dependency stack or a complete project-wide index, both of which go against the tool's zero-dependency, single-pass philosophy.

Work-arounds:

  • Put public API names in __all__ — they are automatically treated as used.
  • Use --ignore unused_function,unused_class (or the config equivalent).
  • Run the tool on the whole project (or the relevant packages) so the definitions and call sites are more likely to be in the same analysis pass when you care about the warnings.

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.

Download files

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

Source Distribution

pystreamliner-1.20.2.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

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

pystreamliner-1.20.2-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file pystreamliner-1.20.2.tar.gz.

File metadata

  • Download URL: pystreamliner-1.20.2.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pystreamliner-1.20.2.tar.gz
Algorithm Hash digest
SHA256 766a0c8e88877cff44a25ba81b6f9eff21d87a529a316fc1a37d7bac75a1cc42
MD5 70dacf3ffddefe22d566bbdf21d9a01a
BLAKE2b-256 813d90796214384996366226f387277379f2676b26338ad511cf57c07da8bcae

See more details on using hashes here.

Provenance

The following attestation bundles were made for pystreamliner-1.20.2.tar.gz:

Publisher: main.yml on Supe232323/pystreamliner

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

File details

Details for the file pystreamliner-1.20.2-py3-none-any.whl.

File metadata

  • Download URL: pystreamliner-1.20.2-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pystreamliner-1.20.2-py3-none-any.whl
Algorithm Hash digest
SHA256 607de74e26675a43458259aa0b5b427f0f8f4ae24ea658bc46ba1010a2f8056a
MD5 cf346e82ac5b9a6ff8a79a2637ac94b4
BLAKE2b-256 00f05361e0a10f505c0b5fd1dc6059bf5cfb5fa670dc1ead0d7c664e5660e832

See more details on using hashes here.

Provenance

The following attestation bundles were made for pystreamliner-1.20.2-py3-none-any.whl:

Publisher: main.yml on Supe232323/pystreamliner

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.21.1

2 files

1.21.0

2 files

1.20.3

2 files

This release

1.20.2 This release

2 files

1.20.0

2 files

1.19.1

2 files

1.19.0

2 files

1.18.0

2 files

1.17.0

2 files

1.16.0

2 files

1.15.0

2 files

1.14.0

2 files

1.13.1

2 files

1.12.1

2 files

1.12.0

2 files

1.11.0

2 files

1.3

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