python-code-style

Python code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.

By wshobson · 14,545 installs

npx skills add wshobson/agents --skill python-code-style

Source repository · Upstream listing

Python Code Style & Documentation Consistent code style and clear documentation make codebases maintainable and collaborative. This skill covers modern Python tooling, naming conventions, and documentation standards. When to Use This Skill Setting up linting and formatting for a new project Writing or reviewing docstrings Establishing team coding standards Configuring ruff, mypy, or pyright Reviewing code for style consistency Creating project documentation Core Concepts 1. Automated Formatting Let tools handle formatting debates. Configure once, enforce automatically. 2. Consistent Naming Follow PEP 8 conventions with meaningful, descriptive names. 3. Documentation as Code Docstrings should be maintained alongside the code they describe. 4. Type Annotations Modern Python code should include type hints for all public APIs. Quick Start Fundamental Patterns Pattern 1: Modern Python Tooling Use ruff as an all in one linter and formatter. It replaces flake8, isort, and black with a single fast tool. Run with: Pattern 2: Type Checking Configuration Configure strict type checking for production code. Alternative: Use pyright for faster checking. Pattern 3: Naming Conventions Follow PEP 8 with emphasis on clarity over brevity. Files and Modules: Classes and Functions: Constants: Pattern 4: Import Organization Group imports in a consistent order: standard library, third party, local. Use absolute imports exclusively: Advanced Patterns Pattern 5: Google Style Docstrings Write docstrings for all public classes, methods, and functions. Simple Function: Complex Function: Class Docstring: Pattern 6: Line Length and Formatting Set line length to 120 characters for modern displays while maintaining readability. Pattern 7: Project Documentation README Structure: CHANGELOG Format (Keep a Changelog): Best Practices Summary 1. Use ruff Single tool for linting and formatting 2. Enable strict mypy Catch type errors before runtime 3. 120 character lines Modern standard for readability 4. Descriptive names Clarity over brevity 5. Absolute imports More maintainable than relative 6. Google style docstrings Consistent, readable documentation 7. Document public APIs Every public function needs a docstring 8. Keep docs updated Treat documentation as code 9. Automate in CI Run linters on every commit 10. Target Python 3.10+ For new projects, Python 3.12+ is recommended for modern language features