Skip to content

third-party libraries

Third-party libraries can be quite useful, especially when they provide tools that the standard library doesn’t include or when they offer a more ergonomic API for a task you do often. At the same time, every dependency adds maintenance overhead and increases the chance of version conflicts.

For third-party packages, these best practices help you keep your dependency footprint healthy:

  • Add third-party dependencies deliberately and sparingly: Treat each external dependency as a design decision, not a shortcut.
  • Isolate dependencies per project: Install third-party packages in a virtual environment so different projects don’t fight over versions.
  • Carefully evaluate packages before installing them: Check the project’s PyPI page, documentation, and repository. Look at supported Python versions, release history, and whether the project is actively maintained.
  • Document and pin your dependencies: Record your dependencies in a dependency file and lock their versions as part of your project’s dependency management workflow.

To see why pinning dependencies matters, say that your project needs a couple of third-party packages:

🔴 Avoid this:

Language: Shell
$ python -m pip install requests rich

This approach works, but it doesn’t document which versions you installed. That makes it harder to reproduce your environment later and easier to accidentally pick up breaking changes.

Favor this:

Language: Text Filename: requirements.txt
requests~=2.32
rich~=15.0
Language: Shell
$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -m pip install -r requirements.txt

Here, you document your third-party dependencies and constrain them to compatible versions. The ~= operator allows compatible releases, so it bounds a version range instead of fixing one version. Pinning goes further: it records exact == versions for every package, including the transitive ones you didn’t install directly, usually in a lock file that you generate with python -m pip freeze > requirements.txt or an equivalent tool. Either way, you make installs more repeatable and upgrades more deliberate.

Two standardized formats cover this ground beyond requirements.txt: packaged projects declare their dependencies in pyproject.toml under [project] (PEP 621), and exact resolved versions go in a pylock.toml lock file, standardized by PEP 751 in 2025 and produced by tools like uv and pip.

How to Evaluate the Quality of Python Packages

Tutorial

How to Evaluate the Quality of Python Packages

Just like you shouldn't download any file from the Internet, you shouldn't install third-party Python packages without evaluating them first. This tutorial will give you the tool set to evaluate the quality of external Python packages before you incorporate them into your Python projects.

intermediate best-practices

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated Aug. 18, 2026