What is pip's equivalent of npm install package --save-dev?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In npm, --save-dev records a dependency that should exist for development and testing but not necessarily runtime production. Python has the same conceptual split, but pip does not provide one universal flag that updates every project manifest the way npm does. In practice, you model dev dependencies through requirements files or optional dependency groups in pyproject.toml.
Why pip Has No Single Direct Flag
pip is primarily an installer and resolver, not a full project metadata manager. Python projects use multiple packaging workflows, so dependency recording is done in project files.
Common approaches:
requirements.txtandrequirements-dev.txt.pyproject.tomloptional dependency groups.- Tool-specific groups in Poetry, Hatch, or PDM.
So the equivalent of npm dev dependency behavior is achieved through structure, not a single command switch.
Requirements File Pattern
A traditional and widely used setup is splitting runtime and development requirements.
requirements.txt for runtime:
requirements-dev.txt for development tools:
Install dev environment with:
This is straightforward, explicit, and compatible with most CI pipelines.
pyproject.toml Optional Dependencies
Modern packaging often defines optional groups directly in metadata.
Then install local package with dev extras:
This is conceptually close to npm dependency groups and works well in package-centric repositories.
Comparing Mental Models: npm and pip
npm workflow often combines install and manifest update in one command. Python separates concerns more explicitly.
Typical Python flow:
- Edit project dependency files.
- Run pip install from those files.
- Commit updated dependency declarations.
This may feel less automatic, but it is clear and tool-agnostic.
CI and Production Separation
Whatever mechanism you choose, the key goal is keeping production images lean.
Recommended split:
This prevents linters, formatters, and test frameworks from bloating runtime containers.
Locking and Reproducibility
Dev dependency groups can drift quickly without pinning strategy. Use constraints, lock tools, or compiled requirements for deterministic builds.
Practical safeguards:
- Pin important tool versions.
- Validate installs in clean virtual environments.
- Use the same install commands locally and in CI.
Reproducibility matters more than whether you chose file-based or extras-based grouping.
Tool-Specific Commands
If your project uses a higher-level manager, you may get dedicated commands for dev groups. Those are valid, but they are manager-specific workflows layered on top of Python packaging conventions.
When documentation says “pip equivalent,” the most accurate answer is to model dev dependencies in project metadata and install those groups explicitly.
Migration Plan for Existing Projects
If all dependencies are currently mixed in one file:
- Identify runtime-only packages.
- Move test and lint tools to dev group.
- Update CI scripts accordingly.
- Verify app runs with runtime-only set.
This cleanup improves deployment confidence and reduces unnecessary runtime attack surface.
Common Pitfalls
- Expecting pip to auto-record dependencies in a project manifest with one flag.
- Mixing runtime and development tools in one unstructured requirements file.
- Using different install commands in local and CI environments.
- Defining extras but forgetting to document install usage.
- Skipping version pinning and seeing inconsistent behavior across machines.
Summary
- Python has dev dependency concepts, but not one universal pip flag identical to npm
--save-dev. - Common solutions are split requirements files or optional dependency groups.
pip install -r requirements-dev.txtandpip install -e ".[dev]"are practical equivalents.- Keep runtime and development dependency sets intentionally separate.
- Reproducible installs and clear documentation matter more than command symmetry with npm.
Related reading
- What is pkg-resources0.0.0 in output of pip freeze command
- What is printf...
- What is pyproject.toml file for?
- What is Python's equivalent of && (logical-and) in an if-statement?
- What is the best auto-suggest search algorithm for javascript
- What is the best way to add options to a select from a JavaScript object with jQuery?
- What is Python's equivalent of logical-and in an if-statement?
- What is Python's site-packages directory?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.