Skip to main content

WhatsExtract API client for Python

Project description

whatsextract

WhatsExtract API client for Python — fast email/phone extraction from WhatsApp-style messages.

DocsExamplesIssues


Installation

pip install whatsextract
# Optional extras:
pip install "whatsextract[pandas]"   # DataFrame helpers
pip install "whatsextract[cli]"      # CLI: `whatsextract`

From source (editable dev):

git clone https://github.com/whatsextract/examples.git
cd examples/sdk-py
python -m venv .venv && source .venv/bin/activate
pip install -e ".[cli,pandas,dev]"

Quick start

from whatsextract import WhatsExtract

client = WhatsExtract(
    api_key="YOUR_API_KEY",
    base_url="https://whatsapp-lead-extractor-api.p.rapidapi.com",  # or your self-hosted URL
)

result = client.extract("Priya — priya@acme.com +1 415 555 0199")
print(result.email, result.phone)

Async

import asyncio
from whatsextract import WhatsExtract

async def main():
    c = WhatsExtract("YOUR_API_KEY", base_url="http://localhost:8080")
    r = await c.extract_async("Contact me: john@example.com, (555) 123-4567")
    print(r)

asyncio.run(main())

Batch

from whatsextract import WhatsExtract

c = WhatsExtract("YOUR_API_KEY", base_url="http://localhost:8080")
resp = c.batch_extract(
    ["A — a@example.com 555-0000", "B — b@example.com 555-1111"],
)
print(resp[0].email, resp[1].email)

Pandas helper (optional)

import pandas as pd
from whatsextract import WhatsExtract

df = pd.DataFrame({"msg": [
    "Hi! jane@corp.com +1 415 555 1212",
    "Rahul — rahul@contoso.io 9876543210",
]})
c = WhatsExtract("YOUR_API_KEY", base_url="http://localhost:8080")
out = c.extract_from_dataframe(df, column="msg", add_columns=True)
print(out.head())

Webhooks

Configure webhook (server must respond 2xx):

c = WhatsExtract("YOUR_API_KEY", base_url="http://localhost:8080")
resp = c.configure_webhook("https://example.com/webhook", events=["batch.completed"])
print(resp)  # {'webhook_id': 'whk_...', 'status': 'verified', ...}

Validate signature in your receiver (example Flask):

import hmac, hashlib
from flask import Flask, request, abort

app = Flask(__name__)
WEBHOOK_SECRET = "replace_me"

@app.post("/webhook")
def hook():
    sig = request.headers.get("X-WhatsExtract-Signature", "")
    body = request.data
    mac = "sha256=" + hmac.new(WEBHOOK_SECRET.encode(), body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(mac, sig):
        abort(401)
    # process json
    return {"ok": True}

Usage stats

c = WhatsExtract("YOUR_API_KEY", base_url="http://localhost:8080")
print(c.get_usage())

CLI

Install whatsextract[cli] then:

# Single extraction
whatsextract extract "Ping me at john@example.com or +1 555 123 4567"   --api-key $WE_API_KEY --base-url http://localhost:8080

# Batch from file (one message per line)
whatsextract batch messages.txt --api-key $WE_API_KEY --base-url http://localhost:8080

# Usage
whatsextract usage --api-key $WE_API_KEY --base-url http://localhost:8080

Set environment variables to avoid passing flags each time:

export WE_API_KEY="YOUR_API_KEY"
export WE_BASE_URL="http://localhost:8080"

Timeouts & retries

  • Default timeout: 30s
  • Automatic retry: up to 3 times on 429/5xx
  • Customize via constructor: WhatsExtract(..., timeout=20, max_retries=5)

Development

pip install -e ".[cli,pandas,dev]"
pytest -q

Publishing (maintainers)

python -m pip install --upgrade build twine
python -m build
twine upload dist/*

License

MIT © WhatsExtract

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whatsextract-0.1.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatsextract-0.1.1-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file whatsextract-0.1.1.tar.gz.

File metadata

  • Download URL: whatsextract-0.1.1.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for whatsextract-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4b72ea7666da8cedf8daebd853a8f5ef9c6dd4ad2a33d7e6bc80968a4caf9ff5
MD5 dc8cd70d112ffe3086e76cea977d254f
BLAKE2b-256 0fd7fd1d79b27f74068cc9e11b9015ead9a68f2396ca9232a533cfa12c52ba37

See more details on using hashes here.

File details

Details for the file whatsextract-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: whatsextract-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for whatsextract-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 235235b88f8b45b9b9c1c2ca6f5325444dd4e709ab6e4ac53bd5f8deca03a7a3
MD5 1451e343846ab3f94488cbc3d8229551
BLAKE2b-256 5a3d921279d538d0d37f27a97c04c0ecebaa73fc0b102a1c40bfa06beebe47a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page