Skip to content
Agentmart
Submit a tool

python-patterns

Python best practices, idioms, and patterns.

Skill by eroslifestyle

IndexedMIT★ 1
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/eroslifestyle-python-patterns

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Python best practices, idioms, and patterns. Auto-activated when working with .py files. Covers PEP 8, type hints, async, testing, packaging.

Use cases: testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/python-patterns

What's inside

Skill name
python-patterns
Description
Python best practices, idioms, and patterns. Auto-activated when working with .py files. Covers PEP 8, type hints, async, testing, packaging.
License
MIT
Instructions
178 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Python Patterns & Best Practices

> **Detailed patterns:** See `rules/python/patterns.md` for comprehensive examples.

## Style & Formatting

- **PEP 8** as baseline, **Black** for auto-formatting (88 char line length)
- **isort** for import ordering: stdlib > third-party > local
- Use f-strings over .format() or % formatting
- Trailing commas in multi-line structures

## Type Hints

- **All** function signatures must have type hints (params + return)
- Prefer `X | None` over `Optional[X]` (Python 3.10+)
- Use `Protocol` for structural subtyping, `TypeVar` for generics
- Use `TypeAlias` for complex type expressions

```python
from collections.abc import Sequence
from typing import TypeVar

T = TypeVar("T")

def find_min(items: Sequence[T]) -> T: ...
def fetch_user(user_id: int) -> User | None: ...
```

## Data Classes

| Use Case | Tool |
|----------|------|
| Simple data containers | `@dataclass` (stdlib) |
| Validation, serialization | `pydantic.BaseModel` |
| Advanced (validators, slots) | `attrs` |

```python
@dataclass(frozen=True, slots=True)
class Point:
    x: float
    y: float

class CreateUserRequest(BaseModel):
    name: str = Field(min_length=1, max_length=100)
    email: str
```

## Error Handling

- Define **custom exception hierarchy** per module/package
- **Never** bare `except:` or `except Exception:` without re-raise
- Use `contextlib.suppress` for expected, ignorable errors
- Wrap with context: `raise AppError("context") from original`

```python
class AppError(Exception): ...
class NotFoundError(AppError): ...

def get_config(path: Path) -> dict:
    try:
        return json.loads(path.read_text())
    except FileNotFoundError as exc:
        raise NotFoundError(f"Config not found: {path}") from exc
```

## Async Patterns

- **asyncio** for I/O-bound work (HTTP, DB, file I/O)
- Use `async with` for resource management
- **Never** mix sync blocking calls in async code (use `run_in_executor`)
- Use `asyncio.TaskGroup` (3.11+) for structured concurrency

```python
async def fetch_all(urls: list[str]) -> list[str]:
    async with httpx.AsyncClient(timeout=10.0) as client:
        async with asyncio.TaskGroup() as tg:
            tasks = [tg.create_task(client.get(url)) for url in urls]
    return [t.result().text for t in tasks]
```

## Testing

- **pytest** as framework (not unittest)
- Fixtures over setUp/tearDown -- composable, explicit
- `@pytest.mark.parametrize` for variant testing
- `conftest.py` for shared fixtures
- Use `tmp_path` fixture for file tests, `monkeypatch` for env

```python
@pytest.mark.parametrize("input_val,expected", [
    ("hello", "HELLO"), ("", ""),
])
def test_uppercase(input_val: str, expected: str) -> None:
    assert to_upper(input_val) == expected
```

## Packaging

- **pyproject.toml** as single config file (PEP 621)
- **uv** (fast) or **poetry** for dependency management
- `src/` layout to prevent accidental imports

```
myproject/
    src/myproject/__init__.py
    tests/conftest.py
    pyproject.toml
```

## Performance

| Technique | When |
|-----------|------|
| Generators | Iterating large datasets (lazy evaluation) |
| `__slots__` | Many instances (reduces memory ~40%) |
| `functools.lru_cache` | Pure functions with repeated calls |
| `collections.deque` | Fast append/pop from both ends |

## Security

From eroslifestyle/Claude-Orchestrator-Plugin, MIT.

More from eroslifestyle/Claude-Orchestrator-Plugin

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
Mar 3, 2026 (8 months ago)
Last release
Mar 3, 2026 (8 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from eroslifestyle

Cite this page

python-patterns skill. Agent Mart. https://agentmart.dev/skills/eroslifestyle-python-patterns (last updated 2026-10-24)