Skip to content

Instantly share code, notes, and snippets.

@scanzy
Created June 23, 2025 12:40
Show Gist options
  • Save scanzy/66505b8e1f6b2cf4d061da42ad64b163 to your computer and use it in GitHub Desktop.
Save scanzy/66505b8e1f6b2cf4d061da42ad64b163 to your computer and use it in GitHub Desktop.
Python coding standard

Coding Standard for python code

Feed this to your AI to have your code tidy and awesome.

Code Layout

  • Line Length: maximum 100 characters
  • 1 blank line: between functions, methods, classes, after imports
  • 2 blank lines: between logical sections, after docstrings, at end of every file

Naming

  • Classes, Functions, Methods: UpperCamelCase
  • Variables, Members: lowerCamelCase
  • Constants: UPPER_SNAKE_CASE

Docstrings

  • Use triple double-quotes, keeping them short and focused
  • Only document args and returns if not intuitive from the function name and types

Comments

  • Each logical block should have a descriptive comment
  • Explain "why" not "what"
  • Keep up-to-date with code changes

Type Annotations

  • Required for function parameters and return values
  • Use built-in types when possible, use collections.abc for container types

Code Organization

  • One class per file (with rare exceptions)
  • Group related functionality
  • Keep methods focused and single-purpose
  • Break long functions into smaller pieces
  • Include descriptive error messages, with possible solutions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment