agentleFS
amirrezaalastiamirrezaalasti/codescribe/skills/coding/python-best-practices/SKILL.md

python-best-practices

Skill2 starsChanged 4 months agoMITView on GitHub

Write idiomatic, typed Python with clear packaging, ruff/pytest defaults, and practical error handling. Use when writing or refactoring Python code, modules, scripts, packages, or APIs, or when the user mentions Python style, typing, or project layout.

15 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use frontend-design and skill-creator.

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.
  • VercelSkill

    frontend-design

    Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

    Also in 4 projects that use this

  • MicrosoftSkill

    skill-creator

    Guide for creating effective GitHub Copilot skills (.github/skills/) in this repository. Use when creating a new skill, updating an existing skill, or when asked about skill structure, format, or best practices for the vscode-documentdb project.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Match the repo first: Follow existing layout, tooling, and import style before introducing new conventions.

    line 29
  2. Very specific:

    Use pathlib and context managers: Prefer pathlib.Path over string paths.

    line 33
  3. Distinctive:

    Dependencies: Prefer the stdlib. Add third-party libs only when they clearly reduce complexity.

    line 34
  4. Distinctive:

    Do not over-abstract: Wait for a second real use before extracting shared helpers or base classes.

    line 35
  5. Very specific:

    Tag unfinished or risky work: Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, …).

    line 36

“Common” is measured: kept by at least 6 in 10 of the 13 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Python Best Practices

Defaults

ConcernDefault
Style / lintRuff (format + lint)
TypesType hints on public APIs; mypy or pyright in CI when the project already uses them
Testspytest (see python-testing skill)
Package layoutsrc/<package>/ for libraries; flat modules OK for small scripts
Python versionMatch requires-python / .python-version; prefer 3.11+

Instructions

  1. Match the repo first. Follow existing layout, tooling, and import style before introducing new conventions.
  2. Prefer clarity over cleverness. Explicit names, small functions, early returns. Avoid deep nesting and clever one-liners.
  3. Type public surfaces. Annotate function parameters and return types for APIs, shared helpers, and data models. Use TypedDict / dataclasses / Pydantic when the project already does.
  4. Handle errors at the boundary. Catch specific exceptions; convert to domain errors or HTTP responses at edges. Do not bare except: or swallow errors silently.
  5. Use pathlib and context managers. Prefer pathlib.Path over string paths; always close resources with with.
  6. Dependencies. Prefer the stdlib. Add third-party libs only when they clearly reduce complexity; pin in the project's lockfile/tooling.
  7. Do not over-abstract. Wait for a second real use before extracting shared helpers or base classes.
  8. Tag unfinished or risky work. Use the global tagged-code-comments convention (🔴 FIXME(P0):, 🟠 TODO(P1):, …). Never leave silent stubs. End with an Open follow-ups table so the developer must check P0/P1 before ship.

Project layout (libraries)

src/mypkg/
  __init__.py
  api.py
  models.py
tests/
  test_api.py
pyproject.toml

Anti-patterns

  • Untyped public APIs in typed codebases
  • Mutable default arguments (def f(x=[]))
  • Broad except Exception without re-raise or logging
  • Circular imports fixed by hacks instead of restructuring
  • Mixing business logic into CLI/__main__ without a callable core

Checklist

See references/checklist.md.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.