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
.cursor/rules/102-python-patterns.mdcWhat 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
exceptblocks and introduce domain-specific exceptions - switch file system routines from
os.pathtopathlib - 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.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/102-python-patterns.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/102-python-patterns.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/102-python-patterns.mdManually: put the files in place
.clinerules/102-python-patterns.mdStep 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