Skip to content

Commit 75c95a2

Browse files
committed
enh: specifiers
1 parent a929ba8 commit 75c95a2

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

package-structure-code/declare-dependencies.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,35 @@ Specifying dependencies in your `pyproject.toml` file ensures that your package
3737
Users automatically get the packages your code needs to run. For instance, if your package requires Pandas to run properly, Pandas will be installed into the users' environment when they install your package using uv, pip or conda, if you specify it as a dependency in your pyproject.toml file.
3838

3939
:::{tip}
40-
You can control which versions of dependencies are compatible with your package using specifiers. You will learn more about dependency specifiers below.
40+
You can control which versions of dependencies are compatible with your package using specifiers. You will learn more about dependency specifiers in the sections below.
41+
:::
42+
43+
## Version specifiers
44+
45+
Version specifiers control which versions of a dependency work with your
46+
package. Use them to specify minimum versions, exclude buggy releases, or
47+
set version ranges.
48+
49+
### Common operators
50+
51+
- **`>=`** - Minimum version set: `numpy>=1.20` (This is the most common approach and is recommended)
52+
- **`==`** - Exact version: `requests==2.28.0` (Avoid pinning dependencies like this unless absolutely necessary)
53+
- **`~=`** - Compatible release: `django~=4.2.0` (Allows patches: >=4.2.0,<4.3.0)
54+
- **`<` or `>`** - Upper/lower bounds: `pandas>=1.0,<3.0`
55+
- **`!=`** - Exclude version: `scipy>=1.7,!=1.8.0` (Rare but allows you to skip a buggy release version)
56+
57+
:::{tip}
58+
**Best practice:** Use `>=` to specify your minimum tested version and
59+
avoid upper bounds unless you know a future version will break. UV will do this by
60+
default when it adds a dependency to your pyproject.toml file. This keeps
61+
your package flexible and reduces dependency conflicts.
62+
```toml
63+
dependencies = [
64+
"numpy>=1.20", # Good - flexible
65+
"pandas>=1.0,<3.0", # OK - known breaking change in 3.0
66+
"requests==2.28.0", # Avoid - too restrictive
67+
]
68+
```
4169
:::
4270

4371

0 commit comments

Comments
 (0)