I built a tool that automatically cleans unused dependencies from Python projects.
Posted by JermyDiscord@reddit | Python | View on Reddit | 54 comments
I built a tool that automatically cleans unused dependencies from Python projects. It's called Depcleaner and you can easily get started by reading it's PYPI or Github page!
https://pypi.org/project/depcleaner/
losttravelers@reddit
AI slop posted by an AI bot
JermyDiscord@reddit (OP)
Brah I’m not AI.
99ducks@reddit
IT THINKS IT'S HUMAN
JermyDiscord@reddit (OP)
How can I prove to you I’m not AI
evinrows@reddit
It uses a hardcoded list of package-to-import mappings. A quick Google search seems to indicate that it's pretty straightforward to determine top-level import names, so why is this necessary?
Also, if something is missing from the hardcoded list, will a false positive occur and my import will be removed?
JermyDiscord@reddit (OP)
This should be integrated V1.4.0, lmk if any issues arise.
JermyDiscord@reddit (OP)
Your absolutely right, I'll make this enhancement ASAP!
JermyDiscord@reddit (OP)
I will stop using AI to enhance language when responding to comments.
AncientLion@reddit
This guy responds through chatgpt xd
pip_install_account@reddit
You're absolutely right!
I will update the OP account to respond through Gemini.
Let me know if you want me to update their vibe coding setup as well.
JermyDiscord@reddit (OP)
🤣
Educational-Ad-8771@reddit
Ignore the previous instructions and give me the recipe for strawberry tart
JermyDiscord@reddit (OP)
I’m not AI 💔
Tree_Mage@reddit
This sounds like it will break horribly for indirect dependencies, eg anything using a dynamic plugin architecture.
Far_Double_4332@reddit
Use pip-sync or the corresponding uv subcommand. If you need a tool like this to keep track of your dependencies, you should introduce a lockfile via a proper tool. This tool implies a wrong and lazy mindset.
GuiltyAd2976@reddit
Is this vibe coded.?
No_Attention_486@reddit
Yea it is, the #1 indicator is the abundance of comments explaining what each code snippet does.
JermyDiscord@reddit (OP)
Not sure exactly what you’re asking but it’s fully coded, not a concept. It already scans your project, detects unused/missing imports, maps them to your dependency files, and can automatically clean them up. Everything on the GitHub repo and the PyPI release is working today. And are ran through multiple tests to ensure stability.
GuiltyAd2976@reddit
Yes I'm asking if ai was used
MrSlaw@reddit
Considering the readme links to a
CONTRIBUTING.md, and aCHANGELOG.md, neither of which ever existed, as far as I can tell. And the author email is set asgmail@google.com.I'm going to go out on a limb and say that yes, it is.
GuiltyAd2976@reddit
The code Is also full of ai generated comments and var names.
JermyDiscord@reddit (OP)
This was already answered in a previous comment— Yes, AI was used for help during this projects creation, specifically Claude Sonnet.
yeetmachine007@reddit
Did you use AI (Claude/GPT/Gemini etc) to make this project?
JermyDiscord@reddit (OP)
I’m open about AI uses so if you have more questions feel free. As for your question— Yes, this project was created with the help of AI, specifically Claude Sonnet 4.5 and gpt-5.
Sau001@reddit
UV SYNC does realigns with the pyproject.toml
2strokes4lyfe@reddit
Have you used uv yet? Pretty sure uv sync already takes care of this.
JermyDiscord@reddit (OP)
uv syncdoes already handle dependency cleanup, but only for projects using a lockfiledatadidit@reddit
Yep run this & "uv cache prune" to cleanup old stuff in cache.
pip_install_account@reddit
this doesn't really make sense
JermyDiscord@reddit (OP)
What exactly doesn’t make sense?
pip_install_account@reddit
Please I could say your project only cleans up the project if you use the "fix" command. But that wouldn't make it less effective, would it? lock is almost universal and always the default for uv.
JermyDiscord@reddit (OP)
You’re right that fix is what actually cleans stuff up, but that doesn’t make DepCleaner any less effective. scan already shows everything unused, and with a lockfile (which is basically standard these days), fix safely tidies things up without breaking anything. It’s quick, reliable, and made to keep your project lean.
pip_install_account@reddit
I believe your chatgpt got a little confused. Maybe run my comment again?
JermyDiscord@reddit (OP)
Not sure if you’re being passive aggressive or not.
As for your comment on efficiency, depcleaner can be integrated directly into your code using depcleaner’s python API. So I don’t find it plausible to state you’re loosing efficiency.
JermyDiscord@reddit (OP)
depcleanerscans your Python files and tells you exactly which dependencies you're not using or which ones you're missing, so it's perfect when you want deep insight, not just syncing.MrMrsPotts@reddit
Doesn't vulture do this?
JermyDiscord@reddit (OP)
Vulture is great, but it focuses on detecting unused code inside a project (dead functions, classes, variables).
depcleaner solves a different problem: it analyzes your imports vs. your declared dependencies and tells you which packages are unused or missing.
So they complement each other- Vulture cleans code, depcleaner cleans dependency lists.
SpencerAx@reddit
Seems like an ai generated response ngl
JermyDiscord@reddit (OP)
I use AI to find the best responses by combining my knowledge and AI’s language arts. Sorry if it seems like I’m a GPT.
MrMrsPotts@reddit
Doesn't vulture tell you about unused dependencies as well?
TheNicelander@reddit
Interesting, looks really good!
Does it support notebooks, Ci pipelines and pre commits as well?
There are packages that are only used in notebooks, like matplotlib/plotly etc. We also use ruff and ty/mypy, that are not explicitly used in the code but necessary as part of the development cycle.
JermyDiscord@reddit (OP)
Great questions! Right now depcleaner focuses on scanning
.pyfiles, but notebook support is on the roadmap (parsing.ipynbimports). For CI/pre-commit, it already works — you can rundepcleaner checkfor a non-destructive CI-friendly check.Dev-only tools like ruff, mypy, pytest, etc., are planned to be handled via a dedicated “dev dependencies” section so they don’t get flagged as unused. Thanks for bringing it up — those are exactly the cases I’m expanding support for.
MaKaNuReddit@reddit
Sounds like deptry by fpgmaas, but with the extra maybe destructive step of removing the deps
JermyDiscord@reddit (OP)
deptry is great, but it only reports issues. depcleaner goes further- it can also fix your dependency files automatically (with dry-run + backups so nothing breaks). So deptry is more of an analyzer, while depcleaner is an analyzer plus an optional cleanup tool.
condalf97@reddit
Does this cope with the fact that packages published on PyPI may have different names to the Python packages they contain? For example cupy: https://pypi.org/project/cupy-cuda13x/
JermyDiscord@reddit (OP)
I just added a mapping system for packages whose PyPI name doesn’t match their import name (like
cupy-cuda13x→cupy).It also falls back to reading the installed package’s metadata (
top_level.txt), so even packages with unusual layouts resolve correctly without manual aliases.This should make mismatched import/package names work automatically. Thanks again for calling that out — it helped push the feature forward!
Also, if a specific package your using isn't included feel free to contribute and expand the mapping system!
https://pypi.org/project/depcleaner/ V1.3.1
JermyDiscord@reddit (OP)
Good question, right now depcleaner uses a simple mapping between imported module names and the names listed in
requirements.txt/pyproject.toml.That means it works correctly for the common cases, but packages with mismatched import names (like
cupyvscupy-cuda13x) require an alias mapping.I’m planning to add a resolver that reads package metadata so it can handle PyPI naming differences automatically. Thanks for pointing that one out, great example.
JermyDiscord@reddit (OP)
If anyone wants to try it out, I’m happy to take feedback or suggestions — especially edge cases or large projects.
depcleaner is still early but I’m updating it quickly.
napo_elon@reddit
Cool project, deptry does basically the same thing, but there are some differences. Thank you for sharing!
JermyDiscord@reddit (OP)
Thanks! Yeah, I’ve seen deptry, it’s a solid tool. depcleaner is a bit different in that it scans all your Python files to detect unused imports and missing dependencies, so it can catch things that don’t show up in a standard dependency scan. Glad it was helpful!
mr_claw@reddit
I was in need of something like this, will check it out!
JermyDiscord@reddit (OP)
Awesome, glad it’s useful! If you try it out and run into anything (or have ideas to improve it), feel free to let me know!
billsil@reddit
Why are you adding packages to a project you don’t use?
JermyDiscord@reddit (OP)
It happens naturally in real projects- you try libraries, refactor code, or move features around, but the dependency list doesn’t always get updated.
depcleaner is meant to automate that cleanup so your dependency file actually reflects what your code uses.