AleSZanello/whatsmac-reader
حول
Read your WhatsApp Desktop chats on macOS from the local SQLite database. Read-only, zero dependencies, CLI + Python API.
البيانات والتحليلاتالنمو المقاس للنجوم
- خلال 24 ساعة
- ٠
- خلال 7 أيام
- جارٍ جمع السجل
- خلال 15 يومًا
- جارٍ جمع السجل
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلWhatsMac Reader
Read your WhatsApp chats on macOS straight from WhatsApp Desktop's local database.
- Read-only. It never opens WhatsApp's file: it reads a temporary copy and deletes it.
- No API, no bot inside WhatsApp, no QR pairing. It only reads what WhatsApp Desktop already stored on your Mac, and it never sends anything.
whatsmac replyopens a chat with your text typed in, and you press Enter. - Zero dependencies. Python 3.9+ standard library, so the Python that ships with macOS works.
- Made to build on. A CLI with JSON output for scripts and cron jobs, plus a small Python API. Clone it, fork it, adapt it.
$ whatsmac new --chat "Book Club"
[Book Club] 2026-01-31 18:02 Alice Example: Are we still on for Thursday?
[Book Club] 2026-01-31 18:05 Bob Example: [image] chapter 4 notes
How it works
WhatsApp Desktop for Mac keeps your messages in a Core Data SQLite database:
~/Library/Group Containers/group.net.whatsapp.WhatsApp.shared/ChatStorage.sqlite
Each time whatsmac reads, it:
- copies
ChatStorage.sqlitetogether with its-waland-shmfiles (the newest messages usually live in the-wal) into a private temporary folder (0700); - checks that the tables and columns it needs are still there, and stops with a clear error if WhatsApp changed them;
- queries the copy, then deletes it, even if something fails.
Contact names for group members come from WhatsApp's own address book (ContactsV2.sqlite, same folder), read the same way.
Requirements
- macOS with WhatsApp Desktop installed, signed in and synced (the native app from the Mac App Store or whatsapp.com).
- Python 3.9+.
/usr/bin/python3is enough. - Full Disk Access for whatever runs
whatsmac, because macOS protects other apps' data: System Settings → Privacy & Security → Full Disk Access, then add your terminal app. For unattended runs (cron, launchd), the app or binary that launches it needs it instead.
Install
pipx install git+https://github.com/AleSZanello/whatsmac-reader
# or: uv tool install git+https://github.com/AleSZanello/whatsmac-reader
Or run it from a clone, with no install at all:
git clone https://github.com/AleSZanello/whatsmac-reader
cd whatsmac-reader
python3 -m whatsmac doctor
Usage
whatsmac doctor # can I read the database? schema OK? when was the last sync?
whatsmac chats # most recent chats (--all adds archived, --limit 0 shows all)
whatsmac chats --search club # filter by name or number (case and accents don't matter)
whatsmac read "Book Club" # last 50 messages of a chat
whatsmac read alice --since 2d # since: 30m, 6h, 2d, 1w, 2026-01-31, 2026-01-31T09:00
whatsmac read 15550000001 --limit 0 # a chat by phone number or jid, every message
whatsmac new # what arrived since the last `new`, across all chats
whatsmac new --chat "Book Club" --chat alice # ... only in these chats
whatsmac reply alice "See you at 8?" # open the chat with the reply typed in; you press Enter
Chats are matched by full name first, then by part of the name, phone number or jid. If a name matches more than one chat, you get the list of matches instead of a guess.
Add --json to chats, read or new to get one JSON object per line (JSON Lines):
{"id": 81234, "chat_jid": "[email protected]", "chat_name": "Book Club", "is_group": true, "at": "2026-01-31T18:05:12-03:00", "ts": 1769893512, "from_me": false, "sender": "Bob Example", "sender_jid": "[email protected]", "kind": "image", "text": "chapter 4 notes"}
kind is text, image, video, audio, document, link, sticker, gif, contact, location, poll, or type-N for types nobody has mapped yet. text is the message text, or the caption for media. System notices (encryption banners, group events, deleted messages) are skipped.
Use --db PATH or the WHATSMAC_DB environment variable to read a different copy of the database.
Replying
whatsmac reply takes you to a chat with your reply already typed. It never presses Enter: you read it, edit it if needed, and send it yourself.
whatsmac reply alice "See you at 8?" # opens the chat with the text in the message box
whatsmac reply "Book Club" "Count me in" # groups: copies the text and brings WhatsApp to the front
whatsmac reply alice # just open the chat
whatsmac reply "+1 555 000 0001" "Hi!" # any number with country code, even with no chat yet
echo "a draft from your script" | whatsmac reply alice -
whatsmac reply alice "See you at 8?" --dry-run # print the link instead of opening it
One-to-one chats open through WhatsApp's whatsapp://send?phone=<number>&text=<text> link. Most chats are now identified by LID instead of by phone number; for those, the number comes from WhatsApp's LID.sqlite or its address book. No link opens a group, so for groups (and the rare contact without a known number) the text goes to the clipboard: open the chat, press Cmd+V, then Enter.
The chat_jid from whatsmac new --json works as the chat argument, so a script can hand you a draft for a specific message without guessing names.
Building a bot
whatsmac new is meant for a job that runs every few minutes. It keeps a small state file (default ~/.local/state/whatsmac/state.json, or set it with --state) with the last message it returned from each chat, so each run prints only what's new. The first time it sees a chat it looks back 24 hours (--first-hours). Use --peek to look without moving the state forward.
# every 10 minutes, append new messages from two chats to a log
*/10 * * * * /usr/local/bin/whatsmac new --chat "Book Club" --chat alice --json >> ~/whatsapp-new.jsonl
Don't poll every few seconds: each read copies the whole database, which can be hundreds of MB.
Two examples to start from:
examples/poll.py: a polling loop in Python that hands each new message to ahandle()function you replace (notify, forward, store...). It saves the state only afterhandle()succeeds, so a crash doesn't lose messages.examples/llm_digest.sh: sends what's new in a chat to an LLM CLI and prints a summary plus what needs a reply.
Treat message text as untrusted input. Anyone who can message you controls it. If you pass it to an LLM, say in the prompt that it's data, not instructions, and don't give that model tools or the power to send messages. A human should approve anything that goes back out.
Python API
import whatsmac
with whatsmac.snapshot() as snap: # copies the database; deleted when the block ends
for chat in whatsmac.list_chats(snap)[:5]:
print(chat.name, chat.unread)
chat = whatsmac.find_chat(snap, "Book Club")
for msg in whatsmac.read_messages(snap, chat, limit=20):
print(msg.sender, msg.kind, msg.text)
state = whatsmac.load_state("bot-state.json")
new, state = whatsmac.read_new(snap, [chat], state)
plan = whatsmac.plan_reply(snap, chat, "Count me in") # plan.url, or plan.reason if no link opens it
# ... handle `new`, then:
whatsmac.save_state("bot-state.json", state)
whatsmac.open_reply(plan) # opens WhatsApp; you press Enter
Every error derives from whatsmac.WhatsMacError: DatabaseNotFound, AccessDenied, SchemaChanged, ChatNotFound. The CLI exits with 1 for errors and 2 when the schema changed.
Notes on the database
None of this is documented by WhatsApp. It's what the Mac app stores today, and it can change with any update. whatsmac doctor checks the exact tables and columns this code uses.
| Table | What's in it |
|---|---|
ZWACHATSESSION |
One row per chat. ZCONTACTJID, ZPARTNERNAME (contact or group name), ZSESSIONTYPE (0 one-to-one, 1 group, others are broadcast lists and status), ZARCHIVED, ZHIDDEN, ZREMOVED, ZUNREADCOUNT, ZLASTMESSAGEDATE |
ZWAMESSAGE |
One row per message. ZCHATSESSION → chat, ZTEXT, ZISFROMME, ZMESSAGEDATE, ZMESSAGETYPE, ZGROUPMEMBER → sender in groups, ZMEDIAITEM → attachment |
ZWAGROUPMEMBER |
Group senders: ZMEMBERJID, ZCONTACTNAME, ZFIRSTNAME |
ZWAPROFILEPUSHNAME |
The name people set for themselves (ZJID → ZPUSHNAME) |
ZWAMEDIAITEM |
Attachments; ZTITLE holds the caption (or a link's page title) |
Some quirks you'll hit if you write your own queries:
- Dates count from 2001-01-01, not 1970 (Core Data's epoch). Add
978307200to get Unix time. - Message types seen so far:
0text,1image,2video,3audio,4contact,5location,7link,8document,11gif,15sticker,46poll.6,10and14are group events, system notices and deleted messages. - jids:
<number>@s.whatsapp.netfor people,<id>@g.usfor groups, and<id>@lidfor the newer privacy IDs that hide the phone number.ContactsV2.sqlitemaps LIDs to names, andLID.sqlite(tableZWAZACCOUNT:ZIDENTIFIER→ZPHONENUMBER) maps them to phone numbers. - WhatsApp re-syncs old history under new row ids. To avoid replaying it,
read_newignores messages dated more than a day before the last one it returned from that chat. - If the newest message is many hours old, WhatsApp Desktop isn't syncing. Open it.
Limitations
- macOS only, and only what WhatsApp Desktop has synced to this Mac.
- It doesn't export media files (you get the kind and caption), transcribe voice notes, or decode reactions, edits or poll options.
- Unknown message types come out as
type-Nwith whatever text they carry.
Privacy
Your chats contain other people's messages. whatsmac keeps everything local and never logs message text, but whatever you pipe its output into (an API, a log, an LLM) is up to you. Read only your own data, on your own Mac.
Development
python3 -m unittest discover -s tests
The tests build a synthetic WhatsApp database with invented data. They never touch the real one.
License
MIT. Not affiliated with, endorsed by or connected to WhatsApp or Meta. "WhatsApp" is a trademark of WhatsApp LLC.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…