Agent skill
lang-python
This skill should be used when the user asks to "write Python code", "debug a Python script", "set up a Python project", "explain Python concepts", or mentions Python-specific libraries like FastAPI, Django, or Pandas.
Install this agent skill to your Project
npx add-skill https://github.com/joncrangle/.dotfiles/tree/main/dot_config/opencode/skills/lang-python
SKILL.md
<skill_doc> <trigger_keywords>
Trigger Keywords
Activate this skill when the user mentions any of:
File Extensions: .py, pyproject.toml, requirements.txt, pytest.ini, setup.py
Python Core: Python, python3, pip, poetry, uv, asyncio, async/await, type hints, dataclass, Protocol, TypeVar, ParamSpec, match/case, pattern matching
Web Frameworks: FastAPI, Django, Flask, Starlette, ASGI, WSGI, Depends, APIRouter, @app.get, @app.post
Validation: Pydantic, BaseModel, model_validate, ConfigDict, Field, validator, model_validator
ORM/Database: SQLAlchemy, AsyncSession, create_async_engine, Alembic, migrations, ORM, query builder
Testing: pytest, pytest-asyncio, @pytest.fixture, @pytest.mark.parametrize, mock, conftest.py, coverage
Data Science: numpy, pandas, polars, DataFrame, ndarray, data pipeline, ETL
Package Management: uv (preferred), poetry, pip install, virtual environment, venv </trigger_keywords>
⛔ Forbidden Patterns
- NO Mutable Default Arguments: Never use
def foo(x=[]). UseNoneas default and initialize inside the function. - NO Sync I/O in Async Functions: Blocking operations (like
requests.getortime.sleep) insideasync defkill performance. Usehttpxorasyncio.sleep. - NO Wildcard Imports: Avoid
from module import *. Explicit imports prevent namespace pollution and make code readable. - NO Bare Excepts: Never use
except:. Always catch specific exceptions (e.g.,except ValueError:). - NO Pip/Poetry (unless forced): ALWAYS prefer
uvfor package management. It is significantly faster and more reliable. Only usepiporpoetryif explicitly requested or ifuvis unavailable.
🤖 Agent Tool Strategy
- Discovery: Check for
justfilefirst. If it exists, usejust -l. Readpyproject.tomlorrequirements.txt. - Package Management: ALWAYS use
uvfor all package operations (uv add,uv pip install,uv venv). Only fallback topip/poetryifuvfails. - Virtual Environment:
uv venvcreates environments instantly. Use it. - Code Analysis: Use
search_filesto find definitions. Avoidgrepif possible. - Testing: Use
pytestfor running tests. Preferpytestoverunittest. - Linting/Formatting: Respect
ruff.tomlorpyproject.toml[tool.ruff] settings.
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:
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:
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:
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)
See patterns.md for the detailed implementation guide covering:
- Python 3.13 New Features (JIT, GIL-Free)
- FastAPI 0.115+ Patterns (Async DI, Class Dependencies)
- Django 5.2 LTS Features
- Pydantic v2.9 Deep Patterns
- SQLAlchemy 2.0 Async Patterns
- pytest Advanced Patterns
- Type Hints Modern Patterns
- Package Management (Poetry, uv)
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:
- patterns.md - Implementation patterns (FastAPI, Pydantic, SQLAlchemy)
- reference.md - Complete reference documentation
- 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:
python --version # Should be 3.13+
python -c "import sys; print(sys.version_info)"
Async Session Detached Error:
- Solution: Set
expire_on_commit=Falsein session config - Or: Use
await session.refresh(obj)after commit
pytest asyncio Mode Warning:
# pyproject.toml
[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Pydantic v2 Migration:
parse_obj()is nowmodel_validate()parse_raw()is nowmodel_validate_json()from_orm()requiresfrom_attributes=Truein ConfigDict </skill_doc>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
lang-javascript
This skill should be used when the user asks to "write JavaScript", "debug a Node.js/Bun app", "create a Hono server", "configure Biome", "run tests with bun test", or mentions .js/.mjs files. Covers ES2024+, Bun, and Hono patterns.
opentui
Comprehensive OpenTUI skill for building terminal user interfaces. Covers the core imperative API, React reconciler, and Solid reconciler. Use for any TUI development task including components, layout, keyboard handling, animations, and testing.
vitest
Specialist in Vitest, a blazing fast unit test framework powered by Vite. Focuses on Jest compatibility, in-source testing, and native ESM support.
PreventionPatterns
Known bug patterns and their fixes to prevent regression.
lang-typescript
This skill should be used when the user asks to "write TypeScript", "debug TypeScript", "create a SolidJS component", "configure TanStack Start", "validate data with Valibot", or mentions .ts/.tsx files. Covers TypeScript 5.9+, SolidJS, and TanStack patterns.
just-cli
This skill should be used when the user asks to "create a justfile", "write just recipes", "configure just settings", "add just modules", "use just attributes", "set up task automation", mentions justfile, just command runner, or task automation with just.
Didn't find tool you were looking for?