Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
pyenv-win
pyenv for Windows. pyenv is a simple python version management tool. It lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
-
pytest
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
-
Flake8
flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
-
safety
Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected.
-
cookiecutter
A cross-platform command-line utility that creates projects from cookiecutters (project templates), e.g. Python package projects, C projects.
-
python-project-template
Automated creation of Python projects with enforced coding standards. (by ShaneNolan)
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
Downloading and installing Python from the official binary limits you to one specific Python version, which isn’t great if you’re working on multiple projects with different Python versions. Therefore, it's better to use pyenv, a tool that lets you easily switch between multiple versions of Python.
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and integrated development environments (IDE). It works by reading the .editorconfig configuration file provided at the top level of a project. Most IDEs have built-in support but this is a list of IDEs/editors that require a plugin.
If you don’t want to use WSL2 you can install pyenv-win, a less modern approach *and skip to the **Set Python Version with pyenv* section.
Packaging systems and dependency management in Python are rather convoluted and hard to understand for newcomers. Even for seasoned developers, it might be cumbersome at times to create all files needed in a Python project. Poetry helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere. It automatically creates isolated environments for each project, preventing modifications to dependencies in another project.
If your editor is VSCode then you’re in luck because you can integrate the Linux subsystem easily with its remote WSL plugin. Once installed open your WSL terminal and execute code . . This will automatically open the VSCode editor within the Linux subsystem. You can read more about it here.
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. I prefer pytest over the inbuilt unittest library because it allows for plugins such as pytest-xdist, which enables the execution of multiple tests at once, expediting test runtimes and requires fewer lines of code to produce the same output as unittest. Additionally, pytest-cov is a plugin that automatically produces a test coverage report.
The wemake.services team describe wemake-python-styleguide as *the strictest and most opinionated Python linter ever*. It's essentially the flake8 package, a linting tool that analyses code for defects, with plugins. Its primary objectives are:
For existing projects, you can use the package flakehell with the baseline feature to report new violations since integrating a new linter will likely result in hundreds or even thousands of violations. This guide explains how to integrate flakehell and resolve violations over time.
Mypy is an optional static type checker that aims to combine the benefits of dynamic (or “duck”) typing and static typing. The benefits of statically typed code are increased readability and maintainability. For an existing code base here's a guide on how to implement Mypy.
A 2021 security report by Snyk, states 47% of Python projects contain known vulnerabilities. On the bright hand side, almost 87% of known vulnerabilities can be resolved by upgrading the vulnerable package. Safety checks your installed dependencies for known security vulnerabilities.
pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. For example, a hook that runs pytest must succeed before code can be committed to the repository, preventing code defects. The following pre-commit configuration file is what I use in my Python projects. It ensures that tests, coverage, stating type checking and vulnerability scanning all pass before code is committed.
It can become tedious maintaining configurations across projects, especially since EditorConfig, pytest-cov, flake8, Mypy and pre-commit all require configuration files. Nitpick is a tool and flake8 plugin that enforces the same configurations across multiple language-independent projects, automating this tedious configuration.
If you’re any way like me, then you must automate a task when you find yourself doing it more than once. I’ve automated the creation and configuration of a modern Python project using cookiecutter. You will need to set up your environment first. Also, nitpick uses my own take on the wemake-services configuration, you can view the repository here.
If you’re any way like me, then you must automate a task when you find yourself doing it more than once. I’ve automated the creation and configuration of a modern Python project using cookiecutter. You will need to set up your environment first. Also, nitpick uses my own take on the wemake-services configuration, you can view the repository here.