Plangs!
Menu
Sun
geo

Python type checking and package management

Type Checking#

Python has supported optional type annotations for several years now. While types may seem unnecessary for smaller scripts or projects, they become almost indispensable for large, complex codebases. Type annotations can help identify potential issues early, leading to more reliable and maintainable code.

Two prominent type-checking tools for Python are:

mypy

One of the earliest static type checkers for (pl+python) and has been widely adopted by the community.

Pyright

Generally found to be faster and stricter by default than MyPy.

Pyright's tight integration with vscode through Python for VSCode makes for a smooth, enjoyable experience and is my preferred way of using type annotations with Python.

Package Management#

Python is well known for its messy package management ecosystem. There are many tools available to "solve" this issue, and perhaps that's part of the problem: the paradox of choice. For my projects, I've found that Pixi covers all my needs, including:

  • Installing Python itself, per project (no need for a global installation).
  • Installing dependencies needed by Python packages, like C libraries.
  • Installing Python pip packages.
  • Pixi is cross-platform across Windows, osx and Linux.

On it's own words:

Pixi builds upon the foundation of the conda ecosystem, introducing a project-centric approach rather than focusing solely on environments.

If you're starting a new project, it's worth giving Pixi a try, especially if you're looking for something faster and lighter than traditional tools like (tool:poetry). Pixi is written in Rust, and consists of a single executable binary.