lang-python
Python 3.13+ development specialist covering FastAPI, Django, async patterns, data science, testing with pytest, and modern Python features. Use when developing Python APIs, web applications, data pipelines, or writing tests.
Best use case
lang-python is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Python 3.13+ development specialist covering FastAPI, Django, async patterns, data science, testing with pytest, and modern Python features. Use when developing Python APIs, web applications, data pipelines, or writing tests.
Teams using lang-python should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/lang-python/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How lang-python Compares
| Feature / Agent | lang-python | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Python 3.13+ development specialist covering FastAPI, Django, async patterns, data science, testing with pytest, and modern Python features. Use when developing Python APIs, web applications, data pipelines, or writing tests.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
## Quick Reference (30 seconds)
Python 3.13+ Development Specialist - FastAPI, Django, async patterns, pytest, and modern Python features.
Auto-Triggers: `.py` files, `pyproject.toml`, `requirements.txt`, `pytest.ini`, FastAPI/Django discussions
Core Capabilities:
- Python 3.13 Features: JIT compiler (PEP 744), GIL-free mode (PEP 703), pattern matching
- Web Frameworks: FastAPI 0.115+, Django 5.2 LTS
- Data Validation: Pydantic v2.9 with model_validate patterns
- ORM: SQLAlchemy 2.0 async patterns
- Testing: pytest with fixtures, async testing, parametrize
- Package Management: poetry, uv, pip with pyproject.toml
- Type Hints: Protocol, TypeVar, ParamSpec, modern typing patterns
- Async: asyncio, async generators, task groups
- Data Science: numpy, pandas, polars basics
### Quick Patterns
FastAPI Endpoint:
```python
from fastapi import FastAPI, Depends
from pydantic import BaseModel
app = FastAPI()
class UserCreate(BaseModel):
name: str
email: str
@app.post("/users/")
async def create_user(user: UserCreate) -> User:
return await UserService.create(user)
```
Pydantic v2.9 Validation:
```python
from pydantic import BaseModel, ConfigDict
class User(BaseModel):
model_config = ConfigDict(from_attributes=True, str_strip_whitespace=True)
id: int
name: str
email: str
user = User.model_validate(orm_obj) # from ORM object
user = User.model_validate_json(json_data) # from JSON
```
pytest Async Test:
```python
import pytest
@pytest.mark.asyncio
async def test_create_user(async_client):
response = await async_client.post("/users/", json={"name": "Test"})
assert response.status_code == 201
```
---
## Implementation Guide (5 minutes)
### Python 3.13 New Features
JIT Compiler (PEP 744):
- Experimental feature, disabled by default
- Enable: `PYTHON_JIT=1` environment variable
- Build option: `--enable-experimental-jit`
- Provides performance improvements for CPU-bound code
- Copy-and-patch JIT that translates specialized bytecode to machine code
GIL-Free Mode (PEP 703):
- Experimental free-threaded build (python3.13t)
- Allows true parallel thread execution
- Available in official Windows/macOS installers
- Best for: CPU-intensive multi-threaded applications
- Not recommended for production yet
Pattern Matching (match/case):
```python
def process_response(response: dict) -> str:
match response:
case {"status": "ok", "data": data}:
return f"Success: {data}"
case {"status": "error", "message": msg}:
return f"Error: {msg}"
case {"status": status} if status in ("pending", "processing"):
return "In progress..."
case _:
return "Unknown response"
```
### FastAPI 0.115+ Patterns
Async Dependency Injection:
```python
from fastapi import FastAPI, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup
await init_db()
yield
# Shutdown
await cleanup()
app = FastAPI(lifespan=lifespan)
async def get_db() -> AsyncGenerator[AsyncSession, None]:
async with async_session() as session:
yield session
@app.get("/users/{user_id}")
async def get_user(
user_id: int,
db: AsyncSession = Depends(get_db)
) -> UserResponse:
user = await get_user_by_id(db, user_id)
return UserResponse.model_validate(user)
```
Class-Based Dependencies:
```python
from fastapi import Depends
class Paginator:
def __init__(self, page: int = 1, size: int = 20):
self.page = max(1, page)
self.size = min(100, max(1, size))
self.offset = (self.page - 1) * self.size
@app.get("/items/")
async def list_items(pagination: Paginator = Depends()) -> list[Item]:
return await Item.get_page(pagination.offset, pagination.size)
```
### Django 5.2 LTS Features
Composite Primary Keys:
```python
from django.db import models
class OrderItem(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField()
class Meta:
pk = models.CompositePrimaryKey("order", "product")
```
URL Reverse with Query Parameters:
```python
from django.urls import reverse
url = reverse("search", query={"q": "django", "page": 1}, fragment="results")
# /search/?q=django&page=1#results
```
Automatic Model Imports in Shell:
```bash
python manage.py shell
# Models from all installed apps are automatically imported
```
### Pydantic v2.9 Deep Patterns
Reusable Validators with Annotated:
```python
from typing import Annotated
from pydantic import AfterValidator, BaseModel
def validate_positive(v: int) -> int:
if v <= 0:
raise ValueError("Must be positive")
return v
PositiveInt = Annotated[int, AfterValidator(validate_positive)]
class Product(BaseModel):
price: PositiveInt
quantity: PositiveInt
```
Model Validator for Cross-Field Validation:
```python
from pydantic import BaseModel, model_validator
from typing import Self
class DateRange(BaseModel):
start_date: date
end_date: date
@model_validator(mode="after")
def validate_dates(self) -> Self:
if self.end_date < self.start_date:
raise ValueError("end_date must be after start_date")
return self
```
ConfigDict Best Practices:
```python
from pydantic import BaseModel, ConfigDict
class BaseSchema(BaseModel):
model_config = ConfigDict(
from_attributes=True, # ORM object support
populate_by_name=True, # Allow aliases
extra="forbid", # Fail on unknown fields
str_strip_whitespace=True, # Clean strings
)
```
### SQLAlchemy 2.0 Async Patterns
Engine and Session Setup:
```python
from sqlalchemy.ext.asyncio import (
create_async_engine,
async_sessionmaker,
AsyncSession,
)
engine = create_async_engine(
"postgresql+asyncpg://user:pass@localhost/db",
pool_pre_ping=True,
echo=True,
)
async_session = async_sessionmaker(
engine,
class_=AsyncSession,
expire_on_commit=False, # Prevent detached instance errors
)
```
Repository Pattern:
```python
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
class UserRepository:
def __init__(self, session: AsyncSession):
self.session = session
async def get_by_id(self, user_id: int) -> User | None:
result = await self.session.execute(
select(User).where(User.id == user_id)
)
return result.scalar_one_or_none()
async def create(self, user: UserCreate) -> User:
db_user = User(**user.model_dump())
self.session.add(db_user)
await self.session.commit()
await self.session.refresh(db_user)
return db_user
```
Streaming Large Results:
```python
async def stream_users(db: AsyncSession):
result = await db.stream(select(User))
async for user in result.scalars():
yield user
```
### pytest Advanced Patterns
Async Fixtures with pytest-asyncio:
```python
import pytest
import pytest_asyncio
from httpx import AsyncClient
@pytest_asyncio.fixture
async def async_client(app) -> AsyncGenerator[AsyncClient, None]:
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
@pytest_asyncio.fixture
async def db_session() -> AsyncGenerator[AsyncSession, None]:
async with async_session() as session:
async with session.begin():
yield session
await session.rollback()
```
Parametrized Tests:
```python
@pytest.mark.parametrize(
"input_data,expected_status",
[
({"name": "Valid"}, 201),
({"name": ""}, 422),
({}, 422),
],
ids=["valid", "empty_name", "missing_name"],
)
async def test_create_user(async_client, input_data, expected_status):
response = await async_client.post("/users/", json=input_data)
assert response.status_code == expected_status
```
Fixture Factories:
```python
@pytest.fixture
def user_factory():
async def _create_user(db: AsyncSession, **kwargs) -> User:
defaults = {"name": "Test User", "email": "test@example.com"}
user = User(**(defaults | kwargs))
db.add(user)
await db.commit()
return user
return _create_user
```
### Type Hints Modern Patterns
Protocol for Structural Typing:
```python
from typing import Protocol, runtime_checkable
@runtime_checkable
class Repository(Protocol[T]):
async def get(self, id: int) -> T | None: ...
async def create(self, data: dict) -> T: ...
async def delete(self, id: int) -> bool: ...
```
ParamSpec for Decorators:
```python
from typing import ParamSpec, TypeVar, Callable
from functools import wraps
P = ParamSpec("P")
R = TypeVar("R")
def retry(times: int = 3) -> Callable[[Callable[P, R]], Callable[P, R]]:
def decorator(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
async def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
for attempt in range(times):
try:
return await func(*args, **kwargs)
except Exception:
if attempt == times - 1:
raise
return wrapper
return decorator
```
### Package Management
pyproject.toml (Poetry):
```toml
[tool.poetry]
name = "my-project"
version = "1.0.0"
python = "^3.13"
[tool.poetry.dependencies]
fastapi = "^0.115.0"
pydantic = "^2.9.0"
sqlalchemy = {extras = ["asyncio"], version = "^2.0.0"}
[tool.poetry.group.dev.dependencies]
pytest = "^8.0"
pytest-asyncio = "^0.24"
ruff = "^0.8"
[tool.ruff]
line-length = 100
target-version = "py313"
[tool.pytest.ini_options]
asyncio_mode = "auto"
```
uv (Fast Package Manager):
```bash
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create virtual environment
uv venv
# Install dependencies
uv pip install -r requirements.txt
# Add dependency
uv add fastapi
```
---
## Advanced Implementation (10+ minutes)
For comprehensive coverage including:
- Production deployment patterns (Docker, Kubernetes)
- Advanced async patterns (task groups, semaphores)
- Data science integration (numpy, pandas, polars)
- Performance optimization techniques
- Security best practices (OWASP patterns)
- CI/CD integration patterns
See:
- [reference.md](reference.md) - Complete reference documentation
- [examples.md](examples.md) - Production-ready code examples
---
## Context7 Library Mappings
```
/docs/astral.sh/uv
/tiangolo/fastapi - FastAPI async web framework
/django/django - Django web framework
/pydantic/pydantic - Data validation with type annotations
/sqlalchemy/sqlalchemy - SQL toolkit and ORM
/pytest-dev/pytest - Testing framework
/numpy/numpy - Numerical computing
/pandas-dev/pandas - Data analysis library
/pola-rs/polars - Fast DataFrame library
```
---
## Troubleshooting
Common Issues:
Python Version Check:
```bash
python --version # Should be 3.13+
python -c "import sys; print(sys.version_info)"
```
Async Session Detached Error:
- Solution: Set `expire_on_commit=False` in session config
- Or: Use `await session.refresh(obj)` after commit
pytest asyncio Mode Warning:
```toml
# pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
```
Pydantic v2 Migration:
- `parse_obj()` is now `model_validate()`
- `parse_raw()` is now `model_validate_json()`
- `from_orm()` requires `from_attributes=True` in ConfigDict
---
Last Updated: 2025-12-30
Status: Active (v0.0.1)Related Skills
langsmith-fetch
Debug LangChain and LangGraph agents by fetching execution traces from LangSmith Studio. Use when debugging agent behavior, investigating errors, analyzing tool calls, checking memory operations, or examining agent performance. Automatically fetches recent traces and analyzes execution patterns. Requires langsmith-fetch CLI installed.
langchain-tool-calling
How chat models call tools - includes bind_tools, tool choice strategies, parallel tool calling, and tool message handling
langchain-notes
LangChain 框架学习笔记 - 快速查找概念、代码示例和最佳实践。包含 Core components、Middleware、Advanced usage、Multi-agent patterns、RAG retrieval、Long-term memory 等主题。当用户询问 LangChain、Agent、RAG、向量存储、工具使用、记忆系统时使用此 Skill。
langchain-js
Builds LLM-powered applications with LangChain.js for chat, agents, and RAG. Use when creating AI applications with chains, memory, tools, and retrieval-augmented generation in JavaScript.
langchain-agents
Expert guidance for building LangChain agents with proper tool binding, memory, and configuration. Use when creating agents, configuring models, or setting up tool integrations in LangConfig.
golang-pro
Master Go 1.21+ with modern patterns, advanced concurrency, performance optimization, and production-ready microservices. Expert in the latest Go ecosystem including generics, workspaces, and cutting-edge frameworks. Use PROACTIVELY for Go development, architecture design, or performance optimization.
AILANG Sprint Executor
Execute approved sprint plans with test-driven development, continuous linting, progress tracking, and pause points. Use when user says "execute sprint", "start sprint", or wants to implement an approved sprint plan.
Add prerequisite install script for Python deps (self-contained skill)
No description provided.
python-github-actions
Complete Python GitHub Actions system. PROACTIVELY activate for: (1) uv-based CI workflows (10-100x faster), (2) Matrix testing across Python versions, (3) Dependency caching with setup-uv, (4) Parallel test execution, (5) Reusable workflows, (6) Publishing to PyPI with trusted publishing, (7) Code coverage with codecov, (8) Security scanning. Provides: Workflow templates, caching config, matrix strategies, composite actions. Ensures fast, reliable CI/CD pipelines.
biopython
Comprehensive molecular biology toolkit. Use for sequence manipulation, file parsing (FASTA/GenBank/PDB), phylogenetics, and programmatic NCBI/PubMed access (Bio.Entrez). Best for batch processing, custom bioinformatics pipelines, BLAST automation. For quick lookups use gget; for multi-service integration use bioservices.
python-v3.14
Python 3.14 / FastAPI. Proyecto usa este skill; contenido canónico en .ai-system.
python-uv
Modern Python development with uv package manager. Use when working on Python projects using uv, pytest, FastAPI, or Django. Covers development workflow, testing, and EC2 deployment.