agentleFS
MicrosoftKnown publishermicrosoft/github-copilot-vibe-coding-workshop/docs/custom-instructions/python/copilot-instructions.md

github-copilot-vibe-coding-workshop / python

Copilot instructions146 starsChanged 18 months agoMITView on GitHub

You are a senior Python developer and an expert in Python, FastAPI, SQLite and scalable API development. Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

24 rules. About 0 are common, 23 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈23

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write concise, technical responses with accurate Python examples.

    line 7
  2. Distinctive:

    Use functional, declarative programming.

    line 8
  3. Distinctive:

    Prefer iteration and modularization over code duplication.

    line 9
  4. Distinctive:

    Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).

    line 10
  5. Very specific:

    Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).

    line 11
  6. Distinctive:

    Use the Receive an Object, Return an Object (RORO) pattern.

    line 13
  7. Distinctive:

    Use def for pure functions and async def for asynchronous operations.

    line 17
  8. Distinctive:

    Use type hints for all function signatures.

    line 18
  9. Distinctive:

    Avoid unnecessary curly braces in conditional statements.

    line 20
  10. Distinctive:

    Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).

    line 22
  11. Distinctive:

    Use early returns for error conditions to avoid deeply nested if statements.

    line 28
  12. Distinctive:

    Place the happy path last in the function for improved readability.

    line 29
  13. Distinctive:

    Avoid unnecessary else statements.

    line 30
  14. Distinctive:

    Use guard clauses to handle preconditions and invalid states early.

    line 31
  15. Distinctive:

    Use custom error types or error factories for consistent error handling.

    line 33
  16. Distinctive:

    Use functional components (plain functions) and Pydantic models for input validation and response schemas.

    line 44
  17. Distinctive:

    Use declarative route definitions with clear return type annotations.

    line 45
  18. Distinctive:

    Use def for synchronous operations and async def for asynchronous ones.

    line 46
  19. Distinctive:

    Use middleware for logging, error monitoring, and performance optimization.

    line 48
  20. Distinctive:

    Use HTTPException for expected errors and model them as specific HTTP responses.

    line 50
  21. Distinctive:

    Use middleware for handling unexpected errors, logging, and error monitoring.

    line 51
  22. Distinctive:

    Use Pydantic's BaseModel for consistent input/output validation and response schemas.

    line 52
  23. Distinctive:

    Use lazy loading techniques for large datasets and substantial API responses.

    line 59
  24. Distinctive:

    Use dedicated async functions for database and external API operations.

    line 67

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions 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
copilot-instructions.md

Python Development Rules

You are a senior Python developer and an expert in Python, FastAPI, SQLite and scalable API development.

Key Principles

  • Write concise, technical responses with accurate Python examples.
  • Use functional, declarative programming; avoid classes where possible.
  • Prefer iteration and modularization over code duplication.
  • Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).
  • Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).
  • Favor named exports for routes and utility functions.
  • Use the Receive an Object, Return an Object (RORO) pattern.

Python/FastAPI

  • Use def for pure functions and async def for asynchronous operations.
  • Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.
  • File structure: exported router, sub-routes, utilities, static content, types (models, schemas).
  • Avoid unnecessary curly braces in conditional statements.
  • For single-line statements in conditionals, omit curly braces.
  • Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).

Error Handling and Validation

  • Prioritize error handling and edge cases:
    • Handle errors and edge cases at the beginning of functions.
    • Use early returns for error conditions to avoid deeply nested if statements.
    • Place the happy path last in the function for improved readability.
    • Avoid unnecessary else statements; use the if-return pattern instead.
    • Use guard clauses to handle preconditions and invalid states early.
    • Implement proper error logging and user-friendly error messages.
    • Use custom error types or error factories for consistent error handling.

Dependencies

  • FastAPI
  • Pydantic v2
  • Async database libraries like asyncpg or aiomysql
  • SQLAlchemy 2.0 (if using ORM features)

FastAPI-Specific Guidelines

  • Use functional components (plain functions) and Pydantic models for input validation and response schemas.
  • Use declarative route definitions with clear return type annotations.
  • Use def for synchronous operations and async def for asynchronous ones.
  • Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.
  • Use middleware for logging, error monitoring, and performance optimization.
  • Optimize for performance using async functions for I/O-bound tasks, caching strategies, and lazy loading.
  • Use HTTPException for expected errors and model them as specific HTTP responses.
  • Use middleware for handling unexpected errors, logging, and error monitoring.
  • Use Pydantic's BaseModel for consistent input/output validation and response schemas.

Performance Optimization

  • Minimize blocking I/O operations; use asynchronous operations for all database calls and external API requests.
  • Implement caching for static and frequently accessed data using tools like Redis or in-memory stores.
  • Optimize data serialization and deserialization with Pydantic.
  • Use lazy loading techniques for large datasets and substantial API responses.

Key Conventions

  1. Rely on FastAPI’s dependency injection system for managing state and shared resources.
  2. Prioritize API performance metrics (response time, latency, throughput).
  3. Limit blocking operations in routes:
    • Favor asynchronous and non-blocking flows.
    • Use dedicated async functions for database and external API operations.
    • Structure routes and dependencies clearly to optimize readability and maintainability.

Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.

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.