Skip to main content

Python client for Evolution API - WhatsApp integration made simple

Project description

🚀 PyEvolution

Python client for Evolution API - WhatsApp integration made simple

CI codecov PyPI version Python Version Downloads License: MIT Code style: black Ruff pre-commit

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

  1. Update version in pyproject.toml
  2. Create a git tag: git tag v0.1.1
  3. Push tag: git push origin v0.1.1
  4. 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

🔗 Links


Made with ❤️ by Luiz Paulo Coutinho

PyEvolution - Making WhatsApp integration simple, powerful, and fun! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyevolutionapi-0.1.0.tar.gz (27.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyevolutionapi-0.1.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file pyevolutionapi-0.1.0.tar.gz.

File metadata

  • Download URL: pyevolutionapi-0.1.0.tar.gz
  • Upload date:
  • Size: 27.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyevolutionapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c85f6a96d5fc622fedd0f7e4ca19b3450da46d0bb21cfaf868c19eeced7cb352
MD5 c84173aa64716ea204de87344ca2a55f
BLAKE2b-256 ff595de0847666a520be73d39a109b52897f77ed31e6dc4806ef323cb5aeb239

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyevolutionapi-0.1.0.tar.gz:

Publisher: publish.yml on lpcoutinho/pyevolutionapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyevolutionapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyevolutionapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyevolutionapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7759ad328dcd6f2e3da7fc8699b0e27670a52179bcc995fcbcce55746f757b8
MD5 d6c9fc0d33436f89f3d81f22a0c5e380
BLAKE2b-256 f676ecdf352026bf67f59dff21172cb961ab72d07904afecec37422e3af23f22

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyevolutionapi-0.1.0-py3-none-any.whl:

Publisher: publish.yml on lpcoutinho/pyevolutionapi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page