Python client for Evolution API - WhatsApp integration made simple
Project description
🚀 PyEvolution
Python client for Evolution API - WhatsApp integration made simple
PyEvolution is a modern, type-safe Python library that provides an intuitive interface to the Evolution API, making WhatsApp integration effortless for developers.
✨ Features
- 🎯 Type-safe: Complete type hints with Pydantic models
- 🔄 Async/Sync: Full support for both synchronous and asynchronous operations
- 🛡️ Error Handling: Comprehensive exception hierarchy with detailed error information
- 📱 Complete API Coverage: Support for messages, media, groups, instances, and more
- 🔧 Easy Configuration: Environment variables and multiple authentication methods
- 📚 Well Documented: Extensive documentation and examples
- ✅ Tested: Comprehensive test suite with high coverage
- 🔌 Webhook Support: Built-in webhook configuration and event handling
🚀 Quick Start
Installation
pip install pyevolutionapi
Basic Usage
from pyevolutionapi import EvolutionClient
# Create client
client = EvolutionClient(
base_url="http://localhost:8080",
api_key="your-api-key-here"
)
# Create an instance
instance = client.instance.create(
instance_name="my-whatsapp-bot",
qrcode=True
)
# Send a message
response = client.messages.send_text(
instance="my-whatsapp-bot",
number="5511999999999",
text="Hello from PyEvolution! 🎉"
)
print(f"Message sent! ID: {response.message_id}")
Async Usage
import asyncio
from pyevolutionapi import EvolutionClient
async def main():
client = EvolutionClient()
async with client:
# Create instance
instance = await client.instance.acreate(
instance_name="async-bot",
qrcode=True
)
# Send multiple messages concurrently
tasks = [
client.messages.asend_text(
instance="async-bot",
number="5511999999999",
text=f"Message {i}"
)
for i in range(5)
]
results = await asyncio.gather(*tasks)
print(f"Sent {len(results)} messages!")
asyncio.run(main())
📋 Supported Operations
🏠 Instance Management
- Create and manage WhatsApp instances
- QR code generation and connection status
- Instance restart, logout, and deletion
💬 Messages
- Send text messages with formatting
- Send media (images, videos, documents, audio)
- Send location, contacts, and stickers
- Interactive messages (polls, lists, buttons)
- Status/Stories publishing
👥 Groups
- Create and manage WhatsApp groups
- Add/remove participants and manage permissions
- Update group info (name, description, picture)
- Generate and manage invite links
💬 Chat Operations
- Manage conversations and contacts
- Mark messages as read
- Send presence indicators (typing, recording)
- Block/unblock contacts
👤 Profile Management
- Update profile information
- Manage profile picture and status
- Configure privacy settings
🔗 Webhooks & Events
- Configure webhooks for real-time events
- Support for WebSocket, RabbitMQ, and AWS SQS
- Comprehensive event handling
🛠️ Configuration
Environment Variables
Create a .env file in your project root:
# Required
EVOLUTION_BASE_URL=http://localhost:8080
EVOLUTION_API_KEY=your-global-api-key
# Optional
EVOLUTION_INSTANCE_NAME=default-instance
EVOLUTION_DEBUG=false
EVOLUTION_REQUEST_TIMEOUT=30
EVOLUTION_MAX_RETRIES=3
Client Configuration
from pyevolutionapi import EvolutionClient
client = EvolutionClient(
base_url="http://localhost:8080",
api_key="your-api-key",
default_instance="my-instance",
timeout=30.0,
max_retries=3,
debug=False
)
📖 Examples
Send Different Message Types
# Text message
client.messages.send_text(
instance="my-bot",
number="5511999999999",
text="Hello *World*! _Italic_ ~strikethrough~"
)
# Image with caption
client.messages.send_media(
instance="my-bot",
number="5511999999999",
mediatype="image",
media="https://example.com/image.jpg",
caption="Check out this image! 📸"
)
# Location
client.messages.send_location(
instance="my-bot",
number="5511999999999",
name="Times Square",
address="New York, NY",
latitude=40.7589,
longitude=-73.9851
)
# Poll
client.messages.send_poll(
instance="my-bot",
number="5511999999999",
name="What's your favorite language?",
values=["Python", "JavaScript", "Go", "Rust"]
)
🚀 Development & Contributing
Setting up Development Environment
# Clone the repository
git clone https://github.com/lpcoutinho/pyevolution.git
cd pyevolution
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=pyevolution --cov-report=html
# Run specific test files
pytest tests/unit/test_client.py
# Run tests with verbose output
pytest -v
Code Quality
This project uses several tools to maintain code quality:
- Black: Code formatting
- Ruff: Fast Python linter
- mypy: Static type checking
- pre-commit: Git hooks for quality checks
# Format code
black pyevolution tests examples
# Lint code
ruff check pyevolution tests examples
# Type check
mypy pyevolution
# Run all quality checks
pre-commit run --all-files
CI/CD Pipeline
The project uses GitHub Actions for:
- Continuous Integration: Automated testing across Python 3.8-3.12 on multiple OS
- Code Quality: Automated formatting, linting, and type checking
- Security: CodeQL analysis and dependency scanning
- Documentation: Automatic deployment to GitHub Pages
- Publishing: Automated releases to PyPI on tag push
Release Process
- Update version in
pyproject.toml - Create a git tag:
git tag v0.1.1 - Push tag:
git push origin v0.1.1 - GitHub Actions will automatically:
- Run all tests
- Build the package
- Publish to PyPI
- Create a GitHub release
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Evolution API - The powerful WhatsApp API that makes this possible
- Pydantic - For excellent data validation
- httpx - For modern HTTP client capabilities
📞 Support
- 🐛 Bug Reports: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📧 Email: your.email@example.com
🔗 Links
- PyPI Package (Coming Soon)
- GitHub Repository
- Evolution API
Made with ❤️ by Luiz Paulo Coutinho
PyEvolution - Making WhatsApp integration simple, powerful, and fun! 🚀
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyevolutionapi-0.1.1.tar.gz.
File metadata
- Download URL: pyevolutionapi-0.1.1.tar.gz
- Upload date:
- Size: 27.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
372dd79e722eac0f28962acca3e29da0922f517e19ef1e21cfe57cafb36f62a1
|
|
| MD5 |
b1f035eeb52eb1fec5b8e75f308ab434
|
|
| BLAKE2b-256 |
791ce3f789c6250597426566f1243452c6d9a81d374fd4598096f59213a0f890
|
Provenance
The following attestation bundles were made for pyevolutionapi-0.1.1.tar.gz:
Publisher:
publish.yml on lpcoutinho/pyevolutionapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyevolutionapi-0.1.1.tar.gz -
Subject digest:
372dd79e722eac0f28962acca3e29da0922f517e19ef1e21cfe57cafb36f62a1 - Sigstore transparency entry: 490959513
- Sigstore integration time:
-
Permalink:
lpcoutinho/pyevolutionapi@cd5071934ac5e0ef8b136c761f1f3778267dbeeb -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/lpcoutinho
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cd5071934ac5e0ef8b136c761f1f3778267dbeeb -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyevolutionapi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyevolutionapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a6beeac8c1fe379d858e0a07b20806ddcdbb15be0cf30cc8383364fef009883
|
|
| MD5 |
7353004bbaabac29a287409ac9d5329c
|
|
| BLAKE2b-256 |
302bbc6a9db1cf8c5417b146135d692dddcdfb23a5348a5e23ee12d52761d7fd
|
Provenance
The following attestation bundles were made for pyevolutionapi-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on lpcoutinho/pyevolutionapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyevolutionapi-0.1.1-py3-none-any.whl -
Subject digest:
5a6beeac8c1fe379d858e0a07b20806ddcdbb15be0cf30cc8383364fef009883 - Sigstore transparency entry: 490959576
- Sigstore integration time:
-
Permalink:
lpcoutinho/pyevolutionapi@cd5071934ac5e0ef8b136c761f1f3778267dbeeb -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/lpcoutinho
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cd5071934ac5e0ef8b136c761f1f3778267dbeeb -
Trigger Event:
push
-
Statement type: