Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

packaging

Compare and check Python version numbers correctly.

Build tools and bundlersPYPI

GitHub

1. License

“license = "Apache-2.0 OR BSD-2-Clause"”

Use it under either Apache-2.0 or BSD-2-Clause; both allow commercial and closed-source use.

github.com/pypa/packaging/blob/main/pyproject.toml

From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error

What packaging does

packaging is a small free Python library that reads version numbers and version rules the way Python's own install tools do. Your program can tell that 1.10 is newer than 1.9, check whether a version fits a rule like ">=2.31,<3", and read the lines of a requirements file. It works offline and installs nothing else.

What people build with it

Tell users an update is out

Your app or command-line tool compares its own version with the newest one and shows "a new version is available" only when it really is newer.

Check a version fits a range

Before a plugin or script runs, check that the installed library version is one it supports, such as at least 2.31 and below 3.

Read a requirements line

A tool that audits a project reads each line like "requests[socks]>=2.31,<3" and gets the name, the extras and the allowed versions apart.

Only for some systems or Pythons

Decide whether a package is needed on this computer, for example only on Windows or only before Python 3.11.

Match package names reliably

Treat "Django_REST.framework" and "django-rest-framework" as the same package when you look names up or compare lists.

Clean up license names

A report on the packages in a project shows license names in one standard spelling, like "MIT OR Apache-2.0".

packaging popularity

68 / 100
Gid Score, #513 overall
457M
downloads a week, pypi
761
GitHub stars
90
agent projects use it
packaging: downloads per weekPyPI, packaging 452,690,823
packaging: GitHub starspypa/packaging 761

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How packaging is used

  • packaging is a dependency in 90 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (5.5% of the 1,623 Python ones), #11 of 185 in build tools and bundlers.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,457; those are left out of every share on this page.
  • Projects that use it most often also use Pydantic (71.1%), Uvicorn (63.3%), PyYAML (63.3%).

By coding agent

55 projects, 1.7%
42 projects, 1.4%
29 projects, 1.2%
11 projects, 3.3%
7 projects, 1.5%
5 projects, 1.1%

Often used with

In 71.1% of its projects
In 63.3% of its projects
In 63.3% of its projects
In 62.2% of its projects
In 58.9% of its projects
In 58.9% of its projects
In 56.7% of its projects

More about packaging

Agent Skills for it
  • packaging-youtube-thumbnails: Create, render, revise, and learn from evidence-backed title-thumbnail packages. Channel profiles, package scoring, visual QA.

See all

More in Build tools and bundlers

Alternatives

packaging This page

Apache-2.0 OR BSD-2-ClauseGid 68457M/wk

semantic-version

Pick semantic-version when your version strings follow strict SemVer (major.minor.patch) rather than Python's own version rules.

semver (JavaScript)

Pick semver when the versions belong to JavaScript packages and your code runs in Node.js.

setuptools

Pick setuptools when you need to build and publish your own Python package, not just read version numbers.

Compare packaging with another tool

Get started

Tell your AI assistant

“Use the Python library packaging (pin packaging==26.3, Python 3.9+) to compare version numbers with Version() and check ranges with SpecifierSet(..., prereleases=False); catch InvalidVersion for strings that are not versions.”

  1. Install packaging into your project's Python environment.

    pip install packaging

    From packaging.pypa.io/en/stable/

  2. Parse two versions and compare them.

    >>> from packaging.version import Version, parse
    >>> v1 = parse("1.0a5")
    >>> v2 = Version("1.0")
    >>> v1 < v2
    True
    

    From packaging.pypa.io/en/stable/version.html

  3. Check versions against a set of rules with SpecifierSet.

    >>> from packaging.specifiers import SpecifierSet
    >>> spec1 = SpecifierSet("~=1.0")
    

    From packaging.pypa.io/en/stable/specifiers.html

Mistakes to avoid

sorted(versions) or max(versions) on plain strings, or comparing "1.10" > "1.9" as text
sorted(versions, key=Version) and Version(a) > Version(b)

Text order puts 1.10.0 before 1.9.2; in our run sorted() as text gave ['1.10.0', '1.10.0rc1', '1.2', '1.9.2', '2.0.0b1'].

"2.0.0b1" in SpecifierSet(">=1.9") to keep test releases out
SpecifierSet(">=1.9", prereleases=False), or spec.contains(v, prereleases=False)

Since 26.0 test releases are handled per PEP 440 and the plain in check accepts them; in our run it gave True on 26.3 and False on 25.0.

Relying on spec.contains("banana") to raise for a bad version string
Parse with Version() first and catch InvalidVersion

Since 26.0 contains() returns False for a bad version instead of raising; in our run 25.0 raised InvalidVersion and 26.3 returned False.

packaging.version.LegacyVersion or parse("latest") expecting a loose version object
Version(s) inside try/except InvalidVersion

LegacyVersion was removed in 22.0; parse() now only accepts PEP 440 versions.

Comparing package names as typed ("Django_REST.framework" vs "django-rest-framework")
Compare canonicalize_name(a) == canonicalize_name(b)

Package names differ in case, dots and underscores but mean the same package.

Questions

Why not just compare version strings?

As text, "1.10.0" sorts before "1.9.2". Version objects compare by the version rules, so 1.10.0 comes after 1.9.2.

What happens with a version like "latest" or "french toast"?

Version() raises InvalidVersion; catch it in your code.

Can I use it in a paid app?

Yes. It is under Apache-2.0 or BSD-2-Clause, at your choice.

Can it tell which wheel file fits this computer?

Yes, the tags module parses wheel tags and lists the ones the running Python supports.