python-best-practices
Skill0 starsChanged 5 months agoMITView on GitHub
Python rules that ruff and ty can't enforce, including FastAPI, SQLAlchemy, and dataframe code. Use when writing, reviewing, refactoring, or debugging Python code.
20 other projects use a version of this.
Adopted by
Most recently taken up by
- baekenough/oh-my-customcodetheir own version, first seen Nov 23, 2026
- The-AIOS/aiostheir own version, first seen Nov 17, 2026
- mahdy-gribkov/arcanatheir own version, first seen Nov 8, 2026
- medy-gribkov/arcanatheir own version, first seen Nov 1, 2026
- jkitchin/knowhowtheir own version, first seen Nov 1, 2026
- OpenxIntelligence/Coding-Agent-Skillstheir own version, first seen Nov 1, 2026
Used with
Projects with it also use react-best-practices, typescript-best-practices and 3 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
OpenAISkillreact-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Also in 3 projects that use this
jaydubya818Skilltypescript-best-practices
Use when TypeScript needs focused type-safety, API, or error-handling guidance.
Also in 3 projects that use this
BlockSkillfrontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Also in 4 projects that use this
SentrySkillskill-creator
Create new agent skills following the Agent Skills specification. Use when asked to "create a skill", "add a new skill", "write a skill", "make a skill", "build a skill", or scaffold a new skill with SKILL.md. Guides through requirements, writing, registration, and verification.
Also in 4 projects that use this
GoogleSkilltdd
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
Also in 3 projects that use this
Other versions20 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 20
- The-AIOS/aios★ 130same name
- baekenough/oh-my-customcode★ 47same name
- jkitchin/knowhow★ 45same name
- jefflester/claude-skills-supercharged★ 44same name
- excatt/superclaude-plusplus★ 14same name
- arnabdeypolimi/claude_code_setup★ 4same name
- I-Onlabs/claude-code-skills★ 4same name
- OpenxIntelligence/Coding-Agent-Skills★ 4same name
- Sanskar015/claude-skills-supercharged★ 3same name
- amirrezaalasti/codescribe★ 2same name
10 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- commitSkill
- deslopSkill
- draft-prSkill
- go-best-practicesSkill
- hardenSkill
- rust-best-practicesSkill
- status-updateSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. 0 are common, 5 are distinctive, and 14 are very specific to this project.
0
Common
Most of the 16 edited versions we read keep these.
5
Distinctive
This author's own choices. Worth a look.
14
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
Read the matching reference before you change code that uses:
- Very specific: line 21
Run Python and its tools with uv run, and add dependencies with uv add.
- Distinctive: line 22
Write code that passes the asset config even when the repo's config is weaker.
- Very specific: line 30
Don't re-check what types or models already guarantee: no redundant isinstance (narrowing a union is fine), no hasattr or getattr(obj, …
- Very specific: line 37
Use Literal or StrEnum for fixed string sets, and an enum instead of mutually exclusive bool flags.
- Very specific: line 39
Don't add an ABC or Protocol for a single implementation.
- Very specific: line 44
Use Pydantic v2 (model_validate, model_dump, field_validator, ConfigDict).
- Very specific: line 47
Use Model.model_validate_json(raw) instead of json.loads + validation, and TypeAdapter(list[Item]) instead of a wrapper model (validate …
- Very specific: line 50
Use model_validate(obj, from_attributes=True) instead of hand-written to_dict / from_row mappers for matching fields.
- Distinctive: line 53
Use plain dataclasses for internal values never parsed from outside.
- Very specific: line 59
Never turn unexpected failures into values (except ...: return None, {}, [], or False).
- Very specific: line 61
Don't pre-check what the callee checks (like path.exists() before open()).
- Very specific: line 69
Prefer module-level functions over static-only classes or stateless single-method classes.
- Distinctive: line 72
Keep no state in module globals, and build clients/connections at startup rather than import time.
- Very specific: line 77
Never block the event loop in async def.
- Very specific: line 81
Start tasks in asyncio.TaskGroup, use asyncio.timeout() for deadlines, and bound fan-out with a Semaphore or worker pool instead of …
- Very specific: line 86
Test through public entry points (TestClient / ASGITransport, CLI, service functions) against a real test database (in-memory SQLite or …
- Very specific: line 89
Avoid bare MagicMock() (it hides renames).
- Distinctive: line 90
Don't test the framework (e.g., Pydantic rejecting a missing field).
“Common” is measured: kept by at least 6 in 10 of the 16 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python best practices
This file assumes uv and repo hooks that run ruff check,
ruff format, ty check, and pytest. It lists only what those tools don't catch. If
the repo has no Python hooks, suggest that the user adopt assets/pre-commit-config.yaml
and the settings in assets/pyproject.toml.
Read the matching reference before you change code that uses:
- FastAPI:
references/fastapi.md - SQLAlchemy:
references/sqlalchemy.md - pandas, Polars, PyArrow, or large files and query results:
references/dataframes.md
Tools
- Run Python and its tools with
uv run, and add dependencies withuv add. - Write code that passes the asset config even when the repo's config is weaker.
- Fix a lint instead of silencing it. If a rule is wrong for one line, use
# noqa: CODEor# ty: ignore[rule]with a reason. Never silence a type error withcast,Any, or# type: ignore; fix the model or signature, or wrap an untyped library once in a typed function.
Trust the types
- Don't re-check what types or models already guarantee: no redundant
isinstance(narrowing a union is fine), nohasattrorgetattr(obj, "field", default)on known classes, nois not Noneon non-optional values, and no.get(key, default)on validated data. If the type is wrong, fix the type. - Make a parameter optional only when a real caller passes
Noneor omits it. - Parse untrusted data once at the boundary (requests, files, env, queues, third-party
responses) and pass typed models inward, never
dict[str, Any]or raw JSON. - Use
LiteralorStrEnumfor fixed string sets, and an enum instead of mutually exclusive bool flags. - Don't add an ABC or
Protocolfor a single implementation. Add one when a second implementation or test fake needs it, in the consuming module.
Pydantic
- Use Pydantic v2 (
model_validate,model_dump,field_validator,ConfigDict). - Let the model parse and convert (dates,
UUID,Decimal, enums,Field/Annotatedconstraints) instead of pre-converting strings or validating after construction. - Use
Model.model_validate_json(raw)instead ofjson.loads+ validation, andTypeAdapter(list[Item])instead of a wrapper model (validate item by item when bad items must be skipped or reported). - Use
model_validate(obj, from_attributes=True)instead of hand-writtento_dict/from_rowmappers for matching fields. - Load settings once with
pydantic-settingsand pass them in; avoid scatteredos.getenv. - Use plain dataclasses for internal values never parsed from outside.
Errors
- Catch only what you can handle around the smallest failing block; let the rest reach the boundary to be logged once.
- Never turn unexpected failures into values (
except ...: return None,{},[], orFalse). ReturningNonefor an expected "not found" is fine. - Don't pre-check what the callee checks (like
path.exists()beforeopen()). - Raise a small set of domain exceptions from business logic and map them to HTTP or exit codes at the boundary.
- Broad
except Exceptionbelongs only in a background loop that must survive one bad item (log withlogger.exceptionand continue).
Structure
- Prefer module-level functions over static-only classes or stateless single-method
classes. Put code in its owning module, not
utils.pyorhelpers.py, and delete pass-through wrappers. - Keep no state in module globals, and build clients/connections at startup rather than import time.
Async
- Never block the event loop in
async def. Ruff catchesrequests,open, andtime.sleep, but not sync DB sessions, sync SDK clients, or CPU work; use async clients,asyncio.to_thread, or plaindefFastAPI routes/dependencies (a sync helper called fromasync defstill blocks). - Start tasks in
asyncio.TaskGroup, useasyncio.timeout()for deadlines, and bound fan-out with aSemaphoreor worker pool instead of unboundedgather.
Tests
- Test through public entry points (
TestClient/ASGITransport, CLI, service functions) against a real test database (in-memory SQLite or test Postgres), mocking only external services (e.g.,MockTransport). - Avoid bare
MagicMock()(it hides renames); use a fake orcreate_autospec. - Don't test the framework (e.g., Pydantic rejecting a missing field).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

