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.

DISCLAIMER 2: This is "work in progress" repository. If you did not find something you might have expected then it is just not written yet.

You can contact me via:

Table of Contents

Technology Stack

Core

DevOps & Infrastructure

Development & Quality Assurance Tools

Libraries

General Software Development Principles

General Coding Rules

  • Start new project with latest dependencies if possible
  • 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
  • Self and AI code review
  • 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
  • Implement database schema changes and related business logic in the same pull request
  • Use consistent data attributes naming
  • Assign or declare variables as close to their usage as possible
  • 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
  • Use keyword arguments for arguments with default values. Call def f(arg='default'): with f(arg='value') instead of f('value').
  • and more...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages