Skip to content

Repository files navigation

Python Best Practices

Python Best Practices developed by Dmitry Mugtasimov during the course of his 27-years career in software engineering.

You can contact me via:

DISCLAIMER: This repository documents Python best practices as I have developed and refined them over 27 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.

DISCLAIMER 3: There are a lot of changes happened since the beginning of 2026 due to the AI advancements. Not all them have been reflected here yet.

Table of Contents

Technology Stack

Core

DevOps & Infrastructure

Development & Quality Assurance Tools

Libraries

General Software Development Principles

General Coding Rules

  • AI Augmented Workflow
  • 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 code review and AI aided code review before submitting a pull request
  • Prefer REST API over RPC API, otherwise use GraphQL API
  • 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
  • Use ServiceNameClient class wrapper even with official SDKs and service clients
  • and more...

Python Specific Rules

  • Follow PEP 8 coding style guide, read more here
  • Use Python logging framework instead of print statements for logging
  • 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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages