askill
python-backend

python-backendSafety 95Repository

Apply for any Python backend project: FastAPI, async patterns, structured logging, PostgreSQL with SQLAlchemy 2.0, error handling, and project structure standards.

1 stars
1.2k downloads
Updated 2/28/2026

Package Files

Loading files...
SKILL.md

PYTHON BACKEND — Production Standards 2025

Structured Logging (NOT print())

import structlog

log = structlog.get_logger()

# Usage — always with context
log.info("job.submitted", job_id=str(job_id), job_type=job_type, user_id=user_id)
log.error("job.failed", job_id=str(job_id), error=str(exc), attempt=attempt)

FastAPI Lifespan (NOT @app.on_event deprecated)

from contextlib import asynccontextmanager

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup
    await db.connect()
    await redis_pool.initialize()
    yield
    # Shutdown
    await db.disconnect()
    await redis_pool.close()

app = FastAPI(lifespan=lifespan)

SQLAlchemy 2.0 Async

from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import DeclarativeBase

engine = create_async_engine(DATABASE_URL, pool_size=10, max_overflow=20)

async def get_db():
    async with AsyncSession(engine) as session:
        yield session

Error Handling Pattern

# Domain exceptions, not raw HTTP codes in business logic
class JobNotFound(Exception): pass
class JobQueueFull(Exception): pass

@app.exception_handler(JobNotFound)
async def job_not_found_handler(request, exc):
    return JSONResponse(status_code=404, content={"detail": str(exc)})

Project Structure (standard)

src/
├── api/
│   ├── main.py          # FastAPI app + lifespan
│   ├── routes/          # One file per domain
│   └── middleware.py
├── domain/
│   ├── models.py        # SQLAlchemy models
│   ├── schemas.py       # Pydantic schemas
│   └── services.py      # Business logic
├── infrastructure/
│   ├── database.py
│   └── redis.py
└── config.py            # pydantic-settings

Type Hints — Always

# Return types on all functions
async def get_job(job_id: UUID) -> JobResponse | None: ...
# Never use Dict, List — use dict, list (Python 3.9+)
async def process_batch(jobs: list[dict]) -> list[str]: ...

Forbidden

print() for logging in production code ❌ @app.on_event("startup") (deprecated since FastAPI 0.93) ❌ Session (sync) instead of AsyncSession ❌ Functions without type hints ❌ Catching bare except Exception without logging

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

82/100Analyzed 3/2/2026

Well-structured technical reference for Python backend standards covering FastAPI, SQLAlchemy 2.0, structured logging, and project structure. Provides practical, copy-pasteable code examples with clear sections. Slightly lower completeness due to missing testing, CI/CD, and auth patterns, but excellent for what it covers. Tags enhance discoverability. Not internal-only.

95
90
90
65
85

Metadata

Licenseunknown
Version-
Updated2/28/2026
PublisherTryboy869

Tags

apidatabaseobservability