Tools to setup great python projects
09-07, 12:30–13:05 (Europe/Lisbon), Auditorium

In a professional python project, there are many steps one can take to improve its quality. In this talk, I will review some tools that have been useful to me:

  • package managers
  • code formatters
  • code linters
  • test runners
  • python manager

I will also talk about centralizing the configuration so different tools can act consistently, eg CLI, IDE and CI/CD.


Edit: I created a small demo in Github, if you're interested.

Package managers

  • no package manager is a (very) bad idea
  • requirements.txt is a good improvement, but makes it harder to do some things, eg lock sub-dependencies versions and specify development-only dependencies
  • pipenv is good, but I prefer poetry

Python manager

  • pyenv makes it easy to install and manage multiple python versions

Code formatters

  • black: formats the code ("any color you want, as long as it's black")
  • isort: sorts the imports ("i sort so you don't have to")
  • darker: formats code only since last commit (gradual formatting for older projects)

Code linters

  • pylint: decent start but too many false positives
  • pycodestyle: popular, didn't use it much
  • flake8: popular and used it a bit, it's ok
  • ruff: the cool kid in the block: much faster and supports rules from different linters

Honorable mentions: bandit, bugbear, pyupgrade

Test runners

  • unittest: native, it's decent but verbose
  • pytest: widely used, supports plugins
  • locust: didn't use it much but potentially useful for load testing
  • hypothesis: property based testing

Centralized configuration

Centralize your configs in pyproject.toml such that every application runs the tools consistently:
- CLI
- IDE
- git hooks / pre-commit
- CI/CD

flake8 didn't support pyproject.toml because it wasn't standard - well now it is, in PEP 621, but it doesn't support it anyway. Bad flake8!

See also: slides (225.1 KB)

Hi, I'm Duarte. I'm a software engineer since 2019, and my passions are architecture, clean code, incremental development and refactoring. I can also make some mean Moscow Mules!

Also here's the link to my linkedin. Link, Linkedin, get it? Sorry.