askill
python-development

python-developmentSafety --Repository

Covers Python 3.12+ development with uv project setup, FastAPI web services, Pydantic validation, async/await patterns, type hints with mypy, pytest testing, SQLAlchemy database operations, Polars data processing, httpx API clients, and Docker deployment. Use when building Python APIs, writing async code, or when the user asks "how do I validate data?" or "what's the best way to structure a Python project?"

1 stars
1.2k downloads
Updated 2/18/2026

Package Files

Loading files...
SKILL.md

Python Development

Comprehensive guide for modern Python 3.12+ development with FastAPI ecosystem.

When to Use This Skill

  • Starting or configuring Python projects
  • Building REST APIs with FastAPI
  • Defining data models with Pydantic
  • Implementing async/await patterns
  • Adding type hints and mypy configuration
  • Writing tests with pytest
  • Working with databases (SQLAlchemy 2.0)
  • Building data pipelines with Polars
  • Integrating external APIs
  • Deploying to production with Docker

Stack Overview

LayerDefaultAlternatives
RuntimePython 3.12+-
Package Manageruvrye, poetry
Linter/Formatterruffblack + flake8
Type Checkermypypyright
Web FrameworkFastAPIFlask, Django
ValidationPydantic v2-
ORMSQLAlchemy 2.0-
Data ProcessingPolarsPandas
HTTP Clienthttpxaiohttp
Testingpytest-
ContainerizationDocker-

Core Philosophy

Follows foundations principles. Python-specific emphasis:

  • Async by default — non-blocking I/O for web services
  • Strict typing — catch errors at development time with mypy
  • Pydantic everywhere — validate at trust boundaries
  • 12-factor methodology — environment-based configuration

Quick Reference

Project Setup with uv

uv init my-project --python 3.12
uv add fastapi uvicorn pydantic-settings
uv add --dev pytest ruff mypy
uv run pytest

pyproject.toml Essentials

[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.12"

[tool.ruff]
target-version = "py312"
select = ["E", "F", "I", "N", "W", "UP"]

[tool.mypy]
python_version = "3.12"
strict = true

FastAPI Endpoint

from fastapi import FastAPI, Depends, HTTPException, status
from pydantic import BaseModel, EmailStr, Field

app = FastAPI()

class UserCreate(BaseModel):
    email: EmailStr
    username: str = Field(..., min_length=3, max_length=50)

class UserResponse(BaseModel):
    id: int
    email: EmailStr
    username: str
    model_config = {"from_attributes": True}

@app.post("/users", response_model=UserResponse, status_code=status.HTTP_201_CREATED)
async def create_user(user: UserCreate, db: AsyncSession = Depends(get_db)):
    db_user = User(**user.model_dump())
    db.add(db_user)
    await db.commit()
    await db.refresh(db_user)
    return db_user

Pydantic Model with Validation

from pydantic import BaseModel, Field, field_validator

class UserRegistration(BaseModel):
    email: EmailStr
    password: str = Field(..., min_length=8)

    @field_validator("password")
    @classmethod
    def password_strength(cls, v: str) -> str:
        if not any(c.isupper() for c in v):
            raise ValueError("Must contain uppercase")
        return v

Async Database Query

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

async def get_user(session: AsyncSession, user_id: int) -> User | None:
    result = await session.execute(select(User).where(User.id == user_id))
    return result.scalar_one_or_none()

pytest Test

@pytest.mark.asyncio
async def test_create_user(client: AsyncClient):
    response = await client.post("/users", json={"email": "test@example.com", "username": "test"})
    assert response.status_code == 201
    assert response.json()["email"] == "test@example.com"

Topics

TopicUse For
CoreProject setup, pyproject.toml, modern Python features
FastAPIREST APIs, routing, dependency injection, middleware
PydanticData models, validation, settings management
Asyncasync/await, TaskGroup, context managers
TypesType hints, mypy, Protocol, generics
Testingpytest, fixtures, mocking, async tests
DatabaseSQLAlchemy 2.0, Alembic migrations, transactions
DataPolars, ETL pipelines, schema validation
API Clientshttpx, retries, rate limiting, error handling
DeploymentDocker, logging, OpenTelemetry, health checks
Debuggingpdb, structlog, pytest debugging, remote debugging

Critical Rules

Always

  • Use async def for I/O-bound operations
  • Use Pydantic models for external input validation
  • Use pathlib.Path for file operations
  • Run mypy in CI/CD pipeline

Never

  • Block the event loop with sync I/O in async code
  • Use mutable default arguments (def foo(items=[]))
  • Skip validation on external input
  • Hardcode configuration values (use pydantic-settings)

Install

Download ZIP
Requires askill CLI v1.0+

AI Quality Score

AI review pending.

Metadata

Licenseunknown
Version-
Updated2/18/2026
Publisherlevifig

Tags

apici-cddatabaselintingobservabilitytesting