Exact Pins or Version Ranges? The Library Dependency Debate

Applications and libraries are different animals, and much of the arguing about dependency versions comes from forgetting that. An application controls its whole install; a library is one guest in somebody else's tree. This page lays out the two main positions on how a library should declare its own dependencies, then where they actually disagree.

The case for ranges

The mainstream advice in both the npm and Python packaging communities is that a library should declare the widest range it genuinely supports. In package.json that usually means a caret range; in pyproject.toml a lower bound and sometimes an upper one:

// package.json
"dependencies": { "yaml-core": "^2.3.0" }

# pyproject.toml
dependencies = ["yaml-core>=2.3"]

The reasoning is about the consumer. If your library pins yaml-core at exactly 2.3.0 and another library in the same app pins 2.3.4, npm may install two copies, which bloats bundles and can break instanceof checks. In Python the situation is stricter: pip installs one version per environment, so two incompatible pins simply fail to resolve. Ranges let the consumer's resolver find a single version that satisfies everyone, and let security patches flow in without waiting for you to release.

The case for exact pins

The other camp has been burned. A dependency ships a patch release that is accidentally breaking, or a compromised maintainer account publishes a malicious version, and every library with an open range pulls it in on the next fresh install. Pinning exactly means your users get the combination you tested and nothing else. Some maintainers of command-line tools, which behave more like applications than libraries, pin for exactly this reason.

Pin advocates also point out that a range is a promise you cannot verify. Declaring ^2.3.0 claims compatibility with versions that do not exist yet.

Where the disagreement really lies

QuestionRanges viewPins view
Who should control the final versions?The application, through its lockfileThe library author, who tested them
How should security fixes arrive?Automatically, within the rangeThrough a deliberate new release
Main risk acceptedAn upstream release breaking usersDuplicate copies or unresolvable trees
Typical fitLibraries imported by other codeStandalone CLIs and apps

Most of the conflict dissolves once you notice that lockfiles exist for the pinning job. An application's package-lock.json, poetry.lock or uv.lock records exact versions for that one install, while the library's manifest says what is allowed. Note that npm does not use a dependency's own lockfile when it is installed as a dependency, so a library's lockfile only pins your development and CI environment.

A middle path many maintainers take

Neither side is foolish. The useful question for your package is whether it is a component or a finished tool. For background on how caret and tilde ranges are interpreted, see our semantic versioning guide.