-
Notifications
You must be signed in to change notification settings - Fork 0
Examples Pep440Versions
Complete reference for version specifier syntax used in PEP 723 dependencies.
| Pattern | Example | Matches | Doesn't Match |
|---|---|---|---|
== |
pandas==1.5.3 |
1.5.3 only | 1.5.2, 1.5.4, 2.0 |
!= |
numpy!=2.0.0 |
Any except 2.0.0 | 2.0.0 |
> |
matplotlib>3.0 |
3.0.1, 3.5, etc. | 3.0.0, 2.9 |
< |
scipy<2.0 |
1.9, 1.0, etc. | 2.0.0, 2.1 |
>= |
sklearn>=1.0 |
1.0, 1.5, 2.0, etc. | 0.9, 0.8 |
<= |
torch<=1.13 |
1.13, 1.12, 1.0, etc. | 1.13.1, 2.0 |
~= |
pydantic~=2.0 |
2.0, 2.1, 2.99 | 2.100+, 3.0 |
# /// script
# dependencies = [
# "pandas==1.5.3",
# ]
# ///Only this exact version is installed.
Use when: You've tested and know the exact version needed.
# /// script
# dependencies = [
# "numpy!=2.0.0", # Any version except 2.0.0
# ]
# ///Installs any version except the specified one.
Use when: One specific version is broken but others work.
# /// script
# dependencies = [
# "matplotlib>3.1", # Any version after 3.1
# ]
# ///Matches: 3.1.1, 3.2, 3.5, 4.0, etc.
Doesn't match: 3.0, 3.1.0
# /// script
# dependencies = [
# "scipy<2.0", # Any version before 2.0
# ]
# ///Matches: 1.0, 1.5, 1.9.9
Doesn't match: 2.0.0, 2.1
# /// script
# dependencies = [
# "sklearn>=1.0", # 1.0 or newer
# ]
# ///Matches: 1.0, 1.1, 2.0, 10.0
Doesn't match: 0.9.9
Common use: "Requires at least this version"
# /// script
# dependencies = [
# "torch<=1.13", # 1.13 or older
# ]
# ///Matches: 1.13, 1.12, 1.0, 0.5
Doesn't match: 1.13.1, 2.0
# /// script
# dependencies = [
# "pandas>=1.5,<2.0", # Between 1.5 and 2.0 (exclusive)
# ]
# ///Matches: 1.5.0, 1.5.3, 1.9.9
Doesn't match: 1.4.9, 2.0.0
Pattern: >=MIN,<MAX is very common for compatibility ranges.
# /// script
# dependencies = [
# "scipy!=1.0.0,!=1.5.0", # Any version except these
# ]
# ///Matches: 1.4.0, 1.6.0, 2.0
Doesn't match: 1.0.0, 1.5.0
The "compatible release" specifier is useful for minor version updates.
# /// script
# dependencies = [
# "pydantic~=2.0", # 2.x but not 3.x
# ]
# ///Meaning: X.y where y can be any number, but X cannot change.
Matches: 2.0, 2.1, 2.99
Doesn't match: 1.9, 3.0
# /// script
# dependencies = [
# "numpy~=1.24.0", # 1.24.x but not 1.25.x
# ]
# ///Meaning: X.Y.z where z can be any number, but X.Y cannot change.
Matches: 1.24.0, 1.24.1, 1.24.999
Doesn't match: 1.23.9, 1.25.0
# ✅ GOOD: Allow bug fixes
# dependencies = ["pandas~=1.5.0"] # Get fixes in 1.5.1, 1.5.2, etc.
# ❌ RISKY: Too permissive
# dependencies = ["pandas~=1.0"] # Allows 1.0 to 1.999 (too broad!)# /// script
# dependencies = [
# "scipy>=1.0.0a1", # Alpha version
# "numpy>=1.24.0rc1", # Release candidate
# ]
# ///Python versions follow PEP 440:
-
a= alpha -
b= beta -
rc= release candidate
# /// script
# dependencies = [
# "package>=1.0.0.post1", # Post-release version
# ]
# ///# /// script
# dependencies = [
# "requests==2.31.0", # Exact version
# "beautifulsoup4>=4.11,<5.0", # Compatible range
# ]
# ///# /// script
# dependencies = [
# "pandas~=1.5.0", # Allow 1.5.x patches
# "numpy>=1.24,<2.0", # Not numpy 2
# "scikit-learn==1.3.0", # Exact version
# "matplotlib>=3.7,<4.0", # Next major pending
# ]
# ///# /// script
# dependencies = [
# "torch>=2.0,<3.0", # Major version 2
# "torchvision>=0.15,<0.16", # Minor version lock
# "transformers~=4.30.0", # Allow 4.30.x patches
# ]
# ///# /// script
# dependencies = [
# "requests", # Latest (risky!)
# ]
# ///
# Better:
# dependencies = [
# "requests>=2.28", # Minimum version
# ]
# ///Python versions follow semantic versioning: MAJOR.MINOR.PATCH
1.5.3 # Major.Minor.Patch
↑ ↑ ↑
| | └─ Patch version (bug fixes: 3 → 4)
| └─── Minor version (features: 5 → 6)
└───── Major version (breaking changes: 1 → 2)
1.5.3.post2dev1
└─ Dev version (developer preview)
└─ Post-release (patch after release)
Do you have tested version?
├─ YES → Use exact: "package==1.5.3"
└─ NO → Continue...
Does package have breaking changes often?
├─ YES (unstable) → Use major.minor: "package~=1.5"
└─ NO (stable) → Continue...
Industry standard version available?
├─ YES → "package>=1.5,<2.0" (safe range)
└─ NO → "package>=1.5" (minimum only)
# WRONG
# dependencies = ["pandas=1.5.3"]
# CORRECT
# dependencies = ["pandas==1.5.3"]# WRONG
# dependencies = ["pandas == 1.5.3"] # Spaces!
# dependencies = ["pandas >=1.5 , <2.0"] # Bad comma
# CORRECT
# dependencies = ["pandas==1.5.3"]
# dependencies = ["pandas>=1.5,<2.0"]# WRONG (blocks updates)
# dependencies = ["pandas==1.5.3", "numpy==1.24.0", "scipy==1.9.0"]
# BETTER (allow compatible updates)
# dependencies = ["pandas~=1.5.0", "numpy~=1.24.0", "scipy~=1.9.0"]# WRONG (May install incompatible version)
# dependencies = ["pandas>=1.0"]
# BETTER (Known boundary)
# dependencies = ["pandas>=1.5,<2.0"]Your PEP 723:
dependencies = ["pandas~=1.5.0", "numpy>=1.24,<2.0"]
↓
UV reads specifiers
↓
Queries PyPI for matching versions
↓
Resolves conflicts (uses SAT solver)
↓
Selects: pandas 1.5.3, numpy 1.24.0
↓
Installs
# Visit: https://pypi.org/project/pandas
# See all available versions# Try installing
uv pip install "pandas==1.5.3" # Exact
uv pip install "pandas~=1.5.0" # Rangeimport pandas
print(pandas.__version__) # e.g., "1.5.3"When unsure, use:
"package>=X.Y.0,<X+1.0" # Allow bug fixes, not major changeFor reproducibility:
"package==X.Y.Z" # Exact versionFor less critical dependencies:
"package>=X.Y" # At least this version- PEP 440 - Official spec
- PyPI - See available versions
- Semver.org - Semantic versioning