Software Engineering
Study: Building Python Libraries Without Dependencies Can Preserve Performance While Cutting Risk
Researchers tested 44 stdlib-only Python modules against their third-party equivalents, finding that eliminating dependencies often delivers comparable speed with major benefits in footprint, security, and deployment.
Reducing external dependencies in Python projects offers significant advantages in footprint, supply-chain security, and ease of deployment—but at what performance cost? A new empirical study published on arXiv examines whether building single-file libraries using only Python's standard library can hold their own against popular third-party alternatives.
The Research Setup#
Researchers created zerodep, a collection of 44 single-file, dependency-free Python modules spanning 12 functional categories, and benchmarked each against its reference implementation. The goal was to quantify both performance and correctness when standard-library alternatives replace external packages.
Performance Patterns#
Three distinct tiers of performance emerged:
- Comparable speed: Stdlib-only versions matched or beat third-party libraries (performing within 2x) in the majority of cases.
- Significant wins: Many implementations outpaced their references by 5x to 115x, particularly where the external library carried architectural overhead.
- Hard limits: A clear performance cliff emerged for C-extension-backed computation—image processing, binary serialization, and low-level cryptography tasks. PyPy JIT and profiling confirmed this gap.
Benefits Beyond Speed#
Beyond raw performance, the stdlib-only approach delivered measurable gains:
- Footprint reduction: Median installed size dropped from 700 KB to 31 KB—orders of magnitude smaller.
- Faster imports: Load time improved by 2.2x.
- Dependency elimination: The 44 modules collectively removed 88 transitive dependencies maintained across 128 distinct PyPI accounts, shrinking the attack surface.
LLM-Assisted Development Insights#
The study tracked how large language models contributed to the development process. A key finding: specification completeness, not model raw capability, best predicted generation success. Contract-linked code review—tying reviews to formal specifications—reduced review overhead by 5x while preventing compatibility regressions.