# packaging — card for AI agents

Core utilities for parsing and working with Python package versions and specifiers.

Category: Build tools and bundlers · PyPI package `packaging` · latest version 26.3 (checked 2026-11-01)
Install: `pip install packaging`
License: Apache-2.0 OR BSD-2-Clause (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Agent Skills for it
- packaging-youtube-thumbnails from ericosiu/ai-marketing-skills: `npx skills add ericosiu/ai-marketing-skills --skill packaging-youtube-thumbnails`

## Numbers (AgentGid data)
- Gid Score: 67.5 (#513 of all tools, 27 of 185 in its category)
- Used in 90 public projects set up for AI coding agents (1.4%)
- Downloads last week: 456,854,454 (as of 2026-11-24), +11.3% over 4 weeks
- GitHub stars: 761 (as of 2026-11-24)
- Last push: 2026-11-23

## Often used with
Pydantic 71.1%, Uvicorn 63.3%, PyYAML 63.3%, Requests 62.2%, Click 58.9%, NumPy 58.9%

## Links
- AgentGid page: https://agentgid.com/tools/packaging/
- Repository: https://github.com/pypa/packaging


## packaging: compare and check Python version numbers correctly

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.

### Where to use 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".

### How to start
- Install packaging into your project's Python environment.

```
pip install packaging
```

- Parse two versions and compare them.

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

- Check versions against a set of rules with SpecifierSet.

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


### License
Free to use, also in paid and closed-source products. You may pick either the Apache-2.0 or the BSD-2-Clause license; if you ship it, keep its copyright notice and license text.

### Good to know
- It reads and compares version numbers and version rules; it does not install, download or update anything.
- Its own version numbers follow the calendar (26.3 is a 2026 release), so a jump in the first number is not a sign of a big rewrite.
- Version 26.3 came out on 2026-08-03 and needs Python 3.9 or newer.
- Strings that are not proper Python versions, like "latest", are refused with an error since version 22.0. Older code that relied on the loose fallback breaks.

Checked 2026-11-10 against: https://packaging.pypa.io/en/stable/, https://packaging.pypa.io/en/stable/version.html, https://packaging.pypa.io/en/stable/specifiers.html, https://packaging.pypa.io/en/stable/markers.html, https://packaging.pypa.io/en/stable/requirements.html, https://packaging.pypa.io/en/stable/tags.html, https://packaging.pypa.io/en/stable/utils.html, https://packaging.pypa.io/en/stable/licenses.html, https://packaging.pypa.io/en/stable/changelog.html, https://github.com/pypa/packaging/blob/main/README.rst, https://github.com/pypa/packaging/blob/main/LICENSE, https://github.com/pypa/packaging/blob/main/LICENSE.BSD, https://github.com/pypa/packaging/blob/main/LICENSE.APACHE, https://github.com/pypa/packaging/blob/main/pyproject.toml, https://pypi.org/pypi/packaging/json

### Mistakes to avoid
- Don't: sorted(versions) or max(versions) on plain strings, or comparing "1.10" > "1.9" as text → Do: 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'].)
- Don't: "2.0.0b1" in SpecifierSet(">=1.9") to keep test releases out → Do: 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.)
- Don't: Relying on spec.contains("banana") to raise for a bad version string → Do: 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.)
- Don't: packaging.version.LegacyVersion or parse("latest") expecting a loose version object → Do: Version(s) inside try/except InvalidVersion (LegacyVersion was removed in 22.0; parse() now only accepts PEP 440 versions.)
- Don't: Comparing package names as typed ("Django_REST.framework" vs "django-rest-framework") → Do: 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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
