# Python

> Python programming language advanced patterns

- Skill: `neuralblitz/python-3` (Agent Skill)
- Install (CLI): `npx skillmds@latest add neuralblitz/python-3`
- Raw SKILL.md: https://api.skillmd.com/api/skills/neuralblitz/python-3/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- License: MIT
- Author: NeuralBlitz (https://skillmd.com/u/neuralblitz)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/neuralblitz/python-3

---

## What I do
- Write idiomatic Python
- Use type hints effectively
- Implement async patterns
- Use decorators properly
- Handle generators
- Use context managers
- Write Pythonic code
- Optimize Python performance

## When to use me
When writing Python code.

## Python Patterns
```python
from typing import TypeVar, Generic, Protocol
from contextlib import contextmanager
import asyncio

T = TypeVar('T')

# Generators for memory efficiency
def process_large_file(filepath: str):
    with open(filepath) as f:
        for line in f:
            yield line.strip()

# Context managers
@contextmanager
def database_transaction():
    try:
        yield
        commit()
    except Exception:
        rollback()
        raise

# Async patterns
async def fetch_all(urls: list[str]) -> list[dict]:
    async with aiohttp.ClientSession() as session:
        tasks = [fetch(session, url) for url in urls]
        return await asyncio.gather(*tasks)

# Protocol for duck typing
class Database(Protocol):
    async def connect(self): ...
    async def query(self, sql: str): ...

# Type hints
from dataclasses import dataclass

@dataclass(frozen=True)
class User:
    id: int
    name: str
    email: str
```

