Use f-strings for string formatting (not .format() or %)
Prefer pathlib.Path over os.path
Use dataclasses or pydantic for data models
Type Hints
Always use type hints for function signatures
Use from __future__ import annotations for forward references
Prefer X | Y union syntax (Python 3.10+) over Optional[X]
Error Handling
Use specific exception types, not bare except:
Log exceptions with context: logger.exception("msg", extra={...})
Use custom exception classes for domain errors
Dependencies
Pin dependencies in pyproject.toml with minimum versions
Use virtual environments (venv or uv)
Prefer httpx over requests for async-compatible HTTP
Testing
Use pytest with pytest-asyncio for async tests
Use unittest.mock or pytest-mock for mocking
Structure tests: tests/unit/, tests/integration/
Use fixtures for shared setup
1---2name: python3description: Python Best Practices4---56# Python Best Practices7# For GitHub Copilot89## Code Style1011- Follow PEP 8; use `ruff` for linting and formatting12- Use f-strings for string formatting (not `.format()` or `%`)13- Prefer `pathlib.Path` over `os.path`14- Use `dataclasses` or `pydantic` for data models1516## Type Hints1718- Always use type hints for function signatures19- Use `from __future__ import annotations` for forward references20- Prefer `X | Y` union syntax (Python 3.10+) over `Optional[X]`2122## Error Handling2324- Use specific exception types, not bare `except:`25- Log exceptions with context: `logger.exception("msg", extra={...})`26- Use custom exception classes for domain errors2728## Dependencies2930- Pin dependencies in `pyproject.toml` with minimum versions31- Use virtual environments (`venv` or `uv`)32- Prefer `httpx` over `requests` for async-compatible HTTP3334## Testing3536- Use `pytest` with `pytest-asyncio` for async tests37- Use `unittest.mock` or `pytest-mock` for mocking38- Structure tests: `tests/unit/`, `tests/integration/`39- Use fixtures for shared setup
Run npx skillmds@latest add coin1860/python in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Python Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
coin1860 (@coin1860) published this skill. Their other Agent Skills are listed on their SkillMD profile.