python-best-practices
Skill0 starsChanged 4 months agoMITView on GitHub
Pythonic code with modern type hints, dataclasses, async patterns, packaging, and testing. Use when writing, reviewing, or refactoring Python — picking type-hint syntax, choosing dataclasses vs Pydantic, structuring async code, laying out a project/pyproject.toml, or setting up pytest.
- Installs packages
19 other projects use a version of this.
Adopted by
Most recently taken up by
- mahdy-gribkov/arcanatheir own version, first seen Nov 8, 2026
- The-AIOS/aiostheir own version, first seen Nov 3, 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
- fullerzz/agent-skillstheir own version, first seen Oct 25, 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 versions19 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 19
- The-AIOS/aios★ 105same name
- jefflester/claude-skills-supercharged★ 43same name
- baekenough/oh-my-customcode★ 42same name
- jkitchin/knowhow★ 42same 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
9 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 repository4 other files it gives its agents.
- git-advancedSkill
- security-hardeningSkill
- tdd-masterySkill
- testing-strategiesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
19 rules. 0 are common, 1 is distinctive, and 18 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Always type function signatures.
- Very specific: line 13
Use X | None union syntax (3.10+) instead of Optional[X].
- Very specific: line 14
Use the type alias and def fT type-parameter syntax (3.12+) for generics.
- Very specific: line 15
Use TypedDict for structured dicts.
- Very specific: line 16
Run mypy --strict or pyright in CI.
- Very specific: line 28
Use httpx instead of requests for async HTTP.
- Very specific: line 29
Use asyncio.gather for concurrent tasks.
- Very specific: line 30
Never call blocking I/O in async functions — wrap legacy blocking code in asyncio.to_thread.
- Very specific: line 31
Use async with for resource management (connections, sessions, clients).
- Very specific: line 36
Use a src/ layout (src/my_project/...) to prevent accidental imports from the project root.
- Very specific: line 42
Put all tool configuration in pyproject.toml (build, deps, ruff, mypy, pytest).
- Very specific: line 43
Use Ruff instead of flake8 + isort + black — one tool, 10-100x faster.
- Distinctive: line 49
Always use a virtual environment.
- Very specific: line 50
Prefer uv (uv venv + uv pip install -e ".[dev]") for speed.
- Very specific: line 56
Put shared fixtures in conftest.py.
- Very specific: line 63
Prefer unpacking (first, *rest = items), comprehensions over map/filter, and context managers for cleanup.
- Very specific: line 64
Use the walrus operator (:=) for assign-and-test, and structural pattern matching (match/case, 3.10+) for dispatch.
- Very specific: line 69
Never use bare except:. Catch the most specific exception possible.
- Very specific: line 71
Use logger.exception() to capture tracebacks when handling unexpected errors.
“Common” is measured: kept by at least 6 in 10 of the 15 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
Worked code examples for every section live in reference.md (sibling file). This SKILL.md carries the rules; open reference.md when you need a concrete snippet to copy.
Type Hints (3.12+ Syntax)
- Always type function signatures. Use built-in generics (
list[str],dict[str, int]) — notyping.List/typing.Dict. - Use
X | Noneunion syntax (3.10+) instead ofOptional[X]. - Use the
typealias anddef f[T](...)type-parameter syntax (3.12+) for generics. - Use
TypedDictfor structured dicts. - Run
mypy --strictorpyrightin CI. Use# type: ignoresparingly and only with a justification. - Examples: see
reference.md§ Type Hints.
Dataclasses vs Pydantic
- Dataclasses for domain models and internal structs (no validation needed). Use
frozen=Truefor immutable value objects,slots=Truefor memory efficiency,field(default_factory=...)for mutable defaults. - Pydantic for API boundaries, config files, and external data parsing (validation required). Use
Field(...)constraints and@field_validatorfor custom checks; setmodel_config = {"strict": True}. - Rule of thumb: internal/trusted data → dataclass; external/untrusted input → Pydantic.
- Examples: see
reference.md§ Dataclasses vs Pydantic.
Async Patterns
- Use
httpxinstead ofrequestsfor async HTTP. - Use
asyncio.gatherfor concurrent tasks;asyncio.Semaphoreto bound concurrency / rate-limit. - Never call blocking I/O in async functions — wrap legacy blocking code in
asyncio.to_thread. - Use
async withfor resource management (connections, sessions, clients). - Examples: see
reference.md§ Async Patterns.
Project Structure
- Use a
src/layout (src/my_project/...) to prevent accidental imports from the project root. - Mirror packages under
tests/with aconftest.pyfor shared fixtures. - Full tree: see
reference.md§ Project Structure.
pyproject.toml
- Put all tool configuration in
pyproject.toml(build, deps, ruff, mypy, pytest). - Use Ruff instead of flake8 + isort + black — one tool, 10-100x faster. Recommended lint select:
["E", "F", "I", "N", "UP", "B", "SIM", "RUF"]. - Set
requires-python = ">=3.12",[tool.mypy] strict = true, andasyncio_mode = "auto"for pytest. - Full template: see
reference.md§ pyproject.toml.
Virtual Environments
- Always use a virtual environment. Never install packages globally.
- Prefer
uv(uv venv+uv pip install -e ".[dev]") for speed; standardvenvworks too. - Pin exact versions in a lockfile (
uv.lockor apip freeze-generatedrequirements.txt). - Commands: see
reference.md§ Virtual Environments.
Testing with pytest
- Put shared fixtures in
conftest.py. Usepytest.mark.parametrizefor test variations and thetmp_pathfixture for filesystem tests. - Name tests by behavior (
test_create_user_rejects_duplicate_email), assert on outcomes, and assert error cases withpytest.raises. - Mock async dependencies with
AsyncMock(spec=...); assert call args. - Examples: see
reference.md§ Testing with pytest.
Pythonic Idioms
- Prefer unpacking (
first, *rest = items), comprehensions overmap/filter, and context managers for cleanup. - Use the walrus operator (
:=) for assign-and-test, and structural pattern matching (match/case, 3.10+) for dispatch. - Examples: see
reference.md§ Pythonic Idioms.
Error Handling
- Never use bare
except:. Catch the most specific exception possible. - Define a custom exception hierarchy for the application (e.g.
AppError→NotFoundError). - Use
logger.exception()to capture tracebacks when handling unexpected errors. - Examples: see
reference.md§ Error Handling.
Checklist
- Every function signature is typed;
mypy --strict/pyrightclean. - Built-in generics +
X | Noneunions; notyping.List/Optional. - Dataclasses for internal models, Pydantic at external boundaries.
- Async uses
httpx,gather, bounded concurrency; no blocking I/O in coroutines. src/layout; all config inpyproject.toml; Ruff configured.- Virtual env in use; dependencies pinned in a lockfile.
- Tests assert behavior + error cases; fixtures in
conftest.py. - No bare
except; custom exception hierarchy;logger.exception()for tracebacks.
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.

