Skip to content

dmugtasimov/python-best-practices

Repository files navigation

Python Best Practices

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.

Table of Contents

Technology Stack

Core

DevOps & Infrastructure

Development & Quality Assurance Tools

Libraries

General Principles

  • 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...

General Coding Rules

  • 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...

Python Specific Rules

  • Follow PEP 8 coding style guide, read more here
  • In except clause always prefer .exception() over .error() logger method, unless you have a good reason for otherwise
  • and more...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published