Python Patterns

This skill should be used for Python idioms, type hints, async/await, pytest, Django, Flask, FastAPI, Python web frameworks, pandas, data processing Use when this capability is needed.

tomevault-io 27c12c3 2 files · 1.9 KB Updated

File contents

Python Patterns

Idiomatic Python patterns for Python 3.10+.

Type Hints

def process(data: list[str]) -> dict[str, int]:
    return {item: len(item) for item in data}

Dataclasses

from dataclasses import dataclass

@dataclass
class User:
    name: str
    email: str
    active: bool = True

Context Managers

with open("file.txt") as f:
    content = f.read()

Pytest

import pytest

def test_add():
    assert add(2, 3) == 5

@pytest.fixture
def user():
    return User(name="test")

Async/Await

async def fetch_data(url: str) -> dict:
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.json()

Error Handling

try:
    result = risky_operation()
except ValueError as e:
    logger.error(f"Invalid value: {e}")
    raise

Converted and distributed by TomeVault — claim your Tome and manage your conversions.

tomevault-io/skills-registry/tree/main/zate--cc-plugins--python-patterns commit 27c12c348e

Frequently asked questions

npx skillmds@latest add tomevault-io/python-patterns