A comprehensive Python starter kit for building applications with the Claude API. Get started in minutes with 10 ready-to-use examples covering everything from basic chat to advanced tool use.
- 10 Production-Ready Examples - Copy, paste, and customize for your needs
- Utility Library - Reusable API client with error handling and retry logic
- Best Practices - Learn proper error handling, streaming, and token management
- Well Documented - Every example includes detailed comments and sample output
- Modern Python - Uses the latest Anthropic SDK with type hints
- Zero to Hero - Progress from simple chat to advanced function calling
- 01_basic_chat.py - Simple chat completion with Claude
- 02_streaming_chat.py - Real-time streaming responses
- 03_system_prompts.py - Control Claude's behavior and personality
- 04_structured_output.py - Get JSON and structured data responses
- 05_code_review.py - AI-powered code analysis and security audits
- 06_email_writer.py - Generate professional emails for any scenario
- 07_content_summarizer.py - Summarize articles and long-form content
- 08_data_extractor.py - Extract structured data from unstructured text
- 09_multi_turn_chat.py - Build conversational interfaces with memory
- 10_tool_use.py - Function calling and tool integration
- ClaudeClient - Simplified API wrapper with convenience methods
- Error Handling - Graceful handling of rate limits and API errors
- Retry Logic - Automatic retry with exponential backoff
- Python 3.8 or higher
- Anthropic API key (Get one here)
-
Clone or download this repository
-
Install dependencies:
pip install -r requirements.txt- Set up your API key:
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY- Run any example:
cd examples
python 01_basic_chat.pyfrom anthropic import Anthropic
client = Anthropic(api_key="your-api-key")
message = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
messages=[{
"role": "user",
"content": "What is the capital of France?"
}]
)
print(message.content[0].text)from utils import ClaudeClient
client = ClaudeClient() # Uses ANTHROPIC_API_KEY from environment
# Simple chat
response = client.chat("Explain quantum computing in simple terms")
print(response)
# Streaming chat
for chunk in client.chat_stream("Write me a poem"):
print(chunk, end="", flush=True)import json
from utils import ClaudeClient
client = ClaudeClient()
response = client.chat(
"Extract contact info from this email: ...",
system="Return only valid JSON with name, email, and phone fields"
)
data = json.loads(response)
print(f"Name: {data['name']}")
print(f"Email: {data['email']}")- 01-04: Core fundamentals (chat, streaming, prompts, structured output)
- 05-07: Practical applications (code review, email writing, summarization)
- 08-10: Complex patterns (data extraction, multi-turn chat, tool use)
This starter kit is perfect for building:
- AI Chatbots - Customer support, internal tools, virtual assistants
- Content Generation - Emails, summaries, articles, social posts
- Code Tools - Code review, documentation, refactoring suggestions
- Data Processing - Extract structured data from documents and text
- Workflow Automation - Integrate AI into your existing pipelines
All examples include proper error handling:
from utils import handle_api_errors, retry_with_backoff
@retry_with_backoff(max_retries=3)
@handle_api_errors
def make_api_call():
# Your code here
passMonitor token usage to control costs:
message = client.messages.create(...)
print(f"Input tokens: {message.usage.input_tokens}")
print(f"Output tokens: {message.usage.output_tokens}")Choose the right model for your needs:
- Claude Sonnet 4 (default) - Best balance of intelligence and speed
- Claude Opus - Maximum capability for complex tasks
- Claude Haiku - Fastest, most cost-effective
The Claude API uses token-based pricing. Approximate costs:
- Claude Sonnet 4: $3 per million input tokens, $15 per million output tokens
- Claude Opus: $15 per million input tokens, $75 per million output tokens
- Claude Haiku: $0.25 per million input tokens, $1.25 per million output tokens
Prices subject to change - check Anthropic's pricing page for current rates
- Never commit your API key - Use environment variables
- Use .gitignore - Exclude
.envfiles from version control - Rotate keys regularly - Generate new keys periodically
- Monitor usage - Set up billing alerts in the Anthropic Console
- Validate inputs - Sanitize user inputs before sending to the API
Found a bug or have a suggestion? Feel free to:
- Fork this repository
- Create a feature branch
- Submit a pull request
MIT License - feel free to use this in your projects!
- Documentation: See individual example files for detailed comments
- Issues: Open an issue on GitHub
- Anthropic Support: support@anthropic.com
Recommended order for learning:
- Start with
01_basic_chat.pyto understand the fundamentals - Move to
02_streaming_chat.pyfor better UX - Learn
03_system_prompts.pyto control Claude's behavior - Master
04_structured_output.pyfor data extraction - Explore
05-07for practical applications - Tackle
08-10for advanced patterns
Ideas to extend this starter kit:
- RAG System - Add document retrieval for knowledge-based chat
- Voice Integration - Combine with speech-to-text/text-to-speech
- Web Interface - Build a Streamlit or Flask UI
- Database Integration - Store conversations and user data
- Multi-Agent Systems - Coordinate multiple Claude instances
- API Service - Deploy as a REST API with FastAPI
If this starter kit helped you, please:
- Star this repository
- Share it with other developers
- Build something awesome and tag us!
Built with β€οΈ for the AI developer community
Ready to build something amazing with Claude? Start with example 01 and level up from there!