Cliente Python para Claude API
ReubenDickson/agentic_ai_python_api
Wrapper Python e exemplos para integração com Claude API
Ver no GitHubAplicação Python simples para integração com a API Claude da Anthropic. Fornece wrapper funcional com exemplos de chat, análise de texto e escrita criativa, ideal para aprender padrões de integração com IA agentic.
Instalação
npx convez-ai ReubenDickson/agentic_ai_python_api1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Prototipagem de agentes de IA
- Aprendizado de integração com APIs
- Experimentação de pipelines CI/CD com Python
Veredito

Projeto educacional bem estruturado com padrões limpos de integração. Útil como ponto de partida para aprender agentes Python com Claude, mas carece de funcionalidades avançadas para casos de produção.
README
A tradução para o português deste README ainda está na fila.
Anthropic AI Python Client
A simple Python application for making API calls to Anthropic's Claude AI. This project serves as a foundation for learning agentic AI applications and demonstrates basic API integration patterns. I built this mainly for the purpose of experimenting CICD pipelines for Agentic AI Applications with Python.
🚀 Features
- Simple API Integration: Easy-to-use wrapper for Anthropic's Claude API
- Multiple Examples: Text analysis, creative writing, and interactive chat
- Conversation Management: Save and manage chat conversations
- Modular Design: Clean separation of concerns for easy extension
- Interactive CLI: Command-line interface for real-time interactions
- Environment Configuration: Secure API key management
📁 Project Structure
anthropic-ai-app/
│
├── .env # Environment variables (API key)
├── .gitignore # Git ignore file
├── requirements.txt # Python dependencies
├── config.py # Configuration settings
├── main.py # Main application entry point
├── README.md # Project documentation
├── api/
│ ├── __init__.py
│ └── anthropic_client.py # Anthropic API client wrapper
├── examples/
│ ├── __init__.py
│ ├── simple_chat.py # Basic chat example
│ ├── text_analysis.py # Text analysis example
│ └── creative_writing.py # Creative writing example
└── utils/
├── __init__.py
└── helpers.py # Utility functions
🛠️ Installation
Prerequisites
- Python 3.7 or higher
- Anthropic API key (get one at console.anthropic.com)
Setup
-
Clone the repository:
git clone https://github.com/yourusername/agentic_ai_python_api.git cd anthropic-ai-app -
Create and activate virtual environment:
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt -
Set up environment variables:
- Copy
.env.exampleto.env(if provided) or create a new.envfile - Add your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here DEFAULT_MODEL=claude-3-5-sonnet-20241022 MAX_TOKENS=1000 - Copy
🎯 Usage
Interactive Chat
Start a conversation with Claude:
python main.py chat
Run All Examples
Execute all example scripts:
python main.py examples
Run Individual Examples
python examples/simple_chat.py
python examples/text_analysis.py
python examples/creative_writing.py
📚 Examples
Simple Chat
from api.anthropic_client import AnthropicClient
client = AnthropicClient()
response = client.send_message("Explain quantum computing in simple terms.")
print(response)
Text Analysis
from api.anthropic_client import AnthropicClient
client = AnthropicClient()
text = "Your text here..."
response = client.send_message(f"Analyze the sentiment of: {text}")
print(response)
Conversation History
from api.anthropic_client import AnthropicClient
from utils.helpers import create_user_message, create_assistant_message
client = AnthropicClient()
conversation = [
create_user_message("Hello, how are you?"),
create_assistant_message("I'm doing well, thank you!"),
create_user_message("Can you help me with Python?")
]
response = client.chat_conversation(conversation)
print(response)
🔧 Configuration
The application uses environment variables for configuration:
| Variable | Description | Default |
|---|---|---|
ANTHROPIC_API_KEY | Your Anthropic API key | Required |
DEFAULT_MODEL | Claude model to use | claude-3-5-sonnet-20241022 |
MAX_TOKENS | Maximum tokens in response | 1000 |
📊 API Client Methods
send_message(message, model=None, max_tokens=None, system_prompt=None)
Send a single message to Claude.
Parameters:
message(str): The user messagemodel(str, optional): Model to usemax_tokens(int, optional): Maximum response tokenssystem_prompt(str, optional): System prompt for context
chat_conversation(messages, model=None, max_tokens=None, system_prompt=None)
Send a conversation history to Claude.
Parameters:
messages(List[Dict]): List of message dictionariesmodel(str, optional): Model to usemax_tokens(int, optional): Maximum response tokenssystem_prompt(str, optional): System prompt for context
🛡️ Error Handling
The client includes basic error handling for:
- Missing API keys
- Network issues
- API rate limits
- Invalid requests
📝 Logging
Conversations can be saved to files using the utility functions:
from utils.helpers import save_conversation
# Save conversation to timestamped file
save_conversation(messages)
# Save to specific filename
save_conversation(messages, "my_conversation.txt")
🚧 Development
Adding New Examples
- Create a new file in the
examples/directory - Import the
AnthropicClientand utility functions - Follow the existing example patterns
- Add your example to the main examples runner
Extending the API Client
The AnthropicClient class can be extended with additional methods for specific use cases:
- Streaming responses
- Function calling
- Custom model parameters
- Response parsing
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and commit:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
🔒 Security
- Never commit your API keys to version control
- The
.envfile is included in.gitignorefor security - Use environment variables for sensitive configuration
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🆘 Troubleshooting
Common Issues
"ANTHROPIC_API_KEY not found"
- Ensure your
.envfile exists and contains your API key - Make sure the
.envfile is in the project root directory
"Module not found" errors
- Activate your virtual environment
- Install dependencies:
pip install -r requirements.txt
API rate limit errors
- Check your API usage at console.anthropic.com
- Implement rate limiting in your application
Getting Help
- Check the Anthropic API documentation
- Review the example files for usage patterns
- Open an issue on GitHub for bugs or questions
🎓 Learning Resources
This project is part of a 30-day agentic AI bootcamp. Recommended next steps:
- Add streaming responses for real-time chat
- Implement function calling for tool use
- Add memory management for longer conversations
- Build a web interface with Flask/FastAPI
- Explore advanced prompting techniques
- Add monitoring and logging for production use
🏷️ Version History
- v1.0.0 - Initial release with basic API integration and examples
Built with ❤️ for learning agentic AI applications