Git Product home page Git Product logo

pywa's Introduction

PyWa Logo


PyWa โ€ข Python wrapper for the WhatsApp Cloud API

PyPi Downloads PyPI Version Tests Docs License CodeFactor Telegram


PyWa is a Fast, Simple, Modern and easy-to-use Python framework for building WhatsApp bots using the WhatsApp Cloud API.

๐Ÿ“„ Quick Documentation Index

Get Started โ€ข WhatsApp Client โ€ข Handlers โ€ข Filters โ€ข Updates โ€ข Flows โ€ข Examples


โšก Features

  • ๐Ÿš€ Fast and simple to use. No need to worry about the low-level details.
  • ๐Ÿ’ฌ Send text messages with interactive keyboards, images, videos, documents, audio, locations, contacts, etc.
  • ๐Ÿ“ฉ Receive messages, callbacks, message status updates, etc.
  • โ™ป๏ธ Create, send and listen to Flows (NEW!)
  • ๐Ÿ”„ Built-in support for webhooks (Flask, FastAPI, etc.)
  • ๐Ÿ”ฌ Filters for handling incoming updates
  • ๐Ÿ“„ Send and create templates
  • โœ… Fully typed, documented and tested

๐Ÿ‘จโ€๐Ÿ’ป Usage

  • Create a WhatsApp client and send a message

See Getting Started for more information.

from pywa import WhatsApp

wa = WhatsApp(
    phone_id="100458559237541",
    token="EAAEZC6hUxkTIB"
)

wa.send_message(
    to="9876543210",
    text="Hello from PyWa!"
)
  • To listen to updates, create a WhatsApp client, pass a web server app (Flask in this example) and register callbacks:

See Handlers for more information.

from pywa import WhatsApp, filters
from pywa.types import Message, CallbackButton, Button
from flask import Flask

flask_app = Flask(__name__)
wa = WhatsApp(
    phone_id="1234567890",
    token="xxxxxxx",
    server=flask_app,
    callback_url="https://xyz.ngrok-free.app",
    verify_token="xyz123",
    app_id=123456,
    app_secret="yyyyyy"
)

@wa.on_message(filters.matches("Hello", "Hi"))
def hello(client: WhatsApp, msg: Message):
    msg.react("๐Ÿ‘‹")
    msg.reply_text(
        text=f"Hello {msg.from_user.name}!",
        buttons=[
            Button(
                title="Click me!",
                callback_data="id:123"
            )
        ]
    )

@wa.on_callback_button(filters.startswith("id"))
def click_me(client: WhatsApp, clb: CallbackButton):
    clb.reply_text("You clicked me!")

flask_app.run()  # Run the flask app to start the server

๐ŸŽ› Installation

  • Install using pip3:
pip3 install -U pywa
  • Install from source (the bleeding edge):
pip3 install -U git+https://github.com/david-lev/pywa.git
  • If you going to use the webhook features, here is shortcut to install the required dependencies:
pip3 install -U "pywa[flask]"
pip3 install -U "pywa[fastapi]"
  • If you going to use the Flow features and want to use the default FlowRequestDecryptor and the default FlowResponseEncryptor, here is shortcut to install the required dependencies:
pip3 install -U "pywa[cryptography]"

๐Ÿ’พ Requirements

๐Ÿ“– Setup and Usage

See the Documentation for detailed instructions

โ˜‘๏ธ TODO

  • Add support for async
  • Add support for more web frameworks (Django, Starlette, etc.)
  • Add support for more types of updates (account_alerts, phone_number_quality_updates, template_category_updates, etc.)
  • Add more examples and guides

Feel free to open an issue if you have any suggestions. or even better - submit a PR!

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details

๐Ÿ”ฑ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

pywa's People

Contributors

david-lev avatar yehuda-lev avatar pre-commit-ci[bot] avatar shlomocode avatar

Stargazers

 avatar ishai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.