agentleFS
Diviner-DojoDiviner-Dojo/agent_framework_template/.claude/skills/python-project-patterns/SKILL.md

python-project-patterns

Skill4 starsChanged 3 months agoApache-2.0View on GitHub

Python project patterns and best practices for FastAPI applications. Reference when writing or reviewing Python code.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Create models: ItemCreate (input), ItemUpdate (partial input), ItemResponse (output)

    line 52
  2. Very specific:

    Use model_config = ConfigDict(from_attributes=True) for ORM integration

    line 54

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Project Patterns

FastAPI Application Structure

App Factory Pattern

from fastapi import FastAPI

def create_app() -> FastAPI:
    app = FastAPI(title="Project Name", version="1.0.0")
    app.include_router(router, prefix="/api")
    return app

Lifespan for Startup/Shutdown

from contextlib import asynccontextmanager

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup: initialize DB, connections
    await init_db()
    yield
    # Shutdown: cleanup
    await close_db()

Dependency Injection

from fastapi import Depends

def get_db() -> Database:
    db = Database()
    try:
        yield db
    finally:
        db.close()

@router.get("/items")
async def list_items(db: Database = Depends(get_db)):
    return db.get_all()

Pydantic Models

Request/Response Separation

  • Create models: ItemCreate (input), ItemUpdate (partial input), ItemResponse (output)
  • Input models validate and constrain; output models shape the response
  • Use model_config = ConfigDict(from_attributes=True) for ORM integration

Validation

from pydantic import BaseModel, Field

class TodoCreate(BaseModel):
    title: str = Field(..., min_length=1, max_length=200)
    description: str | None = Field(None, max_length=1000)

Error Handling

HTTP Exception Pattern

from fastapi import HTTPException

@router.get("/items/{item_id}")
async def get_item(item_id: int):
    item = db.get(item_id)
    if item is None:
        raise HTTPException(status_code=404, detail="Item not found")
    return item

Custom Exception Handlers

Register at the app level for consistent error responses across all endpoints.

Project Layout

src/
  __init__.py
  main.py          # App creation and configuration
  models.py         # Pydantic models
  routes.py         # API endpoints
  database.py       # Data access layer
  dependencies.py   # Shared dependencies (if needed)
tests/
  conftest.py       # Shared fixtures
  test_routes.py    # Endpoint tests

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.