Skip to main content

wa_me

A modern, easy to use, feature-rich ready API wrapper for WhatsApp Business Cloud written in Python.

Features

Installing

Stable release

To install wa_me, run this command in your terminal:

$ pip install wa_me

This is the preferred method to install wa_me, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for wa_me can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/leandcesar/wa_me

Or download the tarball:

$ curl -OJL https://github.com/leandcesar/wa_me/tarball/master

Once you have a copy of the source, you can install it with:

$ python setup.py install

Quick Example

Mirror Bot

from wa_me import Bot, Ctx

class MirrorBot(Bot):
    def before_event_message(self, ctx: Ctx):
        ctx.read()

    def on_event_message_audio(self, ctx: Ctx):
        ctx.send_audio(ctx.message.audio.id)

    def on_event_message_document(self, ctx: Ctx):
        ctx.send_document(
            ctx.message.document.id,
            caption=ctx.message.document.caption,
        )

    def on_event_message_image(self, ctx: Ctx):
        ctx.send_image(
            ctx.message.image.id,
            caption=ctx.message.image.caption,
        )

    def on_event_message_location(self, ctx: Ctx):
        ctx.send_location(
            latitude=ctx.message.location.latitude,
            longitude=ctx.message.location.longitude,
            address=ctx.message.location.address,
            name=ctx.message.location.name,
        )

    def on_event_message_sticker(self, ctx: Ctx):
        ctx.send_sticker(ctx.message.sticker.id)

    def on_event_message_text(self, ctx: Ctx):
        ctx.send_text(ctx.message.text.body)

    def on_event_message_video(self, ctx: Ctx):
        ctx.send_video(
            ctx.message.video.id,
            caption=ctx.message.video.caption,
        )

Run using Flask

from flask import Flask, request
from wa_me import Bot

app = Flask(__name__)
bot = Bot()
bot.start(phone_id="PHONE_ID", token="ACCESS_TOKEN")

@app.get("/")
async def ping():
    if request.args.get("hub.verify_token") == "VERIFY_TOKEN":
        return request.args.get("hub.challenge")
    return "Invalid verify token"

@app.post("/")
def root():
    data = request.get_json()
    bot.handle(data)
    return "Success"

Run using Fast API

from fastapi import FastAPI, Request
from wa_me import Bot

app = FastAPI()
bot = Bot()
bot.start(phone_id="PHONE_ID", token="ACCESS_TOKEN")

@app.get("/")
async def ping(
    token: str = Query(alias="hub.verify_token"),
    challenge: str = Query(alias="hub.challenge"),
):
    if token == VERIFY_TOKEN:
        return challenge
    return "Invalid verify token"

@app.post("/")
async def root(request: Request):
    data = await request.json()
    bot.handle(data)
    return "Success"

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2022-12-25)

  • First release on PyPI.

  • Implement data classes and converters with dacite.

  • Implement HTTP and Client.

  • Implement Bot and Ctx.

  • Implement TTLDict.

  • Implement Routine.

  • Add docs.

  • Add examples.

Metadata

Release files for wa-me 0.1.0

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

Source distribution (sdist)

Source distribution for wa-me 0.1.0
File Size Uploaded Provenance Actions
wa_me-0.1.0.tar.gz 71.0 kB Without provenance Details for wa_me-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wa-me 0.1.0
File Interpreter ABI Platform Actions
wa_me-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for wa_me-0.1.0-py2.py3-none-any.whl

Total release size: 75.0 kB

Release files / wa_me-0.1.0.tar.gz

Download URL wa_me-0.1.0.tar.gz
Size 71.0 kB
Tags Source
SHA-256 checksum
How to use checksums
deaa5a82076d9873849c73e5db94303ebc6c9288b468a308bde8f9b2e9ec0358
BLAKE2b-256 checksum
How to use checksums
e0c381709ce6e68f93fec4f90d5c0d1988658a2e3b0880e859753a965a4a7ee8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.9.2 requests/2.28.1 setuptools/44.0.0 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.10

Release files / wa_me-0.1.0-py2.py3-none-any.whl

Download URL wa_me-0.1.0-py2.py3-none-any.whl
Size 3.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
3fc1d653153f9a14bb505439737c2030f799a6f9797d068cd62d8c4820703a97
BLAKE2b-256 checksum
How to use checksums
c1b24e5adb2bf1e18621968b53e5eb2e03f9cb6e0fe42c0d189e99d5ded341ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.9.2 requests/2.28.1 setuptools/44.0.0 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.8.10

Security for wa-me 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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