A python script for extracting WhatsApp conversations from the app's SQLite database and exporting them as HTML or txt files.
- Export WhatsApp chats to a WhatsApp Web like HTML page.
- Export WhatsApp chats to txt files (one per chat).
- Prerequisite: The Whatsapp database files must be available (see the following section).
- Supply all configuration values in
config.cfg
. Here, the paths to the database files must be given. Thewa.db
database is only needed for adding names of contacts and does not need to be used. - Run the main script:
python3 main.py
. - Open then generated HTML page (configured via
html_output_path
) with a web browser. To view media files, simply place WhatsApp'sMedia
directory to the same directory as the HTML page.
In order to export only certain chats (or to include further filtering requirements), the SQL queries in main.py
can be modified directly.
# New database format: Modify query_messages_from_table_message to filter for the chat with phone number 12345678
WHERE cv.raw_string_jid =:key_remote_jid and cv.raw_string_jid = '12345678@s.whatsapp.net'
# Old database format: Modify query_messages_from_table_messages to filter for the chat with phone number 12345678
WHERE key_remote_jid =:key_remote_jid and key_remote_jid = '12345678@s.whatsapp.net'
For retrieving the WhatsApp database files from an Android device there are several options. Two of them are described in this section.
WhatsApp stores all messages in SQLite databases in the app directory /data/data/com.whatsapp/
. These can be
downloaded to a computer using adb
, e.g. when the Android device is booted to a recovery such as TWRP
(or when the device is rooted). Copy all WhatsApp files to the local directory my_WhatsApp
using the following command.
adb pull /data/data/com.whatsapp/ my_WhatsApp/
The directory my_WhatsApp
now contains the following relevant files:
com.whatsapp/databases/msgstore.db
: The database for storing all messages.com.whatsapp/databases/wa.db
: The database for storing contacts.
It is also possible to decrypt a WhatsApp backup file. These backups are generated by WhatsApp and can be found in the
publicly accessible device storage (e.g. sdcard0/WhatsApp/Databases/msgstore.db.crypt12
).
Obviously, the decryption key (which is stored in the app's private storage) is still required. The tool
WhatsApp-Crypt12-Decrypter can be used to decrypt a backup file:
python3 decrypt12.py key msgstore.db.crypt12 msgstore.db
This project is licensed under the GNU General Public License v3.0.
This project is not endorsed or certified by WhatsApp Inc.