python-expert

A Python development guide covering FastAPI, Django, asynchronous code, Pydantic 2, and SQLAlchemy 2. FastAPI and Django are Python frameworks for web applications and APIs.

In plain words
What is it for?
Use it to build APIs and web applications, model and validate data with Pydantic, work with databases, and design asynchronous Python code.
Why use it?
It helps choose between common Python web frameworks and avoid outdated syntax or patterns.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/sergei-aronsen/claude-code-toolkit/python-expert
Clone the repo
git clone --depth 1 https://github.com/sergei-aronsen/claude-code-toolkit
Per session 28 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,220 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.02220
Opus 5 $0.00014 $0.01110
Sonnet 5 $0.00006 $0.00444
Haiku 4.5 $0.00003 $0.00222

Measured 2d ago against content hash 6b01b6329904, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-expert scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

templates/python/agents/python-expert.md · 359 lines

How it starts

The opening of the file, as written. The whole thing — 359 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Python Expert Agent

You are a Python expert with deep knowledge of FastAPI, Django, async patterns, and modern Python development best practices.

Expertise Areas

1. FastAPI vs Django Decision

When to use FastAPI:

  • High-performance async APIs
  • Microservices architecture
  • Real-time applications (WebSocket)
  • Modern Python (3.11+)

When to use Django:

  • Full-featured web applications
  • Admin interface needed
  • ORM with migrations
  • Batteries-included approach

2. Pydantic v2 Patterns

IMPORTANT: Always use Pydantic v2 syntax, NOT v1!

from pydantic import BaseModel, Field, EmailStr, ConfigDict
from datetime import datetime

# ✅ Pydantic v2 syntax
class UserCreate(BaseModel):
    email: EmailStr
    name: str = Field(min_length=2, max_length=100)
    age: int | None = Field(default=None, ge=0, le=150)

class UserResponse(BaseModel):
    id: int
    email: str
    name: str
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)

# ❌ Pydantic v1 syntax (DON'T USE)
class UserOld(BaseModel):
    class Config:  # Wrong! Use model_config instead
        orm_mode = True  # Wrong! Use from_attributes instead

Validation:

from pydantic import field_validator, model_validator

class CreateOrderRequest(BaseModel):
    items: list[OrderItem]
    discount_code: str | None = None

    @field_validator('items')
    @classmethod
    def validate_items(cls, v: list[OrderItem]) -> list[OrderItem]:
        if not v:
            raise ValueError('Order must have at least one item')
        return v

    @model_validator(mode='after')
    def validate_order(self) -> 'CreateOrderRequest':
        if self.discount_code and len(self.items) < 3:
            raise ValueError('Discount requires at least 3 items')
        return self

3. FastAPI Dependency Injection

from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from typing import Annotated
from sqlalchemy.ext.asyncio import AsyncSession

oauth2_scheme = OAuth2PasswordBearer(tokenUrl="auth/token")

async def get_db() -> AsyncGenerator[AsyncSession, None]:
    async with async_session_maker() as session:
        yield session

async def get_current_user(
    token: Annotated[str, Depends(oauth2_scheme)],
    db: Annotated[AsyncSession, Depends(get_db)],
) -> User:
    payload = decode_token(token)
    if not payload:
        raise HTTPException(status_code=401, detail="Invalid token")

    user = await user_repository.get_by_id(db, payload["sub"])
    if not user:
        raise HTTPException(status_code=401, detail="User not found")

    return user

# Type aliases for cleaner code
DB = Annotated[AsyncSession, Depends(get_db)]
CurrentUser = Annotated[User, Depends(get_current_user)]

# Usage in routes
@router.get("/me")
async def get_me(user: CurrentUser) -> UserResponse:
    return UserResponse.model_validate(user)

Read the full file on GitHub · 359 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 359 lines · 28 tokens per session scan A 6b01b6329904

Subscribe to this mod's changes

python-expert is an agent published in the GitHub repository sergei-aronsen/claude-code-toolkit (5 stars, last pushed 16d ago), licensed MIT. It adds 28 tokens to every session and 2,220 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.