Skip to main content

WhatsApp Cloud API is complicated, Twilio is expensive, PyGwan is the opposite of both. Free & Intuitive! ~ Tarmica Chiwara.

Project description

Pygwan

Unofficial Python wrapper for the WhatsApp Cloud API by Tarmica Chiwara.

Installation

To install the WhatsApp Python wrapper, use the following command:

pip install pygwan

Usage

Import the WhatsApp class from the package and initialize an instance with your WhatsApp token and phone number ID:

from pygwan import WhatsApp

whatsapp = WhatsApp(token="your_token", phone_number_id="your_phone_number_id")

Sending a Message

You can send a text message to a WhatsApp user using the send_message method:

whatsapp.send_message("Hello, this is a test message.", "recipient_phone_number")

Replying to a Message

Reply to a message using the reply_to_message method:

whatsapp.reply_to_message("message_id", "recipient_phone_number", "Reply message.")

Sending a Template

Send a template message using the send_template method:

components = [
    # List of template components
    # Example: {"type": "text", "text": "Hello, this is a template message."}
]
whatsapp.send_template("template_name", "recipient_phone_number", components)

Sending a Location

Send a location message using the send_location method:

whatsapp.send_location("-23.564", "-46.654", "Location Name", "Location Address", "recipient_phone_number")

Sending an Image

Send an image message using the send_image method:

image_link = "https://example.com/image.jpg"
whatsapp.send_image(image_link, "recipient_phone_number")

LATEST NOTES:

Here's what changed and why: The rabbit 🐇 — human_reply

wa.human_reply(message_id, "263779281345", "Sure, let me check that for you!")
  • One call does: read receipt → typing bubble → 1.5s pause → reply. Your bot instantly feels like a person. For even more realism, use a length-aware delay:
delay=len(response_text) * 0.03  # ~30ms per character

Template improvements

wa.send_simple_template("hello_world", "263779281345")           # static templates

wa.send_flow_template("agentd", "263779281345")                  # flow templates, zero config

wa.send_flow_template("onboarding", "263779281345",              # flow + variables
    body_variables=["Alice"], flow_token="sess-123")
  • TemplateComponents builder for anything more complex — chainable, readable, no raw dicts:
components = (
    TemplateComponents()
    .add_header("Invoice #1023")
    .add_body("Alice", "shipped")
    .add_flow_button()
    .add_quick_reply_button("CONFIRM")
    .build()
)
wa.send_template("order_update", "263779281345", components)
  • Also quietly fixed:

send_templatev2 was calling send_template without self, get_message now also handles list_reply, and create_button is kept as an alias so nothing breaks.

For more detailed usage and information, please refer to the official documentation in the code lol

License

This project is licensed under the MIT License.

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

pygwan-0.3.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

pygwan-0.3.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file pygwan-0.3.2.tar.gz.

File metadata

  • Download URL: pygwan-0.3.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pygwan-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6e128dd71950d50549138c48d679e6a68050d15b32f4635953baee3c5c8b51b4
MD5 0d6ee908cfba2a271b8d8633b9c1133c
BLAKE2b-256 e4e9fb3892ec6431fd6f6b50e868b21bbaa7d32f6d644acba0edad96e107c883

See more details on using hashes here.

File details

Details for the file pygwan-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pygwan-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for pygwan-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb002de0fff967aae03379832034906b833d1fc70b1c4b65368b6d14456f316
MD5 de956514ae0fa0d9fe65c75addffb735
BLAKE2b-256 ac3dd89752ea9c91e6119e1c7edde0668be238ea87e7ab272359e710f3eba106

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