A dependency of a dependency releases a bad version and your install breaks. You don’t use that package directly, so adding it to your requirements feels wrong. A constraints file is made for this.
It looks like a requirements file:
# constraints.txt
urllib3<2
Pass it with -c next to your normal install:
python3 -m pip install -r requirements.txt -c constraints.txt
The rule only applies if something else asks for urllib3. A constraint never causes a package to be installed on its own, which is the whole difference with -r.
I like it as a record of workarounds. Add a comment above each line saying why the cap is there, and you know when it’s safe to delete.
You can also set it for a shell session or a CI job with the PIP_CONSTRAINT environment variable, handy when you can’t change the command itself.
The catch is that constraints can make a resolve impossible. If two packages need ranges that don’t overlap with your cap, pip stops with a conflict error and you have to loosen something. Old caps also keep you away from security fixes, so check the file now and then.
Further reading: pip user guide: constraints files
Going deeper: Guide: let git bisect find the commit that broke your code