Python Best Practices developed by Dmitry Mugtasimov during the course of his 26-year career in software engineering.
DISCLAIMER: This repository documents Python best practices as I have developed and refined them over 26 years of professional software engineering. They reflect my experience, reasoning, and approach to building and maintaining software, and are shared as a practical reference rather than as a definitive or universal standard. As with any engineering guidance, their applicability may vary depending on context, constraints, and goals.
- Python - programming language
- Django - web framework
- Django REST Framework (alternatively FastAPI + SQLAlchemy + Alembic) - REST API framework
- Celery - distributed task queue
- PostgreSQL - relational database
- RabbitMQ - message broker
- Redis - in-memory data store
- uv (earlier Poetry + pyenv) - package management
- Docker + Docker Compose - containerization platform
- Pulumi - infrastructure as code
- Sentry - error tracking
- AWS - cloud platform
- Uvicorn, Gunicorn - application servers
- NGINX (or Traefik for containerized deployments) - load balancer and reverse proxy
- Let's Encrypt - SSL/TLS certificate authority
- GitHub Actions - CI/CD platform
- PyCharm - IDE
- AI coding assistants
- Linear (alternatively - GitHub Projects) - project management
- pytest - testing framework
- diff-cover - test coverage tool
- pre-commit - git hook manager
- Ruff (earlier Flake8, Pylint) - linting and formatting
- GNU Make - command automation
- model-bakery - fixture factory
- ngrok - local tunneling service
- VCR.py - HTTP interaction recording
- Moto - AWS service mocking
- pdbpp - enhanced debugger
- colorlog - colored logging
- django-split-settings - settings organization
- django-restql - GraphQL-like API queries
- django-dirtyfields - model field change tracking
- WhiteNoise - static file serving
- Anymail - email service integration
- python-jose - JWT library
- Jinja - template engine
- time-machine - time mocking for tests
- Pydantic - data validation
- tqdm - progress bars
- cachetools - caching utilities
- HTTPX (preferred over Requests) - HTTP client
- Tenacity - retry library
- Beautiful Soup - HTML/XML parser
- Liquid - template engine
- Respect best practices
- Respect industry standards
- Respect backward compatibility
- Respect forward compatibility
- The Less code (lines) the better
- Write code to be read (by humans and AI), not just to be executed
- DRY (Don't Repeat Yourself)
- KISS (Keep It Simple, Stupid)
- YAGNI (You Aren't Gonna Need It)
- Principle of Least Astonishment
- Start new project with latest dependencies if possible
- Have a reason behind every decision
- Respect business needs over technical preferences
- Automate repetitive tasks
- Use AI for coding as much as possible
- Review and refactor AI-generated code
- Continuous refactoring
- Unit testing
- Continuous Learning
- and more...
- Declare and assign variable values as close to the usages as possible
- Do not put a value to a variable if it is then read just once
- Do not implement logic that depends on environment name the code is running in
- Do not hard code a list of environments
- Avoid dead code
- Use comments and docstrings reasonably
- Use asserts to describe expected invariants and assumptions in the code
- Use TODO or FIX comments to describe technical debt and convey intended imperfections to other developers
- and more...