Skip to main content

py-whatsapp-formatter: Python Library for WhatsApp Text Formatting

Convert Markdown and HTML to WhatsApp formatting in Python — A lightweight, zero-dependency library for bidirectional conversion between WhatsApp, Markdown, and HTML text formatting. Perfect for WhatsApp chatbots, messaging automation, WhatsApp Business API integrations, and any application that needs to format text for WhatsApp messages.

Key Features:

  • 🔄 Bidirectional conversion (to and from WhatsApp format)
  • 📝 Supports Markdown ↔ WhatsApp and HTML ↔ WhatsApp
  • 🎯 Zero dependencies, fully typed
  • ⚡ Fast and lightweight
  • 🔗 Handles nested formatting correctly

Installation

pip install py-whatsapp-formatter

Use Cases

  • WhatsApp Chatbots: Format bot responses with proper WhatsApp styling
  • WhatsApp Business API: Convert rich text to WhatsApp-compatible format
  • Content Management: Transform CMS content (HTML/Markdown) for WhatsApp
  • Message Automation: Programmatically format WhatsApp messages
  • AI Chat Integration: Convert ChatGPT/Claude markdown responses to WhatsApp format

Usage

Convert to WhatsApp Format

from whatsapp_formatter import convert_markdown_to_whatsapp, convert_html_to_whatsapp

# Convert Markdown to WhatsApp format
text = convert_markdown_to_whatsapp("**Bold** and *italic* and ~~strikethrough~~")
# Output: "*Bold* and _italic_ and ~strikethrough~"

# Convert HTML to WhatsApp format
text = convert_html_to_whatsapp("<strong>Bold</strong> <em>italic</em>")
# Output: "*Bold* _italic_"

Convert from WhatsApp Format

from whatsapp_formatter import convert_whatsapp_to_markdown, convert_whatsapp_to_html

# Convert WhatsApp to Markdown format
text = convert_whatsapp_to_markdown("*Bold* and _italic_ and ~strikethrough~")
# Output: "**Bold** and *italic* and ~~strikethrough~~"

# Convert WhatsApp to HTML format
text = convert_whatsapp_to_html("*Bold* and _italic_ and ~strikethrough~")
# Output: "<strong>Bold</strong> and <em>italic</em> and <del>strikethrough</del>"

WhatsApp Formatting Reference

Format WhatsApp Markdown HTML
Bold *text* **text** <b>, <strong>
Italic _text_ *text* <i>, <em>
Strikethrough ~text~ ~~text~~ <s>, <strike>, <del>
Monospace `text` `text` <code>
Code block ```text``` ```text``` <pre><code>

All conversions are bidirectional. Nested formatting is supported (e.g., *_bold and italic_*).

Advanced Usage

For more control, use the converter classes directly:

from whatsapp_formatter import (
    MarkdownToWhatsAppConverter,
    HTMLToWhatsAppConverter,
    WhatsAppToMarkdownConverter,
    WhatsAppToHTMLConverter,
)

# Custom Markdown converter with post-processing
converter = MarkdownToWhatsAppConverter()
converter.add_post_processor(lambda x: x.strip())
result = converter.convert("  **Hello**  ")

# HTML converter without tag stripping
converter = HTMLToWhatsAppConverter(strip_remaining_tags=False)
result = converter.convert("<b>Bold</b> <span>kept</span>")

# WhatsApp to Markdown
converter = WhatsAppToMarkdownConverter()
result = converter.convert("*bold* _italic_ ~strike~")
# Output: "**bold** *italic* ~~strike~~"

# WhatsApp to HTML (with optional line break conversion)
converter = WhatsAppToHTMLConverter(include_line_breaks=True)
result = converter.convert("*bold*\n_italic_")
# Output: "<strong>bold</strong><br>\n<em>italic</em>"

Requirements

  • Python 3.9+
  • No external dependencies

License

MIT License

Metadata

Release files for py-whatsapp-formatter 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-whatsapp-formatter 1.0.6
File Size Uploaded
py_whatsapp_formatter-1.0.6.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-whatsapp-formatter 1.0.6
File Interpreter ABI Platform
py_whatsapp_formatter-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / py_whatsapp_formatter-1.0.6.tar.gz

Download URL py_whatsapp_formatter-1.0.6.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
aedf9a437347a75a8df54ed4359725e26314504fe43c132b51026b6e2ae3ff7c
BLAKE2b-256 checksum
How to use checksums
81b8a449c5748573c0db1c8c2405a9eed3397bc713804a36718f4ed6e823dc64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / py_whatsapp_formatter-1.0.6-py3-none-any.whl

Download URL py_whatsapp_formatter-1.0.6-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
364cbe6ac39240b6031a4badc022484bcfc5e502fb4329aae91d3cf1acfe7efe
BLAKE2b-256 checksum
How to use checksums
62163415d84c907110ff8c3cb9db04d41900a9fce5ee19b15c11b97b38fd23fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page