agentleFS
jenrehjenreh/appkit/.claude/skills/python-coding/SKILL.md

python-coding

Skill4 starsChanged 5 months agoMITView on GitHub

Enforces Python 3.14 code style, logging rules, type annotations, design patterns, testing strategy, and clean code principles for the appkit project. Apply automatically whenever writing, reviewing, or refactoring Python code, creating new modules, or adding tests.

  • Reads credentials

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 4 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Python 3.14: only; deps via uv; line length 88 chars (Ruff/Black).

    line 17
  2. Very specific:

    Never use print or printf.

    line 37
  3. Very specific:

    Do not mix Literal[...] with str — pick one.

    line 48
  4. Distinctive:

    Remove unused imports immediately (F401).

    line 49
  5. Very specific:

    Remove unused args or prefix with _ (ARG001).

    line 50
  6. Distinctive:

    No Python file may exceed 1000 lines.

    line 68
  7. Very specific:

    No credentials in code/history.

    line 86
  8. Very specific:

    Use appkit_commons.database.session_manager.get_session_manager().session() for DB access outside Reflex handlers (not rx.session()).

    line 89
  9. Very specific:

    Do NOT use --autogenerate for Alembic migrations.

    line 104
  10. Distinctive:

    Read the docs first: If something isn't working, use Context7 or DuckDuckGo to verify the correct API — never guess or change code blindly.

    line 110
  11. Very specific:

    Write or adjust tests first (tests/test_*.py).

    line 111

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “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

Writing Python Code

Quick reference

  • Python 3.14 only; deps via uv; line length 88 chars (Ruff/Black).
  • No f-strings in logger calls — use log.info("x: %s", val).
  • Type annotations on every function and method.
  • Files ≤ 1000 lines — refactor via Extract Class, Mixins, Strategy, etc.
  • Coverage ≥ 80% for non-Reflex classes and Reflex State classes.
  • Task runner: task format, task lint, task test (not make).

Code style

Logging

import logging

log = logging.getLogger(__name__)

log.info("Loaded items: %d", count)          # ✅ parameterized
# log.info(f"Loaded items: {count}")         # ❌ f-string

Never use print or printf. Log levels: debug → internal state (default), info → milestones, warning → recoverable, error → serious.

Type hints

def process(data: dict[str, Any], count: int = 0) -> list[str]: ...

async def handler(value: str) -> AsyncGenerator[Any, Any]:
    yield
  • Do not mix Literal[...] with str — pick one.
  • Remove unused imports immediately (F401).
  • Remove unused args or prefix with _ (ARG001).

Imports & formatting

  • Ruff handles lint + format; run task format before committing.
  • Break long calls/strings to fit 88 chars.

Ruff rules to watch (project-specific)

CodeRuleFix
UP031No %-formatting outside logger calls — use f-stringsReplace "x %s" % val with f"x {val}"
I001Import orderAuto-fixed by task format
PLC0415No local imports inside functions or test methodsMove to top of file
B017pytest.raises(Exception) too broadUse specific exception, e.g. pytest.raises(ValidationError)

File size rule

No Python file may exceed 1000 lines. When approaching the limit, apply clean code refactoring strategies.

Design patterns & refactoring strategies: See skill python-clean-code.

Testing

Coverage target: ≥ 80% for services, repositories, models, utilities, and Reflex State classes. UI component rendering is best-effort.

task test                           # full suite with coverage
uv run pytest tests -k assistant    # targeted
uv run pytest tests -x              # stop on first failure

Test patterns, fixtures, Reflex State testing: See references/testing.md.

Security & config

  • No credentials in code/history; use .env locally, Key Vault in prod.
  • Access Pydantic SecretStr via .get_secret_value().
  • Parameterized logs; avoid sensitive values.
  • Use appkit_commons.database.session_manager.get_session_manager().session() for DB access outside Reflex handlers (not rx.session()).

Database operations

from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession

async def get_user(session: AsyncSession, user_id: int) -> User | None:
    result = await session.execute(
        select(User).where(User.id == user_id)
    )
    return result.scalar_one_or_none()
  • Do NOT use --autogenerate for Alembic migrations; write them manually.
  • BaseRepository methods must not commit; transaction boundaries are owned by the caller.

Workflow

  1. task sync to install/update deps.
  2. Read the docs first. If something isn't working, use Context7 or DuckDuckGo to verify the correct API — never guess or change code blindly.
  3. Write or adjust tests first (tests/test_*.py).
  4. Implement minimal diff.
  5. task format && task lint && task test.
  6. Conventional Commits: feat:, fix:, refactor:, test:, chore:.

Pre-commit checklist

  • Tests pass (task test)
  • Coverage ≥ 80%
  • Lint/format clean (task format && task lint)
  • No file exceeds 1000 lines
  • No secrets in code
  • Logging uses parameterized formatting
  • All functions have type annotations

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.