Practical Claude API recipes — copy, run, and build upon
claude-cookbook is a collection of practical, runnable recipes for the Claude API. Each recipe is a self-contained Python file you can copy and adapt for your project.
Think of it as Stack Overflow for Claude API patterns — except the code actually works.
| Recipe | Description | Difficulty |
|---|---|---|
| web_research_agent.py | Agentic web research loop with DuckDuckGo | ⭐⭐ |
| Recipe | Description | Difficulty |
|---|---|---|
| extract_data.py | Extract typed data (contacts, invoices) with Pydantic | ⭐ |
| Recipe | Description | Difficulty |
|---|---|---|
| simple_rag.py | RAG with TF-IDF retrieval — no vector DB required | ⭐⭐ |
| Recipe | Description | Difficulty |
|---|---|---|
| calculator_agent.py | Tool use pattern: define, call, collect, repeat | ⭐ |
| Recipe | Description | Difficulty |
|---|---|---|
| streaming_chat.py | Streaming chat with history and token tracking | ⭐ |
| Recipe | Description | Difficulty |
|---|---|---|
| image_analyzer.py | Analyze images from URLs or local files | ⭐ |
Difficulty: ⭐ Beginner · ⭐⭐ Intermediate · ⭐⭐⭐ Advanced
1. Clone the repo
git clone https://github.com/mimonimo/claude-cookbook
cd claude-cookbook2. Install dependencies
pip install anthropic rich httpx pydantic scikit-learn3. Set your API key
export ANTHROPIC_API_KEY="your-key-here"
# Get yours at: https://console.anthropic.com/4. Run a recipe
python recipes/streaming/streaming_chat.py
python recipes/agents/web_research_agent.py
python recipes/structured_output/extract_data.pyEach recipe follows a consistent structure:
"""
Recipe: Name
=============
What this recipe demonstrates.
When to use it.
Requirements:
pip install anthropic <other-deps>
Usage:
ANTHROPIC_API_KEY=your-key python recipe_name.py
"""
# ... imports ...
# ── Tool/Function Definitions ───────
# ... the interesting code ...
# ── Demo ───────────────────────────
def main():
# Runnable example
if __name__ == "__main__":
main()Philosophy:
- Each recipe fits in a single file
- Minimal dependencies
- Runnable as-is with just an API key
- Clear comments explaining the why, not just the what
Coming soon:
- Batch processing with concurrency
- Prompt caching patterns
- Multi-agent coordination
- Code execution agent
- PDF/document analysis
- CSV data analyst
- Automated testing with Claude
- Slack bot integration
- Voice transcription + Claude
Have a useful Claude API pattern? Add it as a recipe!
Guidelines:
- One recipe = one
.pyfile in the right category folder - Follow the recipe format (docstring header +
main()) - Minimize dependencies — prefer stdlib when possible
- Add your recipe to the README table
- Open a PR!
# Fork, clone, add recipe, push, PR
git clone https://github.com/mimonimo/claude-cookbook
cd claude-cookbook
# Create your recipe in the right folder
# Add it to the README
git add . && git commit -m "Add recipe: your-recipe-name"
git push origin mainNew recipe ideas (open issues):
- Semantic search with embeddings
- Code review bot
- Meeting summarizer
- Email draft generator
- Claude API Documentation
- Anthropic Cookbook — Official cookbook
- Claude API Python SDK
- MCP Documentation
MIT © mimonimo
Found a useful recipe? Give it a ⭐ to help others find it!
Built by mimonimo