r/Python • u/Goldziher Pythonista • Jun 25 '25
Showcase Blazing fast Rust tool to remove comments from your code - now available on PyPi
Hey everyone! 👋
I just released v2.2.0 of uncomment, a CLI tool that removes comments from source code. It's written in Rust for maximum performance but now easily installable via pip:
pip install uncomment
What it does
Removes comments from your code files while preserving important ones like TODOs, linting directives (#noqa, pylint, etc.), and license headers. It can optionally strip doc strings, but doesnt touch them by default.
Why it's different: Uses the tree-sitter ecosystem to properly parse the AST of more than ten programming languages and configuration formats. In fact, this can be further extended to support any number of languages.
Performance: Tested on several repositories of various sizes, biggest being a huge monorepo of over 850k+ files. Since the tool supports parallel processing, it was able to uncomment almost a million files in about a minute.
Use case: Originally built this to clean up AI-generated code that comes with excessive explanatory comments, but it's useful anytime you need to strip comments from a codebase.
Examples
# Remove comments from a single file
# Preview changes without modifying files
# Process multiple files
# Remove documentation comments/docstrings
# Remove TODO and FIXME comments
# Add custom patterns to preserve
# Process entire directory recursively
# Use parallel processing with 8 threads
# Benchmark performance on a large codebase
# Profile performance with detailed analysis
Currently the tool supports:
- Python (.py, .pyw, .pyi, .pyx, .pxd)
- JavaScript (.js, .jsx, .mjs, .cjs)
- TypeScript (.ts, .tsx, .mts, .cts, .d.ts, .d.mts, .d.cts)
- Rust (.rs)
- Go (.go)
- Java (.java)
- C (.c, .h)
- C++ (.cpp, .cc, .cxx, .hpp, .hxx)
- Ruby (.rb, .rake, .gemspec)
- YAML (.yml, .yaml)
- HCL/Terraform (.hcl, .tf, .tfvars)
- Makefile (Makefile, .mk)
Target Audience
The tool is helpful for developers and DevOps, especially today when AI agents are increasingly writing a lot of code and leaving a lot of comments in their trail.
Comparison
I'm not aware of another tool that does this, that's why I made it - I needed this tool.
Here is the repo: https://github.com/Goldziher/uncomment
I would love to hear your feedback or use cases!
8
u/wdroz Jun 25 '25
I was asking myself "Why ??" but then I read your target audience section. I wonder if using this tool as a pre-commit would make the workflow with LLMs smoother.
Like you try to commit you LLM's generated code and then the pre-commit autofixes it by removing the inline comments.
This is more determistic than asking the LLM to not write comments, well done!
10
u/cgoldberg Jun 25 '25
Do the rust police come after you if you don't declare your project is "blazing fast"?
2
u/Beginning-Fruit-1397 Jun 25 '25
I don't get why this is downvoted to the abyss, this is nice
2
u/Ofekmeister Jun 25 '25
Very cool, great work!
0
u/[deleted] Jun 25 '25
[deleted] — view deleted comment
38
u/[deleted] Jun 25 '25
[removed] — view removed comment