Skip to main content

Open Source Framework to develop smart Workflows, Agents and full chat applications through WhatsApp

Project description

Wappa ๐Ÿค–

Open Source Framework for WhatsApp Business Applications

Build intelligent WhatsApp bots, workflows, and chat applications with clean architecture and modern Python.

Python 3.12+ License: Apache 2.0 FastAPI WhatsApp Business API Version

v0.13.0 โ€” Clean-break release โ€” inbox_id replaces tenant_id/owner_id as core identity, all compatibility shims removed, webhook schemas consolidated under wappa/webhooks/, inbound dispatch context added for multi-inbox routing. See CHANGELOG.md for the full breakdown.


๐Ÿš€ What is Wappa?

Wappa is a modern Python framework that transforms WhatsApp Business API into a powerful platform for building:

  • ๐Ÿค– Smart Chatbots - AI-powered conversational experiences
  • ๐Ÿ“‹ Workflows - Multi-step business processes
  • ๐ŸŽฏ Agents - Intelligent customer service automation
  • ๐Ÿ’ฌ Chat Applications - Full-featured messaging platforms

Built for developers who want clean code, not webhook complexity.

โœจ Key Features

๐ŸŽฏ Simple & Clean

from wappa import Wappa, WappaEventHandler

class MyBot(WappaEventHandler):
    async def process_message(self, webhook):
        await self.messenger.send_text("Hello!", webhook.user.user_id)

app = Wappa()
app.set_event_handler(MyBot())
app.run()

๐Ÿ—๏ธ Production-Ready Architecture

  • Clean Architecture - Domain-driven design with dependency injection
  • Type-Safe - Full Pydantic models for all WhatsApp data structures
  • Multi-Inbox - Built for scaling across multiple business numbers
  • Plugin System - Extensible with Redis, CORS, rate limiting, and custom plugins

๐Ÿ“ฑ Complete WhatsApp Support

  • All Message Types - Text, media, interactive buttons, lists, templates
  • Rich Interactions - Buttons, lists, call-to-action messages
  • Media Handling - Images, videos, audio, documents with automatic upload/download
  • Templates - Pre-approved business message templates

๐Ÿ†” Recipient Contract and BSUID Support

  • Stable Internal Contract - Wappa keeps the framework-facing parameter as recipient across self.messenger.send_*, API routes, and request models
  • Transport Resolution - In the WhatsApp adapter, recipient is resolved to:
    • to when the identifier is a phone number
    • recipient when the identifier is a BSUID
  • BSUID-Aware Outbound - Text, media, interactive, template, and specialized messages use the same internal recipient resolution
  • No Framework Fallback - If a message type cannot be sent via BSUID, Wappa does not automatically downgrade to phone-number transport

Important BSUID Risk

Wappa currently treats BSUID support as a transport concern, not as a delivery fallback workflow.

This means:

  • your application can keep calling send_* with recipient=... exactly as before
  • Wappa will choose the correct WhatsApp request field internally
  • but if Meta rejects a BSUID for a specific message type, Wappa will return an explicit error instead of retrying with a phone number

This is intentional for now. The fallback policy depends on each Wappa implementation because only the application knows:

  • whether a phone number is available
  • whether falling back is legally or product-wise acceptable
  • whether that specific message should be retried with a different recipient identity

If your bot needs automatic fallback, implement it in your application layer around self.messenger, your user identity store, or your delivery orchestration logic.

๐Ÿ› ๏ธ Developer Experience

# Initialize new project
wappa init my-bot

# Start development server with auto-reload
wappa dev app/main.py

# Browse interactive examples
wappa examples

๐Ÿ’พ Flexible State Management

# Memory, JSON file, or Redis caching
app = Wappa(cache="redis")  # or "memory" or "json"

# Automatic state persistence
await self.state_cache.set("conversation", {"step": "greeting"})

๐Ÿญ Factory Pattern for Cross-Platform Messages (v0.3.0)

Text, read-status, and media payloads are produced by dedicated factories (WhatsAppMessageFactory, WhatsAppMediaFactory) and consumed by WhatsAppMessenger through dependency injection. This keeps pure payload construction separate from I/O and gives you clean injection points in FastAPI routes.

# Defaults keep the library ergonomic:
messenger = WhatsAppMessenger(
    client=client,
    media_handler=media_handler,
    interactive_handler=interactive_handler,
    template_handler=template_handler,
    specialized_handler=specialized_handler,
    inbox_id=inbox_id,
)

# Or inject custom factories for advanced use cases (testing, multi-inbox extensions):
messenger = WhatsAppMessenger(
    client=client,
    # ... handlers ...
    inbox_id=inbox_id,
    message_factory=MyCustomMessageFactory(),
    media_factory=MyCustomMediaFactory(),
)

Why only text/media have factories? Interactive messages, templates, and specialized types (contact, location) are platform-specific โ€” Telegram has inline keyboards instead of WhatsApp buttons/lists, templates are WA-only, and Instagram has quick replies but no lists. Factories are reserved for concepts that truly cross platforms. Platform-specific types are owned by their corresponding handlers.

๐Ÿ“ฆ Installation

Using uv (Recommended)

# Create new project
uv init my-wappa-project
cd my-wappa-project

# Add Wappa
uv add wappa

# Initialize project structure
wappa init .

Using pip

pip install wappa

# Initialize new project
wappa init my-wappa-project
cd my-wappa-project

Using Poetry

poetry new my-wappa-project
cd my-wappa-project
poetry add wappa

# Initialize project structure  
wappa init .

๐Ÿƒโ€โ™‚๏ธ Quick Start

1. Get WhatsApp Business API Credentials

  1. Visit Meta for Developers
  2. Create a WhatsApp Business App
  3. Get your credentials:
    • Access Token
    • Phone Number ID
    • Business Account ID

2. Create Your Bot

# Initialize project
wappa init my-bot
cd my-bot

# Configure environment
cp .env.example .env
# Edit .env with your WhatsApp credentials

3. Run Development Server

# Start with auto-reload
wappa dev app/main.py

# Or manually
uv run python -m app.main

4. Test Your Bot

Send a message to your WhatsApp Business number and watch it echo back!

๐ŸŽ›๏ธ Architecture Overview

graph TD
    A[๐Ÿ‘ค WhatsApp User] -->|Message| B[๐Ÿ“ก Webhook Endpoint]
    B --> C[๐Ÿ”„ Event Dispatcher]
    C --> D[โšก Your Event Handler]
    D --> E[๐Ÿ’ฌ Messenger Interface]
    E --> F[๐Ÿ“ฑ WhatsApp API]

    D --> G[๐Ÿ’พ State Management]
    D --> H[๐Ÿง  Business Logic]
    G --> I[๐Ÿ—„๏ธ Redis/Memory/JSON Cache]
    H --> J[๐Ÿ”— External Services]

    style D fill:#333481,color:#fff,stroke:#333481,stroke-width:3px
    style E fill:#4A90E2,color:#fff,stroke:#4A90E2,stroke-width:3px
    style G fill:#333481,color:#fff,stroke:#333481,stroke-width:3px
    style A fill:#25D366,color:#fff,stroke:#25D366,stroke-width:3px
    style F fill:#25D366,color:#fff,stroke:#25D366,stroke-width:3px
  • Event-Driven: Webhook โ†’ Event Handler โ†’ Response
  • Type-Safe: Full Pydantic models for all WhatsApp data structures
  • FastAPI Core: Built on modern async Python with automatic OpenAPI docs
  • Production Ready: Docker support, Redis caching, structured logging

๐Ÿ“š Documentation

๐Ÿ“– Complete Documentation

Quick Links

Example Projects

Explore 6 complete example applications:

# Browse examples interactively
wappa examples

# Copy specific example
wappa examples redis-cache-demo
  • Simple Echo - Basic message echoing
  • JSON Cache Demo - File-based state persistence
  • Redis Cache Demo - High-performance caching
  • OpenAI Transcription - Voice message processing
  • Full-Featured Bot - Complete production example
  • Basic Project - Minimal setup template

๐Ÿ› ๏ธ Advanced Usage

Builder Pattern for Complex Apps

from wappa import WappaBuilder

app = await (WappaBuilder()
             .with_whatsapp(
                 token="your_token",
                 phone_id="your_phone_id", 
                 business_id="your_business_id"
             )
             .with_redis_cache("redis://localhost:6379")
             .with_cors_enabled()
             .with_rate_limiting(requests_per_minute=100)
             .build())

app.set_event_handler(MyAdvancedHandler())
app.run()

Plugin System

from wappa.plugins import DatabasePlugin, CorsPlugin

app = Wappa(cache="redis")
app.add_plugin(DatabasePlugin("postgresql://..."))
app.add_plugin(CorsPlugin(allow_origins=["*"]))
app.set_event_handler(MyHandler())
app.run()

CLI Commands

# Project management
wappa init [directory]          # Initialize new project
wappa examples [target]         # Browse/copy examples

# Development
wappa dev app/main.py           # Development server with auto-reload
wappa prod app/main.py          # Production server

# Help
wappa --help                    # Show all commands

๐Ÿš€ Deployment

Railway (Recommended)

# Install Railway CLI
npm install -g @railway/cli

# Login and deploy
railway login
railway init
railway add redis
railway up

# Set environment variables
railway variables set WP_ACCESS_TOKEN=your_token
railway variables set WP_PHONE_ID=your_phone_id
railway variables set WP_BID=your_business_id

See complete Railway deployment guide.

Docker

FROM python:3.12-slim

WORKDIR /app
COPY . .

RUN pip install uv
RUN uv sync --frozen

EXPOSE 8000
CMD ["uv", "run", "python", "-m", "app.main"]

๐Ÿงช Development

Setup Development Environment

# Clone repository
git clone https://github.com/sashanclrp/wappa.git
cd wappa

# Install dependencies
uv sync --group dev

# Run tests
uv run pytest

# Code formatting
uv run ruff check .
uv run ruff format .

Project Structure

wappa/
โ”œโ”€โ”€ wappa/                  # Core framework
โ”‚   โ”œโ”€โ”€ core/              # Application core & plugins
โ”‚   โ”œโ”€โ”€ messaging/         # WhatsApp messaging implementation
โ”‚   โ”œโ”€โ”€ persistence/       # Cache backends (Memory/JSON/Redis)
โ”‚   โ”œโ”€โ”€ cli/               # CLI tools & project templates
โ”‚   โ””โ”€โ”€ api/               # FastAPI routes & dependencies
โ”œโ”€โ”€ examples/              # Example applications
โ”œโ”€โ”€ docs/                  # Documentation source
โ””โ”€โ”€ tests/                # Test suite

๐Ÿค Community & Support

๐Ÿ’ฌ Join the Community

๐Ÿ“ž Get Support

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ“‹ Requirements

  • Python 3.12+ - Modern Python with latest type hints
  • WhatsApp Business API - Meta for Developers account
  • Redis (optional) - For production caching and state management

๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Meta - For the WhatsApp Business API
  • FastAPI - For the excellent async Python framework
  • Redis - For high-performance caching
  • Open Source Community - For inspiration and contributions

Built with โค๏ธ by Mimeia โ€ข Open Source โ€ข Apache 2.0 License

Transform your business communication with WhatsApp automation.

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

wappa-0.13.1.tar.gz (8.2 MB view details)

Uploaded Source

Built Distribution

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

wappa-0.13.1-py3-none-any.whl (8.3 MB view details)

Uploaded Python 3

File details

Details for the file wappa-0.13.1.tar.gz.

File metadata

  • Download URL: wappa-0.13.1.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for wappa-0.13.1.tar.gz
Algorithm Hash digest
SHA256 6a80af1d9c026736ae9439b0ec4e2b40ffe149864441d0aa1a89d7f87f2f0639
MD5 da7c307cabc0ee1c206aa199a3203863
BLAKE2b-256 138b4f040f4e61fef39ef0aad33ebea243b0e86e00b80ffc13e2cb254b23c30a

See more details on using hashes here.

File details

Details for the file wappa-0.13.1-py3-none-any.whl.

File metadata

  • Download URL: wappa-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for wappa-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e9011f3dbbbf5d075589a08fd3ae99e251792aa0782c7f37940fc7a597044ff2
MD5 8b791752d423401d00264ae8225ed22e
BLAKE2b-256 59cb24758d800ebb18944a143120420381de3b970f13051295389f7aebc2656b

See more details on using hashes here.

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