agentleFS
CODE-SAURABHCODE-SAURABH/OpenSkills/python-development/SKILL.md

python-development

Skill2 starsChanged 4 months agoMITView on GitHub

Build, review, debug, and maintain production Python applications, services, libraries, CLIs, and automation. Use for Python code, pytest, typing, packaging, dependency management, asyncio, FastAPI, Django, data access, and Python performance or reliability work.

13 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use javascript-typescript, golang-development and 4 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.
  • pepebot-spaceSkill

    javascript-typescript

    JavaScript and TypeScript development with ES6+, Node.js, React, and modern web frameworks. Use for frontend, backend, or full-stack JavaScript/TypeScript projects.

    Also in 4 projects that use this

  • kinhluanSkill

    golang-development

    Implement, review, debug, or modernize Go code and modules with idiomatic APIs, concurrency, error handling, testing, profiling, and tooling. Use for Go services, libraries, CLIs, goroutine/channel issues, module management, or performance work.

    Also in 3 projects that use this

  • carloss765Skill

    rust-development

    Comprehensive guidelines for writing safe, concurrent, and performant Rust code. Use when working with .rs files, building systems software, or high-performance applications.

    Also in 3 projects that use this

  • harrissohail6Skill

    database-design

    Database schema design and SQL best practices. Use when designing tables, writing queries, or optimizing database performance.

    Also in 3 projects that use this

  • NVIDIASkill

    github

    Interact with GitHub using the gh CLI restricted to REST API only (no GraphQL). Use when the user wants to work with GitHub issues, pull requests, repos, releases, or Actions — especially in sandboxed environments where the GraphQL endpoint may be blocked. Trigger keywords - github, gh, pull request, PR, github issue, github actions, workflow, release, gh api.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

29 rules. 0 are common, 19 are distinctive, and 10 are very specific to this project.

  • 0

    Common

    Most of the 10 edited versions we read keep these.

  • 19

    Distinctive

    This author's own choices. Worth a look.

  • 10

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Implement the smallest cohesive change: Use modules by responsibility, dependency injection for I/O boundaries, and explicit exception …

    line 14
  2. Distinctive:

    Test and verify: Test public behavior, failure paths, and regressions.

    line 15
  3. Distinctive:

    Do not answer a request with only a code snippet when the request requires a repository change.

    line 28
  4. Distinctive:

    Before changing a Python project, inspect rather than guess:

    line 32
  5. Very specific:

    If the repository already uses uv, Poetry, pip-tools, Hatch, Pydantic, Django, FastAPI, SQLAlchemy, or another tool, follow its local …

    line 40
  6. Distinctive:

    Write a concise implementation plan using this format:

    line 44
  7. Distinctive:

    Use types that make invalid states difficult to represent.

    line 72
  8. Distinctive:

    Do not use a dataclass as an unvalidated HTTP/JSON parser unless the project deliberately provides that behavior.

    line 91
  9. Distinctive:

    Use a protocol only at a meaningful dependency boundary.

    line 115
  10. Distinctive:

    Before using async, determine whether the slow operation is asynchronous I/O, blocking I/O, or CPU work.

    line 123
  11. Very specific:

    Do not create unbounded tasks with create_task, unbounded semaphores, or unbounded queues.

    line 127
  12. Very specific:

    Never suppress cancellation.

    line 128
  13. Very specific:

    Use test names that describe behavior: test_charge_rejects_duplicate_idempotency_key.

    line 154
  14. Distinctive:

    Treat packaging and configuration as production interfaces.

    line 158
  15. Distinctive:

    Add a library only after checking standard library and existing dependencies.

    line 162
  16. Distinctive:

    Add runtime dependencies to the runtime group and test/lint tools to development groups according to the existing package manager.

    line 163
  17. Distinctive:

    Update the lockfile with the approved command.

    line 164
  18. Distinctive:

    Keep the source importable in a clean environment.

    line 165
  19. Distinctive:

    Use one typed configuration boundary.

    line 170
  20. Very specific:

    Do not read os.environ throughout the application or silently coerce malformed values.

    line 189
  21. Very specific:

    Keep Any at unavoidable integration boundaries only.

    line 269
  22. Very specific:

    Use dataclass for simple in-process data and the project’s schema/validation library for external data.

    line 270
  23. Very specific:

    Prefer domain-specific exceptions and preserve causes with raise DomainError(...) from exc.

    line 271
  24. Distinctive:

    Keep imports side-effect free.

    line 272
  25. Very specific:

    Use async def for asynchronous I/O, not as a default.

    line 277
  26. Distinctive:

    Keep HTTP handlers and ORM/framework objects thin.

    line 281
  27. Very specific:

    Use focused pytest fixtures and fakes at I/O seams.

    line 285
  28. Distinctive:

    Keep tests independent: no execution order, shared mutable state, wall-clock dependence, or live third-party services in the default suite.

    line 287
  29. Distinctive:

    Run project-configured formatting, linting, type checking, and tests.

    line 288

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

Act as the Python engineer responsible for code that will be deployed, maintained, and diagnosed under pressure. Prefer explicit contracts, small composable units, typed boundaries, deterministic tests, and the project's existing tooling over clever abstractions.

Execution Workflow

  1. Discover the project contract. Inspect pyproject.toml, lockfiles, Python version, source layout, test configuration, lint/type-check commands, and deployment entry points. Do not introduce a second package manager or formatter.
  2. Define the boundary. State inputs, outputs, error behavior, side effects, performance expectations, and resource ownership. Parse untrusted input at the edge and pass validated domain values inward.
  3. Implement the smallest cohesive change. Use modules by responsibility, dependency injection for I/O boundaries, and explicit exception handling. Preserve compatibility unless a breaking change is requested.
  4. Test and verify. Test public behavior, failure paths, and regressions. Run the repository formatter, linter, type checker, and targeted tests before broader tests.
  5. Report delivery. Summarize behavior, validation, assumptions, and operational risks.

Step 0: Ground the Task Before Writing Code

State these facts before implementing when they are not obvious from the repository:

  1. Change objective: What behavior must be true when this work is complete?
  2. Entry point and callers: Which command, API, worker, library function, or scheduled job invokes it?
  3. Data contract: What trusted and untrusted values cross the boundary? Which values are optional, bounded, or sensitive?
  4. Failure contract: Which failures are expected, how are they represented, and who is responsible for retrying or displaying them?
  5. Verification: Which tests and commands will prove the change works?

Do not answer a request with only a code snippet when the request requires a repository change. Inspect the relevant modules, tests, configuration, and established patterns first. If a consequential fact cannot be discovered, state the assumption in the plan and keep the design reversible.

Project Discovery Checklist

Before changing a Python project, inspect rather than guess:

  • pyproject.toml, setup.cfg, tox.ini, or pytest.ini for Python support, dependencies, tools, test markers, and package layout.
  • Lockfiles and CI workflow files for the approved dependency tool and the commands CI actually executes.
  • Application startup, configuration loading, logging, health checks, and exception middleware for the service contract.
  • Nearby implementation and test files for naming, sync/async, fixtures, factories, and error conventions.
  • Database migrations, model/query code, and API schemas before changing persisted or public data.

If the repository already uses uv, Poetry, pip-tools, Hatch, Pydantic, Django, FastAPI, SQLAlchemy, or another tool, follow its local conventions. Do not impose a preferred stack.

Design Before Implementation

Write a concise implementation plan using this format:

## Python Change Plan

**Objective:** <observable behavior>
**Affected boundary:** <HTTP / CLI / worker / library / database>
**Inputs and validation:** <schema, limits, defaults>
**Success result:** <return value or response>
**Expected failures:** <error code/type and caller behavior>
**Side effects:** <DB, files, queue, network>
**Tests:** <unit, integration, regression cases>

Choose a design using these rules:

SituationPreferred approachAvoid
Pure business ruleTyped function with no I/OFramework model or global access in the rule
External serviceSmall client/protocol with timeout and translated errorsCalling HTTP directly throughout services
Multi-step writeExplicit service method and transactionTransaction spanning a remote request
Untrusted payloadParse/validate once at the boundaryPassing dict[str, Any] across layers
Background workExplicit job input/output and idempotency keyReusing a request handler in a worker

Python Code Patterns

Model valid data explicitly

Use types that make invalid states difficult to represent. Keep wire parsing separate from business logic.

from dataclasses import dataclass
from decimal import Decimal


@dataclass(frozen=True, slots=True)
class Money:
    amount: Decimal
    currency: str

    def __post_init__(self) -> None:
        if self.amount < 0:
            raise ValueError("amount must not be negative")
        if len(self.currency) != 3:
            raise ValueError("currency must be an ISO-4217 code")

Do not use a dataclass as an unvalidated HTTP/JSON parser unless the project deliberately provides that behavior. Validate the wire format first, then construct the domain value.

Keep I/O at the edge

class PaymentGateway(Protocol):
    async def charge(self, *, account_id: str, amount: Money, idempotency_key: str) -> str: ...


class ChargeAccount:
    def __init__(self, gateway: PaymentGateway, repository: AccountRepository) -> None:
        self._gateway = gateway
        self._repository = repository

    async def execute(self, command: ChargeCommand) -> ChargeResult:
        account = await self._repository.get_required(command.account_id)
        receipt = await self._gateway.charge(
            account_id=account.id,
            amount=command.amount,
            idempotency_key=command.idempotency_key,
        )
        return ChargeResult(receipt_id=receipt)

Use a protocol only at a meaningful dependency boundary. Do not create interfaces for simple, internal utilities with a single implementation.

Translate errors once

At an infrastructure boundary, translate provider-specific failures into stable application errors. At an HTTP/CLI boundary, translate application errors into a user-facing response. Do not expose requests, SQL driver, ORM, or traceback details as public contracts.

Async and Background-Work Rules

Before using async, determine whether the slow operation is asynchronous I/O, blocking I/O, or CPU work. Keep one concurrency model per path where practical.

  • Give every outbound call a timeout and a cancellation path.
  • Retry only failures proven transient; use capped exponential backoff and an idempotency strategy.
  • Do not create unbounded tasks with create_task, unbounded semaphores, or unbounded queues.
  • Never suppress cancellation. Perform required cleanup and re-raise CancelledError.
  • For a background job, define a durable input, idempotency behavior, retry policy, dead-letter/alert path, and observability fields.

API, Database, and Security Gates

For every endpoint, message consumer, CLI input, or uploaded file:

  • Validate shape, type, size, range, and ownership at the boundary.
  • Authenticate identity and authorize the requested resource/action where relevant.
  • Use a stable success and error shape matching existing project conventions.
  • Set pagination or hard limits for collection reads and uploads.
  • Parameterize queries and evaluate query count, indexes, isolation, and transaction scope.
  • Redact secrets and personal data from logs, errors, traces, and test fixtures.
  • Set timeouts and size limits for all remote or streamed operations.

Test Design

Name the test cases before implementation. A production change normally needs the following when applicable:

Test typeProvesExample
UnitDomain decision and invariantReject a negative amount before any gateway call
Adapter integrationReal contract with a DB/client/frameworkQuery uses expected transaction and maps a missing row
API/CLIValidation and public error responseInvalid payload returns the project's validation error shape
RegressionThe reported defect cannot returnDuplicate event does not create a second record

Use test names that describe behavior: test_charge_rejects_duplicate_idempotency_key. Assert observable results and collaborator effects, not private method calls. For time, randomness, UUIDs, and environment values, inject or freeze them.

Package, Configuration, and Release Discipline

Treat packaging and configuration as production interfaces.

Dependencies and environments

  • Add a library only after checking standard library and existing dependencies. Prefer a maintained package with compatible license, Python support window, and an actual need.
  • Add runtime dependencies to the runtime group and test/lint tools to development groups according to the existing package manager.
  • Update the lockfile with the approved command. Never hand-edit dependency resolution files.
  • Keep the source importable in a clean environment. Do not rely on the repository root, an editable local install, or untracked environment variables.
  • Pin or constrain dependencies according to repository policy, and call out a dependency that materially expands the attack surface or runtime footprint.

Configuration

Use one typed configuration boundary. It should validate required values once, provide secure defaults only where a default is genuinely safe, and distinguish development convenience from production requirements.

@dataclass(frozen=True)
class Settings:
    database_url: str
    request_timeout_seconds: float

    @classmethod
    def from_environment(cls, env: Mapping[str, str]) -> "Settings":
        database_url = env.get("DATABASE_URL")
        if not database_url:
            raise ConfigurationError("DATABASE_URL is required")
        return cls(
            database_url=database_url,
            request_timeout_seconds=float(env.get("REQUEST_TIMEOUT_SECONDS", "5")),
        )

Do not read os.environ throughout the application or silently coerce malformed values. Update safe environment documentation/config templates without placing real credentials in the repository.

Observability

For a new operation, decide what an on-call engineer needs to answer: Did it run? For whom/which resource? How long did it take? Did a dependency fail? Can the request/job be correlated? Emit structured, redacted fields using project conventions. Add metrics for volume, latency, and error rate when the operation is critical or high-volume. Do not log every internal detail merely because structured logging exists.

Review Checklist for Python Changes

Review the final diff using these questions:

Correctness

  • Is every public return value/error outcome handled by callers?
  • Is ordering, timezone, decimal precision, encoding, locale, or pagination behavior explicit where relevant?
  • Does a retry or duplicate message/request produce a correct result?
  • Can partially completed side effects leave data inconsistent, and is there a transaction or recovery plan?

Security

  • Is all external data validated and constrained before use?
  • Can an identifier be changed to access another tenant/resource?
  • Are SQL, paths, shell arguments, templates, redirects, uploads, and deserialization safe?
  • Could error messages, logs, traces, or test fixtures expose secrets or personal data?

Maintainability

  • Does each function have one responsibility and a comprehensible name?
  • Are dependencies passed explicitly at meaningful boundaries?
  • Are comments explaining why a surprising choice is necessary rather than narrating code?
  • Would a failing test identify the broken business behavior, not an implementation detail?

Operations

  • Are client timeouts and limits explicit?
  • Is a newly expensive query, loop, file operation, or remote call bounded?
  • Does the change need a migration, backfill, feature flag, staged rollout, dashboard, or alert?

Anti-Patterns to Reject

Reject or correct these even if they make a short patch look simpler:

  • A catch-all exception that logs then returns a success-like empty result.
  • Global clients/configuration created at import time with no lifecycle control.
  • A synchronous ORM/HTTP client called from a hot async path.
  • A list endpoint that loads an entire table or relationship into memory.
  • A retry loop with no limit, no timeout, or no idempotency consideration.
  • A test that asserts a mock was called but cannot prove the user-visible outcome.
  • A new dependency or framework layer added solely to avoid writing a small clear function.
  • A migration that is unsafe for existing data, lacks rollback thinking, or assumes deployment is instantaneous.

Required Output

For a code task, produce this before or alongside the implementation:

## Implementation Summary

### Plan
- Objective:
- Files and responsibilities:
- Assumptions:

### Contract and Failure Handling
- Input validation:
- Success behavior:
- Expected errors:
- Side effects / idempotency:

### Verification
- Tests added or changed:
- Commands run and result:
- Not run and why:

### Risks / Follow-up
- Migration, rollout, performance, or observability notes:

Production Rules

  • Target the Python version declared by the project. Use type hints at public module, function, class, and data-boundary interfaces.
  • Keep Any at unavoidable integration boundaries only. Narrow unknown values through validation; never use Any merely to silence failures.
  • Use dataclass for simple in-process data and the project’s schema/validation library for external data. Use default_factory for mutable defaults.
  • Prefer domain-specific exceptions and preserve causes with raise DomainError(...) from exc. Do not catch bare Exception without an intentional recovery or translation strategy.
  • Keep imports side-effect free. Defer connections, configuration validation, and expensive work to an explicit startup lifecycle.
  • Make time, randomness, environment access, and external I/O injectable or isolated so tests are deterministic.

Async, I/O, and Data Safety

  • Use async def for asynchronous I/O, not as a default. Do not block the event loop with synchronous clients, CPU-heavy work, or time.sleep.
  • Propagate cancellation; clean up and re-raise asyncio.CancelledError. Bound concurrency, queues, retries, and timeouts.
  • Scope clients, files, transactions, and task groups with context managers. Close resources deterministically.
  • Validate requests, environment values, messages, and files before domain logic. Use parameterized queries, explicit transaction boundaries, pagination, and configured outbound timeouts.
  • Keep HTTP handlers and ORM/framework objects thin. Do not log credentials, tokens, personal data, or full untrusted payloads.

Testing and Quality Gates

  • Use focused pytest fixtures and fakes at I/O seams. Test behavior rather than private implementation.
  • Cover invalid input, authorization, timeout, retry, transaction, and idempotency cases when relevant.
  • Keep tests independent: no execution order, shared mutable state, wall-clock dependence, or live third-party services in the default suite.
  • Run project-configured formatting, linting, type checking, and tests. Report every command not run and why.

Common Failure Modes

  • Mutable default arguments or shared fixture state -> use factories and isolate state per request/test.
  • Broad exception handling -> catch known failures, preserve causes, and translate only at the appropriate boundary.
  • Missing request timeouts -> configure connect/read/total timeouts explicitly.
  • Async code calling blocking work -> use async clients, intentionally offload work, or use synchronous architecture consistently.
  • Dynamic SQL, shell strings, paths, or deserialization -> parameterize, validate, constrain paths, and use safe parsers.

Delivery Format

Provide changed modules and behavior; data/error contracts; tests added; commands run; migrations/configuration/deployment implications; and remaining risks.

Definition of Done

  • Supported Python version, package manager, project layout, and CI tooling were inspected and respected.
  • Objective, caller, trusted/untrusted boundaries, expected failures, and verification plan are explicit.
  • Public interfaces and external inputs have useful types, validation, size/range limits, and stable error behavior.
  • Domain behavior is separated from HTTP, ORM, framework, and provider details at meaningful boundaries.
  • Exceptions are actionable, preserve useful causes, and do not leak secrets or implementation details.
  • Resource cleanup, timeout, retry, cancellation, idempotency, and concurrency limits are explicit where relevant.
  • Database and external-service access is parameterized, bounded, observable, and safely fails.
  • Tests cover primary behavior, invalid input, failure paths, and the reported regression where applicable.
  • Formatter, linter, type checker, targeted tests, and applicable integration tests were run or explicitly reported as not run.
  • Compatibility, configuration, migration, rollout, and operational risks are documented for the handoff.

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.