WAsock
wasock (WhatsApp Socket) is a lightweight Python library for interacting with WhatsApp, built on top of Baileys via a Node.js subprocess that communicates with Python over a TCP socket.
Made by an Egyptian developer 🇪🇬 — Ahmed Mohmmed-AM.
Status:
0.5.1-Beta— still under development, the API may change before a stable release.
Overview
wasock gives you a simple Python interface for WhatsApp: receiving messages, replying to them, sending new messages, deleting messages, and displaying a QR code or pairing code for login — without writing a single line of JavaScript.
wasock is a lightweight Python wrapper around Baileys. It spawns a Node.js subprocess and talks to it over a local TCP socket, so you can send, receive, reply to, and delete WhatsApp messages entirely from Python.
Requirements
- Python >= 3.8
- Node.js (>= 18 recommended)
- An internet connection to install the initial npm dependencies
Installation
pip install wasock
Quick Start
from wasock import WhatsAppSocket, Message, QRCode, Connection
bot = WhatsAppSocket(authName="auth", loggerLevel="silent")
def onQr(data):
qr = QRCode(data["qr"], bot.nodeJS, small=True, type="img", imgWidth=500)
qr.render("qr.png")
print("Scan qr.png with WhatsApp on your phone")
def onConnection(data):
conn = Connection(data)
if conn.connected:
print("Connection opened!")
else:
print(f"Connection closed: {conn.reason}")
def onMessage(data):
message = Message(data, bot.nodeJS)
if message.fromBot:
return
if message.text == "!ping":
message.reply("pong")
bot.on("login", onQr)
bot.on("connection", onConnection)
bot.on("message", onMessage)
bot.start()
try:
input("Bot is running, press Enter to exit...\n")
finally:
bot.end()
API
WhatsAppSocket(authName="auth", loggerLevel="silent")
Starts the connection to the Node server and sets up the session.
.start()— starts the actual connection to WhatsApp..on(event, callback)— registers an event listener ("login","connection","message")..requestPairingCode(phoneNumber, customPairingCode=None)— gets a pairing code for the given phone number, as an alternative to scanning a QR code.customPairingCodemust be exactly 8 uppercase letters/digits if provided..end()— closes the connection and stops the Node process.
Message
Automatically built for each incoming message. Key properties:
| Property | Description |
|---|---|
.text |
The message text |
.chat |
The chat's JID |
.fromBot |
True if the message was sent by the bot itself |
.quoted / .quotedText / .quotedSender |
The quoted message's data (if this message is a reply) |
Methods:
.reply(msg, chat=None, quoted=None)— replies to the message..send(msg, chat=None)— sends a new message (without a quote)..delete()— deletes the message (Delete for Everyone).
QRCode(data, nodeJS, small=True, type="terminal", imgWidth=500)
data: the raw QR string received from the"login"event.nodeJS: thebot.nodeJSinstance, used to send the QR to the Node server for rendering.small:Truefor a compact QR (terminal mode only),Falsefor a larger one.type:"terminal"(prints to the terminal) or"img"(saves as an image file).imgWidth: width in pixels for the generated image, only used whentype="img". Must be anint.
Methods:
.render(imgName="qr.png")— renders the QR code. Fortype="terminal", prints it directly to the terminal. Fortype="img", saves it as an image file with the given name.
Connection
.connected—True/False.statusCode— the disconnect status code (if any).reason— the disconnect reason (if any).isAuthFailure()—Trueif the reason was a 401 (a new QR code is needed)
Important Notes
- The
auth/folder contains sensitive WhatsApp session data — never commit it to GitHub. - The location of
auth/is resolved relative to the script's working directory, not the library's location.
License
MIT License — see the LICENSE file for details.
Author
Ahmed Mohmmed-AM — Egyptian developer 🇪🇬 GitHub: @Ahmed-Mohmmed-AM
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wasock-0.5.1.tar.gz.
File metadata
- Download URL: wasock-0.5.1.tar.gz
- Upload date:
- Size: 13.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a574846759fa24157f85a0bbdd870ef99271c60a06df8abc571cf64a8b4a417b
|
|
| MD5 |
ccb3cbfd6d21c74f7b16a55b8d1540a5
|
|
| BLAKE2b-256 |
07a7c436edfec93710fe37492ce6663c6f455557c03ee9252f6f36b257c96eb1
|
File details
Details for the file wasock-0.5.1-py3-none-any.whl.
File metadata
- Download URL: wasock-0.5.1-py3-none-any.whl
- Upload date:
- Size: 15.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7416cefb7dfddf66f30d4961465f8299ed5792def26f3027ebb4b5b0551b5b8c
|
|
| MD5 |
101b18d71d410ad34a8f70d2331d2f89
|
|
| BLAKE2b-256 |
a6c41a1c9d9404901961d0a52e3e085f417858a84378cfe3f528a3ea27f39295
|