/backend-and-infra:python-profrom backend-and-infra
Write idiomatic Python code with advanced features like decorators, generators, context managers, and async/await. Use when writing Python code, refactoring Python, optimizing Python performance, implementing design patterns in Python, or setting up pytest testing.
Ships in backend-and-infra. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Guidelines for writing clean, performant, and idiomatic Python code.
from typing import Protocol, TypeVar, Generic
from collections.abc import Callable, Iterator
T = TypeVar('T')
class Repository(Protocol[T]):
def get(self, id: str) -> T | None: ...
def save(self, item: T) -> None: ...
def process_items[T](items: list[T], fn: Callable[[T], T]) -> Iterator[T]:
for item in items:
yield fn(item)
from contextlib import contextmanager
from typing import Generator
@contextmanager
def managed_resource(name: str) -> Generator[Resource, None, None]:
resource = Resource(name)
try:
yield resource
finally:
resource.cleanup()
from functools import wraps
from typing import ParamSpec, TypeVar, Callable
P = ParamSpec('P')
R = TypeVar('R')
def retry(max_attempts: int = 3) -> Callable[[Callable[P, R]], Callable[P, R]]:
def decorator(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
for attempt in range(max_attempts):
try:
return func(*args, **kwargs)
except Exception as e:
if attempt == max_attempts - 1:
raise
raise RuntimeError("Unreachable")
return wrapper
return decorator
import asyncio
from typing import AsyncIterator
async def fetch_all[T](urls: list[str], parse: Callable[[str], T]) -> list[T]:
async with aiohttp.ClientSession() as session:
tasks = [fetch_one(session, url, parse) for url in urls]
return await asyncio.gather(*tasks)
async def stream_data() -> AsyncIterator[bytes]:
async with aiofiles.open('large.csv', 'rb') as f:
async for chunk in f:
yield chunk
from dataclasses import dataclass
@dataclass
class ValidationError(Exception):
field: str
message: str
value: object = None
def __str__(self) -> str:
return f"{self.field}: {self.message} (got {self.value!r})"
import pytest
from typing import Generator
@pytest.fixture
def db_session() -> Generator[Session, None, None]:
session = Session()
yield session
session.rollback()
@pytest.fixture
def sample_user(db_session: Session) -> User:
user = User(name="test", email="[email protected]")
db_session.add(user)
return user
@pytest.mark.parametrize("input,expected", [
("hello", "HELLO"),
("World", "WORLD"),
("", ""),
])
def test_uppercase(input: str, expected: str) -> None:
assert input.upper() == expected
import pytest
@pytest.mark.asyncio
async def test_fetch_data() -> None:
result = await fetch_data("https://api.example.com")
assert result.status == "success"
project/
├── pyproject.toml # Modern Python config
├── src/
│ └── package/
│ ├── __init__.py
│ ├── py.typed # PEP 561 marker
│ ├── domain/ # Business logic
│ ├── services/ # Application services
│ └── adapters/ # External integrations
├── tests/
│ ├── conftest.py # Shared fixtures
│ ├── unit/
│ └── integration/
└── .python-version # pyenv version
[project]
name = "myproject"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = []
[project.optional-dependencies]
dev = ["pytest>=8.0", "mypy>=1.8", "ruff>=0.2"]
[tool.ruff]
line-length = 100
target-version = "py311"
[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM"]
[tool.mypy]
strict = true
python_version = "3.11"
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
__slots__ for data classes with many instancesdict.get() over try/except KeyErroritertools for efficient iterationcProfile and line_profilerfunctools.lru_cache for expensive pure functionsdef f(items=[]) → def f(items=None)except: clauses → Always specify exception typetype() for comparisons → Use isinstance()"".join() or f-strings_What SKILL.md sets; muted values are Claude Code's defaults
6 skills in this plugin
/backend-patternsBackend architecture patterns, API design, database optimization, and server-side best practices for Node.js, Express, and Next.js API routes./dockerDocker and Docker Compose for local dev, homelab (Raspberry Pi 5 / ARM64), and production. Scaffolds production-ready Compose configs via /docker, and serves as a best-practice reference for container security, networking, volumes, multi-stage builds, and debugging. Use when writing Dockerfiles, setting up Compose, troubleshooting containers, or doing homelab stack work./homelab-helperExpert guidance for homelab infrastructure, self-hosting, and Raspberry Pi optimization. Use when recommending self-hosted services, configuring Docker services, setting up reverse proxies, integrating Home Assistant, or troubleshooting homelab networking.Other plugins' skills for the same job
npx claudepluginhub arosenkranz/agent-config --plugin backend-and-infra