Mohammad RazieiThe "It's Just a Small Library" Trap We've all been there. You find a Python package that...
We've all been there. You find a Python package that promises to solve your problem with minimal overhead. The README says "lightweight," the GitHub stars look good, and the developer swears it's "just a few kilobytes."
So you install it, run your project, and wonder why your Docker image grew by 200MB.
What happened?
The package is small. But its dependencies aren't. And those dependencies have dependencies. And those... you get the idea.
I was comparing HTTP libraries for a new project. requests is popular, but everyone says it's "heavy." Then I found a library that claimed to be a "lightweight alternative."
But something in my gut said "let me check." So I built pip-size — a tool that calculates the real download size of PyPI packages and their dependencies, using only the PyPI JSON API. No downloads. No pip subprocess. Just data.
pip install pip-size
pip-size requests
pip-size httpx
pip-size aiohttp
The results might surprise you:
| Package | Package Size | Total (with deps) |
|---|---|---|
| requests | 63.4 KB | 620.4 KB |
| httpx | 71.8 KB | 560.0 KB |
| aiohttp | 1.7 MB | 2.6 MB |
httpx is often marketed as a "modern" alternative to requests, but the total size is almost identical! Meanwhile, aiohttp is over 4x larger — which makes sense since it's a full async framework, not just a client.
Here's where it gets interesting. Flask is often called "lightweight" while FastAPI is labeled as "heavy." Let's verify:
pip-size flask
pip-size fastapi
Results:
| Framework | Package Size | Total (with deps) |
|---|---|---|
| Flask | 101.0 KB | 606.2 KB |
| FastAPI | 115.0 KB | 2.9 MB |
Flask is indeed smaller — about 5x smaller than FastAPI when you count everything.
But here's the nuance: FastAPI's size comes from pydantic (2.4 MB), which brings powerful data validation and automatic API documentation. You're not just getting a web framework — you're getting a complete API solution.
So "lightweight" depends on what you need. If you want simplicity and control, Flask wins. If you want automatic docs, validation, and type hints, FastAPI's "weight" is a feature, not a bug.
pip-size httpx
pip-size requests
pip-size aiohttp
Now you can compare apples to apples — not just the package size, but the entire dependency tree.
pip-size mypackage
See what you're actually shipping to your users. Sometimes you'll be surprised.
When your project grows unexpectedly, run pip-size on your dependencies. You'll find which one is dragging in the bulk of the weight.
pip-size "requests[security]"
pip-size "fastapi[standard]"
See exactly how much each extra adds over the base package.
In a world where:
Knowing the real cost of a dependency before you install it isn't a luxury — it's a necessity.
pip-size is open source (MIT license) and available on PyPI. It uses the PyPI JSON API, caches responses for 24 hours, and supports proxies if you need them.
Next time you see a package advertised as "lightweight," run pip-size first. Your future self (and your users) will thank you.
Have you ever been surprised by a package's hidden dependencies? Let me know in the comments!
Links: