# Python Generators Coroutines

> Use when implementing Python generators and coroutines.

- Skill: `loopyluci/python-generators-coroutines` (Agent Skill)
- Install (CLI): `npx skillmds@latest add loopyluci/python-generators-coroutines`
- Raw SKILL.md: https://api.skillmd.com/api/skills/loopyluci/python-generators-coroutines/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: LoopyLuci (https://skillmd.com/u/loopyluci)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/loopyluci/python-generators-coroutines

---


# Python Generators and Coroutines

Implementing Python generators — from generator expressions through yield from, send/throw/close, and bidirectional coroutines.

## When to Use

- Processing data streams with generator pipelines
- Implementing coroutines for cooperative multitasking
- Lazy evaluation and infinite sequences
- Data pipeline composition

## Generator Patterns

```python
def pipeline(*steps):
    """Chain generator functions."""
    def run(initial):
        result = initial
        for step in steps:
            result = step(result)
        return result
    return run

def read_chunks(file, size=8192):
    while True:
        chunk = file.read(size)
        if not chunk: break
        yield chunk

def grep(pattern):
    """Bidirectional coroutine generator."""
    while line := (yield):
        if pattern in line:
            yield line
```

## Verification Checklist

- [ ] Generator expressions vs list comprehensions
- [ ] yield from for subgenerator delegation
- [ ] .send() for bidirectional communication
- [ ] Generator pipeline composition
- [ ] Memory-efficient large data processing

