Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add skills/kunanonj/ai-skills-hub/python-best-practicesnpx skills add KunanonJ/ai-skills-hub --skill python-best-practicesgit clone --depth 1 https://github.com/KunanonJ/ai-skills-hubWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/kunanonj/ai-skills-hub/python-best-practices)<a href="https://agentmods.dev/skills/kunanonj/ai-skills-hub/python-best-practices"><img src="https://agentmods.dev/badge/skills/kunanonj/ai-skills-hub/python-best-practices.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00050 | $0.00648 |
| Opus 5 | $0.00025 | $0.00324 |
| Sonnet 5 | $0.00010 | $0.00130 |
| Haiku 4.5 | $0.00005 | $0.00065 |
Grade A, and why
python-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 61 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Python + FastAPI Best Practices — Quick Reference
Layered Architecture
Router → Service → Repository → Database. Each layer only calls the one below it.
See code-patterns.md for full project structure and layer examples.
Pydantic v2
Separate Create/Update/Response schemas. Use ConfigDict(from_attributes=True) for ORM integration. Use str | None syntax (not Optional[str]).
See code-patterns.md for schema examples.
Async Patterns
async def for I/O routes, plain def for CPU-bound. Use lifespan context manager (not on_event). Use httpx.AsyncClient for external HTTP calls.
See code-patterns.md for async examples.
Soft Delete
Use a SoftDeleteMixin on SQLAlchemy models. Filter where(Model.deleted_at.is_(None)) in all queries.
See code-patterns.md for mixin and repository patterns.
Configuration
Use pydantic-settings for all config. Never hardcode secrets, URLs, or magic numbers.
See code-patterns.md for Settings class pattern.
Pagination
Use a generic PaginatedResponse[T] for all list endpoints. Always return total, page, limit, has_more.
See code-patterns.md for the pattern.
Gotchas
-
async defvsdefmatters for performance. Anasync defroute that calls blocking code (liketime.sleep()or sync DB drivers) blocks the entire event loop. Use plaindeffor CPU-bound work — FastAPI runs it in a threadpool. Useasync defonly when youawaitsomething. -
datetime.utcnow()is deprecated since Python 3.12. Usedatetime.now(UTC)instead. The old function returns a naive datetime (no timezone), which causes comparison bugs. The new one returns timezone-aware UTC. -
Mutable default arguments in Pydantic look safe but have a catch.
tags: list[str] = []works in Pydantic (it copies the default). Buttags: list[str] = Field(default_factory=list)is explicit and safer for nested models. For simple fields, either works. For complex nested defaults, always usedefault_factory.
What ships with it
1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 61 lines · 50 tokens per session scan A 74e25c6954e3
python-best-practices is a skill published in the GitHub repository KunanonJ/ai-skills-hub (4 stars, last pushed 1mo ago), licensed MIT. It adds 50 tokens to every session and 648 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other skills, from other repositories
docker-py
Provides patterns for programmatic Docker container management using the Docker SDK for Python and aiodocker. USE WHEN the user asks to "manage Docker containers from Python", "create containers programmatically", "stream container logs", "execute commands in a running container", "build images with docker-py"…
pydantic-ai
Teaches PydanticAI agent development with tool decorators, RunContext dependency injection, streaming, and VercelAIAdapter. USE WHEN the user asks to "build a PydanticAI agent", "add tools to an agent", "stream responses with PydanticAI", "test a PydanticAI agent", "connect PydanticAI to Svelte", "configure model…
claude-api
Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.
agentic-development
Build AI agents with Pydantic AI (Python) and Claude SDK (Node.js).
aws-dynamodb
AWS DynamoDB single-table design, GSI patterns, SDK v3 TypeScript/Python.
supabase-python
FastAPI with Supabase and SQLAlchemy/SQLModel.