python-best-practices
Skill1 starsChanged 6 months agoMITView on GitHub
Expert guidance for Python best practices: PEP 8, type hints, testing, error handling, async patterns, modern tooling. Use when writing or refactoring Python code.
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 1 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
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 repository41 other files it gives its agents.
- AGENTS.mdAGENTS.md
- academic-evaluationSkill
- academic-writingSkill
- agent-orchestrationSkill
- agents-md-writerSkill
- algorithmic-artSkill
- brand-guidelinesSkill
- codebase-architectureSkill
- code-reviewSkill
- commit-workflowSkill
- context-checkpointSkill
- doc-coauthoringSkill
- docxSkill
- etl-runnerSkill
- eval-runnerSkill
- feature-devSkill
- frontend-designSkill
- hpc-deucalionSkill
- internal-commsSkill
- langchainSkill
- langfuseSkill
- langgraphSkill
- llm-observability-stackSkill
- mcp-builderSkill
- neo4j-verifySkill
- pdfSkill
- pptxSkill
- project-conventionsSkill
- react-namingSkill
- security-hooksSkill
- service-verifySkill
- skill-creatorSkill
- skill-inspectorSkill
- slack-gif-creatorSkill
- sprint-contractSkill
- theme-factorySkill
- uml-modelingSkill
- webapp-testingSkill
- web-artifacts-builderSkill
- web-debugSkill
- xlsxSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
23 rules. 0 are common, 12 are distinctive, and 11 are very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
12
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Write idiomatic, maintainable, and production-ready Python code following modern standards and type-safe patterns.
- Distinctive: line 12
When writing or reviewing Python code, follow this checklist:
- Very specific: line 14
Structure: Use src/ layout with pyproject.toml (PEP 621)
- Distinctive: line 15
Style: Follow PEP 8 -- Ruff handles formatting automatically
- Distinctive: line 16
Types: Add type hints to all function signatures (PEP 484)
- Distinctive: line 17
Tests: Write tests with pytest before implementation (TDD)
- Distinctive: line 18
Errors: Use specific exceptions and context managers
- Very specific: line 19
Tools: Run ruff check, mypy, and pytest before committing
- Very specific: line 29
No wildcard imports (from module import *)
- Distinctive: line 33
All function signatures must have type hints
- Very specific: line 34
Use list[X] not List[X] (Python 3.9+)
- Very specific: line 36
Use TypedDict for structured dicts, dataclasses or Pydantic for data models
- Very specific: line 37
Run mypy --strict to catch type errors
- Distinctive: line 41
Write self-documenting code: descriptive names over comments
- Very specific: line 43
Prefer explicit over implicit -- no magic values, no bare except:
- Very specific: line 47
Use specific exception classes, never bare except:
- Distinctive: line 54
Write tests first, then implement, then refactor
- Distinctive: line 55
Use pytest with descriptive test function names
- Very specific: line 78
Mutable default arguments: Use None and check inside the function
- Very specific: line 79
Bare except clauses: Always specify Exception or a concrete type
- Distinctive: line 81
Over-abstracting: Don't add interfaces/ABCs until you have at least two implementations
- Distinctive: line 82
Mixing sync and async: Don't call async code from sync without an event loop
- Very specific: line 83
Neglecting
__pycache__: Add to .gitignore
“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
Write idiomatic, maintainable, and production-ready Python code following modern standards and type-safe patterns.
Quick Start
When writing or reviewing Python code, follow this checklist:
- Structure: Use
src/layout withpyproject.toml(PEP 621) - Style: Follow PEP 8 -- Ruff handles formatting automatically
- Types: Add type hints to all function signatures (PEP 484)
- Tests: Write tests with pytest before implementation (TDD)
- Errors: Use specific exceptions and context managers
- Tools: Run
ruff check,mypy, andpytestbefore committing
Core Principles
1. PEP 8 -- Style Guide
- 4 spaces per indentation level (never tabs)
- 88 char line length (Ruff default), 72 for docstrings
snake_casefor functions/variables,PascalCasefor classes,UPPER_CASEfor constants- Imports: stdlib, third-party, local (each group separated by blank line)
- No wildcard imports (
from module import *)
2. Type Hints (PEP 484 / 585 / 604)
- All function signatures must have type hints
- Use
list[X]notList[X](Python 3.9+) - Use
X | NonenotOptional[X](Python 3.10+) - Use
TypedDictfor structured dicts,dataclassesorPydanticfor data models - Run
mypy --strictto catch type errors
3. Readability and Clarity
- Write self-documenting code: descriptive names over comments
- Docstrings on all public functions (Args, Returns, Raises)
- Prefer explicit over implicit -- no magic values, no bare
except:
4. Error Handling
- Use specific exception classes, never bare
except: - Context managers for resource management (
withblocks) - Log exceptions with
logging.exception()orlogger.exception() - Define custom exception hierarchies for domain errors
5. Testing (TDD)
- Write tests first, then implement, then refactor
- Use pytest with descriptive test function names
- Parametrize tests with
@pytest.mark.parametrize - One assertion per test where possible
- Aim for mutation testing coverage (see references/TESTING.md)
6. Modern Tooling
- uv for package management (replaces pip + venv + pip-tools)
- Ruff for linting + formatting (replaces flake8 + isort + black)
- MyPy --strict for type checking
- pytest for testing
- pre-commit / prek for git hooks
References
| File | When to read |
references/TOOLING.md | When setting up a new Python project. Complete tool configuration (pyproject.toml, Ruff, MyPy, pytest, uv). |
references/PATTERNS.md | When writing Python code. Patterns for dataclasses, Pydantic, async/await, context managers, logging, CLI. |
references/TESTING.md | When writing or improving tests. pytest, Hypothesis, mocking, async testing, mutation testing. |
Common Pitfalls
- Mutable default arguments: Use
Noneand check inside the function - Bare except clauses: Always specify
Exceptionor a concrete type - Ignoring type hints:
Anyshould be a last resort, not the default - Over-abstracting: Don't add interfaces/ABCs until you have at least two implementations
- Mixing sync and async: Don't call async code from sync without an event loop
- Neglecting
__pycache__: Add to.gitignore
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.

