Python Advanced¶
Intermediate → Advanced · 10 topics
The Python that real GenAI codebases are written in: streaming, retries, structured output, concurrent API calls, tests and clean project layout. Finish Python Basics first.
| # | Topic | Sub-topics |
|---|---|---|
| 1 | Iterators & generators | iter/next · yield · lazy file reading · generator expressions · streaming tokens |
| 2 | Decorators | Functions as objects · closures · functools.wraps · retry decorator · lru_cache |
| 3 | Context managers | How with works · class-based · @contextmanager · suppress |
| 4 | Type hints, dataclasses & Pydantic | Type hints · optional values · @dataclass · validating LLM JSON |
| 5 | Error handling & logging | Custom exceptions · raise … from · logging · what to log |
| 6 | Async programming | async/await · gather · semaphores · timeouts · async SDKs |
| 7 | Concurrency: threads vs processes | The GIL · ThreadPoolExecutor · ProcessPoolExecutor · as_completed |
| 8 | Testing with pytest | Asserts · raises · parametrize · fixtures · faking LLM calls |
| 9 | Project structure & packaging | Folder layout · settings · pyproject.toml · ruff, mypy |
| 10 | Performance & caching | Measuring · data-structure choice · lru_cache · disk cache · batching |
Next: put it to work — Call an LLM from Python, then Build a RAG chatbot.