Skip to main content
rule

102-python-patterns — Claude Code rule: what it does, how to install

102-python-patterns defines modern Python conventions for AI coding: strict typing, async I/O, PEP 8 compliance, and structured error handling in **/*.py files.

MIT ★ 97 updated 2026-06-11

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/102-python-patterns.mdc
Open on GitHub

What 102-python-patterns does

The rule sets coding standards whenever the assistant touches Python files. It mandates explicit type hints across all function parameters and return types, preferring Pydantic or dataclasses instead of generic dictionaries. File system calls must rely on pathlib rather than os.path.

For I/O routines, the instructions enforce async/await and concurrent execution with asyncio.gather(). Bare except blocks are disallowed. Domain errors require dedicated custom exception classes, and resource cleanup delegates to contextlib.

Using structural pattern matching directly ties your codebase to Python 3.10 or higher.

What it helps with

  • enforce full type hints on all function signatures
  • eliminate bare except blocks and introduce domain-specific exceptions
  • switch file system routines from os.path to pathlib
  • keep hot paths purely asynchronous with asyncio.gather()

Example prompts for the agent

  • Write an async file fetcher validating its payload with Pydantic
  • Refactor branching logic using structural pattern matching
  • Build a safe resource wrapper using contextlib

How to install 102-python-patterns

Manually: put the files in place

.cursor/rules/102-python-patterns.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about 102-python-patterns

How to install 102-python-patterns in Claude Code?

Place the rule file at .claude/rules/102-python-patterns.md. Claude Code will automatically read it when inspecting **/*.py files.

What does 102-python-patterns do?

It guides the assistant to produce modern Python code using strict type annotations, PEP 8, pathlib, and structured error handling.

Which Python version is required?

The prompt specifies structural pattern matching, which demands at least Python 3.10 in your runtime environment.

Source text

102-python-patterns.mdc · MIT
---
description: Python coding patterns and conventions
globs: ["**/*.py"]
alwaysApply: false
---

# Python Patterns

## Type Hints
- Required for all function signatures (params + return type)
- Use Pydantic models for data validation
- Use TypeVar and Generic for reusable types

## Async
- Use async/await for all I/O operations
- Use asyncio.gather() for concurrent operations
- Never mix sync and async code in hot paths

## Style
- Follow PEP 8 strictly
- Use structural pattern matching (Python 3.10+) over complex if/else
- Prefer dataclasses or Pydantic over plain dicts
- Use pathlib over os.path

## Error Handling
- Use specific exception types (never bare except)
- Create custom exceptions for domain errors
- Use contextlib for resource management

© obviousworks · MIT · obviousworks/vibe-coding-ai-rules

Similar IDE rules

All IDE rules for Programming languages →

From the same set7

Project sponsors

Companies that keep this analytics open