
Python Code Style
- 12.3k installs
- 38.3k repo stars
- Updated July 22, 2026
- wshobson/agents
How to configure and enforce Python code style, type checking, naming conventions, import organization, and docstring standards using ruff, mypy, and pyright.
About
This skill teaches modern Python code style, linting, and documentation practices for maintainable codebases. It covers automated formatting with ruff, type checking with mypy/pyright, PEP 8 naming conventions, import organization, and Google-style docstrings. Developers use it when setting up project standards, configuring tools in pyproject.toml, writing or reviewing docstrings, and establishing team coding conventions. Key workflows include installing ruff and mypy, enabling strict type checking, documenting public APIs with consistent docstring formats, and automating style checks in CI/CD pipelines.
- Configure ruff for unified linting and formatting, replacing flake8, isort, and black
- Set strict mypy or pyright type checking to catch errors before runtime
- Write Google-style docstrings for classes, functions, and methods with Args/Returns/Raises
- Follow PEP 8 naming: snake_case functions, PascalCase classes, SCREAMING_SNAKE_CASE constants
- Organize imports in three groups: stdlib, third-party, local absolute imports
Python Code Style by the numbers
- 12,331 all-time installs (skills.sh)
- +326 installs in the week ending Jul 28, 2026 (Skillselion tracking)
- Ranked #36 of 1,901 Documentation skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Jul 28, 2026 (Skillselion catalog sync)
python-code-style capabilities & compatibility
- Capabilities
- configure automated linting and formatting · set up strict type checking · write google style docstrings · establish naming conventions · organize imports correctly · document public apis
- Use cases
- code review · documentation · testing · refactoring
- Platforms
- macOS · Windows · Linux · WSL
- Runs
- Runs locally
- Pricing
- Free
What python-code-style says it does
Docstrings should be maintained alongside the code they describe.
Follow PEP 8 conventions with meaningful, descriptive names.
Modern Python code should include type hints for all public APIs.
npx skills add https://github.com/wshobson/agents --skill python-code-styleAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 12.3k |
|---|---|
| repo stars | ★ 38.3k |
| Security audit | 3 / 3 scanners passed |
| Last updated | July 22, 2026 |
| Repository | wshobson/agents ↗ |
What it does
Configure linting, formatting, type checking, and docstring standards for Python projects.
Who is it for?
Setting up new Python projects, enforcing team coding standards, configuring linters and formatters, writing public API documentation, enabling strict type checking.
Skip if: Legacy Python 2 codebases, projects without type hints, teams opposed to automated tooling, dynamic code generation systems.
When should I use this skill?
Starting a new project, establishing team standards, reviewing code for style consistency, configuring pre-commit hooks, documenting public APIs.
What you get
Developers establish automated, enforceable code style standards with strict type checking and clear docstrings, improving code quality and team collaboration.
- pyproject.toml with ruff and mypy configuration
- linting and formatting setup
- docstring standards for team
By the numbers
- Recommended line length: 120 characters for modern displays
- Minimum Python version: 3.10+ (3.12+ recommended for new projects)
- Core linting rules: E (errors), W (warnings), F (pyflakes), I (isort), B (bugbear), C4 (comprehensions), UP (pyupgrade),
Files
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
# Install modern tooling
pip install ruff mypy
# Configure in pyproject.toml
[tool.ruff]
line-length = 120
target-version = "py312" # Adjust based on your project's minimum Python version
[tool.mypy]
strict = trueFundamental 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.
# pyproject.toml
[tool.ruff]
line-length = 120
target-version = "py312" # Adjust based on your project's minimum Python version
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"SIM", # flake8-simplify
]
ignore = ["E501"] # Line length handled by formatter
[tool.ruff.format]
quote-style = "double"
indent-style = "space"Run with:
ruff check --fix . # Lint and auto-fix
ruff format . # Format codePattern 2: Type Checking Configuration
Configure strict type checking for production code.
# pyproject.toml
[tool.mypy]
python_version = "3.12"
strict = true
warn_return_any = true
warn_unused_ignores = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = falseAlternative: Use pyright for faster checking.
[tool.pyright]
pythonVersion = "3.12"
typeCheckingMode = "strict"Pattern 3: Naming Conventions
Follow PEP 8 with emphasis on clarity over brevity.
Files and Modules:
# Good: Descriptive snake_case
user_repository.py
order_processing.py
http_client.py
# Avoid: Abbreviations
usr_repo.py
ord_proc.py
http_cli.pyClasses and Functions:
# Classes: PascalCase
class UserRepository:
pass
class HTTPClientFactory: # Acronyms stay uppercase
pass
# Functions and variables: snake_case
def get_user_by_email(email: str) -> User | None:
retry_count = 3
max_connections = 100Constants:
# Module-level constants: SCREAMING_SNAKE_CASE
MAX_RETRY_ATTEMPTS = 3
DEFAULT_TIMEOUT_SECONDS = 30
API_BASE_URL = "https://api.example.com"Pattern 4: Import Organization
Group imports in a consistent order: standard library, third-party, local.
# Standard library
import os
from collections.abc import Callable
from typing import Any
# Third-party packages
import httpx
from pydantic import BaseModel
from sqlalchemy import Column
# Local imports
from myproject.models import User
from myproject.services import UserServiceUse absolute imports exclusively:
# Preferred
from myproject.utils import retry_decorator
# Avoid relative imports
from ..utils import retry_decoratorAdvanced Patterns
Pattern 5: Google-Style Docstrings
Write docstrings for all public classes, methods, and functions.
Simple Function:
def get_user(user_id: str) -> User:
"""Retrieve a user by their unique identifier."""
...Complex Function:
def process_batch(
items: list[Item],
max_workers: int = 4,
on_progress: Callable[[int, int], None] | None = None,
) -> BatchResult:
"""Process items concurrently using a worker pool.
Processes each item in the batch using the configured number of
workers. Progress can be monitored via the optional callback.
Args:
items: The items to process. Must not be empty.
max_workers: Maximum concurrent workers. Defaults to 4.
on_progress: Optional callback receiving (completed, total) counts.
Returns:
BatchResult containing succeeded items and any failures with
their associated exceptions.
Raises:
ValueError: If items is empty.
ProcessingError: If the batch cannot be processed.
Example:
>>> result = process_batch(items, max_workers=8)
>>> print(f"Processed {len(result.succeeded)} items")
"""
...Class Docstring:
class UserService:
"""Service for managing user operations.
Provides methods for creating, retrieving, updating, and
deleting users with proper validation and error handling.
Attributes:
repository: The data access layer for user persistence.
logger: Logger instance for operation tracking.
Example:
>>> service = UserService(repository, logger)
>>> user = service.create_user(CreateUserInput(...))
"""
def __init__(self, repository: UserRepository, logger: Logger) -> None:
"""Initialize the user service.
Args:
repository: Data access layer for users.
logger: Logger for tracking operations.
"""
self.repository = repository
self.logger = loggerPattern 6: Line Length and Formatting
Set line length to 120 characters for modern displays while maintaining readability.
# Good: Readable line breaks
def create_user(
email: str,
name: str,
role: UserRole = UserRole.MEMBER,
notify: bool = True,
) -> User:
...
# Good: Chain method calls clearly
result = (
db.query(User)
.filter(User.active == True)
.order_by(User.created_at.desc())
.limit(10)
.all()
)
# Good: Format long strings
error_message = (
f"Failed to process user {user_id}: "
f"received status {response.status_code} "
f"with body {response.text[:100]}"
)Pattern 7: Project Documentation
README Structure:
# Project Name
Brief description of what the project does.
## Installation
\`\`\`bash
pip install myproject
\`\`\`
## Quick Start
\`\`\`python
from myproject import Client
client = Client(api_key="...")
result = client.process(data)
\`\`\`
## Configuration
Document environment variables and configuration options.
## Development
\`\`\`bash
pip install -e ".[dev]"
pytest
\`\`\`CHANGELOG Format (Keep a Changelog):
# Changelog
## [Unreleased]
### Added
- New feature X
### Changed
- Modified behavior of Y
### Fixed
- Bug in ZBest 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
Related skills
Forks & variants (1)
Python Code Style has 1 known copy in the catalog totaling 39 installs. They canonicalize to this original listing.
- jurgendn - 39 installs
How it compares
Pick python-code-style for agent-guided Python conventions and linter setup; rely on pre-commit hooks alone when CI already auto-formats without needing authoring-time guidance.
FAQ
Should I use ruff or black for formatting?
Ruff combines linting and formatting in one fast tool, replacing flake8, isort, and black. Configure it once in pyproject.toml and run 'ruff check --fix' and 'ruff format'.
What does 'strict = true' do in mypy?
Strict mode enforces type hints on all functions, disallows untyped definitions, and requires explicit handling of optional values, catching errors before runtime.
Do I need docstrings for every function?
Yes, all public functions, classes, and methods should have docstrings. Use Google-style format with Args, Returns, Raises, and Example sections.
Is Python Code Style safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.