Skip to main content

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.30.1 — WhatsApp webhook and Redis scan fixes — Wappa accepts system.previous_user_id and blank contact names in Meta webhooks, and user-namespace scans skip host mutation locks. See CHANGELOG.md.


🚀 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"})

Inbox-scoped Template transport

Embedding applications send Templates through Wappa's public runtime capability; they do not construct WhatsApp clients, handlers, sessions, or pipelines:

from wappa.messaging import (
    OutboundRuntime,
    PhoneNumberTemplateRecipient,
    TextTemplateTransportRequest,
)

transport = OutboundRuntime.from_app(fastapi_app).templates(inbox_id)
result = await transport.send(
    TextTemplateTransportRequest(
        recipient=PhoneNumberTemplateRecipient(value="573001112233"),
        template_name="welcome",
        category="utility",
    )
)

result.outcome is accepted, rejected, transport_unavailable, or indeterminate. Acceptance proves a platform Message ID, not delivery or a Host Application commit. Wappa's standalone Template HTTP routes are opt-in with Wappa(include_template_transport_api=True).

An embedding application that owns its own authenticated boundary drops Wappa's unauthenticated mutation surface with one argument:

app = Wappa(cache="redis", route_profile="embedded")

That omits every route which sends a message, deletes a media asset, or rewrites a recipient's cached state. Media upload/download/lookup, limits, validation, Template info, webhooks, health, and every wappa.messaging service stay exactly as they are. Standalone applications need no change.

🏭 Factory Pattern for Cross-Platform Messages (v0.3.0)

Text/read-status payloads and media payloads have separate owners: WhatsAppMessageFactory and WhatsAppMediaFactory. WhatsAppMessenger consumes both through dependency injection, keeping pure payload construction separate from I/O without duplicating media construction rules.

# 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

# 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:
    • App Secret (META_APP_SECRET) — Wappa verifies every webhook POST body with it; there is no development bypass
    • A verify token you choose (WP_WEBHOOK_VERIFY_TOKEN) — used only for Meta's GET challenge
    • Access Token, Phone Number ID, Business Account ID (WP_ACCESS_TOKEN, WP_PHONE_ID, WP_BID) — the legacy single-Inbox bundle
  4. Configure the one callback URL in the Meta App: https://<host>/webhook/inboxes/whatsapp

2. Create Your Bot

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

# The generated project already contains .env
# Edit .env with your 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!

Many Inboxes under one Meta App (explicit mode)

Wappa has exactly two Inbox Routing Modes and they never mix. legacy (the default) runs the single Inbox from the WP_* bundle. explicit runs any number of Inboxes through Wappa's encrypted Inbox Directory: you implement a read-only IInboxDirectorySource over your own database, Wappa owns encryption (SYSTEM_TOKEN_ENC_KEY), caching, the WABA reverse index, and Messenger eviction.

Start a Host-adapter scaffold with wappa init my-bot --inbox-routing explicit. It includes the required environment configuration and an IInboxDirectorySource stub to connect to the Host's durable Inbox records.

# Explicit mode never mixes with the legacy WP_* Inbox bundle.
SYSTEM_INBOX_ROUTING_MODE=explicit
SYSTEM_TOKEN_ENC_KEY=<Fernet key from CredentialCodec.generate_key()>
from wappa import Wappa, InboxRoutingMode

app = Wappa(
    cache="redis",
    inbox_routing=InboxRoutingMode.EXPLICIT,
    inbox_directory_source=MyInboxSource(db),   # implements IInboxDirectorySource
)

Explicit mode rejects WP_ACCESS_TOKEN, WP_PHONE_ID, and WP_BID at startup, and every Inbox-dependent /api/whatsapp/* call sends X-Wappa-Inbox-ID — a selector, not a credential; your authentication decides who may use it. The ordered setup, the credential commands, and the key-rotation runbook are in docs/migration/v0.27.0-multi-inbox.md.

🎛️ 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

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 Wappa, WappaBuilder
from wappa.core.plugins import CORSPlugin, RateLimitPlugin, RateLimitProfile, RedisPlugin

fastapi_app = (
    WappaBuilder()
    .with_inbox_routing("explicit")
    .with_inbox_directory_source(MyInboxSource(db))
    .add_plugin(RedisPlugin())
    .add_plugin(CORSPlugin(allow_origins=["*"]))
    .add_plugin(RateLimitPlugin([RateLimitProfile(name="default", limit=100, window_seconds=60)]))
    .configure(title="My Wappa App")
    .build()
)

app = Wappa()
app.set_app(fastapi_app)
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

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

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

# Set environment variables (legacy single-Inbox mode)
railway variables set META_APP_SECRET=your_meta_app_secret
railway variables set WP_WEBHOOK_VERIFY_TOKEN=your_verify_token
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.

Release files for wappa 0.30.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wappa 0.30.1
File Size Uploaded
wappa-0.30.1.tar.gz 8.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for wappa 0.30.1
File Interpreter ABI Platform
wappa-0.30.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 MB

Release files / wappa-0.30.1.tar.gz

Download URL wappa-0.30.1.tar.gz
Size 8.7 MB
Tags Source
SHA-256 checksum
How to use checksums
635837b56a6aa5865f3af638dbf812c9df1b938c17bfd8eae9fc032fa4b558b4
BLAKE2b-256 checksum
How to use checksums
92ba54e0004e73311c621d6a00a3e712fb7b3331692b2a9c26440ef7c6a52b26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.20 {"installer":{"name":"uv","version":"0.12.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / wappa-0.30.1-py3-none-any.whl

Download URL wappa-0.30.1-py3-none-any.whl
Size 8.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4688d7028a65dd2721aab2685c058c20f16830c128d6f1d1791af7e6286b6bf7
BLAKE2b-256 checksum
How to use checksums
97e6b466938eb8299e87d3b4f60e28fca9ffb7f43680a59a6bba854ae034468a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.20 {"installer":{"name":"uv","version":"0.12.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.30.1 This release

2 release files

0.30.0

2 release files

0.29.0

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.26.3

2 release files

0.26.2

2 release files

0.23.1

2 release files

0.23.0

2 release files

0.22.1

2 release files

0.22.0

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.17.4

2 release files

0.17.2

2 release files

0.17.1

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.0

2 release files

0.13.6

2 release files

0.13.5

2 release files

0.13.4

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.32

2 release files

0.2.30

2 release files

0.2.28

2 release files

0.2.27

2 release files

0.2.26

2 release files

0.2.25

2 release files

0.2.24

2 release files

0.2.23

2 release files

0.2.22

2 release files

0.2.21

2 release files

0.2.20

2 release files

0.2.17

2 release files

0.2.16

2 release files

0.2.15

2 release files

0.2.14

2 release files

0.2.13

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page