Reference¶
Auto-generated from the source docstrings, grouped to mirror the R package's reference index.
Client¶
Create and configure the API client.
evolution_api.EvoClient
¶
Bases: _BaseClient, MessagesMixin, NumbersMixin, InstanceMixin
Synchronous Evolution API v2 client.
Equivalent to the R package's evo_client(): holds base_url,
api_key and instance, sets the apikey header and a custom
User-Agent, and retries transient failures automatically.
Example
client = EvoClient( ... base_url="https://my-host", ... api_key="...", # or via the EVO_APIKEY env var ... instance="myInstance", ... ) client.send_text("5581999990000", "Hello from Python!") # doctest: +SKIP
Source code in src/evolution_api/client.py
evolution_api.AsyncEvoClient
¶
Bases: _BaseClient, MessagesMixin, NumbersMixin, InstanceMixin
Asynchronous Evolution API v2 client.
Exposes every method of :class:EvoClient, but each is awaitable::
async with AsyncEvoClient(base_url, api_key, instance) as client:
await client.send_text("5581999990000", "Hello!")
Source code in src/evolution_api/client.py
Send messages¶
Functions to send different types of WhatsApp messages. All are methods on
EvoClient / AsyncEvoClient.
All send_* endpoints under message/<endpoint>/<instance>.
Source code in src/evolution_api/messages.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
send_text
¶
send_text(number: str, text: str, *, delay: int | None = None, link_preview: bool | None = None, mentions_everyone: bool | None = None, mentioned: list[str] | None = None, quoted: dict[str, Any] | None = None, verbose: bool | None = None) -> Any
Send a plain text WhatsApp message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Recipient with country code ( |
required |
text
|
str
|
Message body. |
required |
delay
|
int | None
|
Optional presence delay in milliseconds (simulates typing). |
None
|
link_preview
|
bool | None
|
Enable URL link preview. |
None
|
mentions_everyone
|
bool | None
|
Mention everyone in a group. |
None
|
mentioned
|
list[str] | None
|
JIDs to mention (e.g. |
None
|
quoted
|
dict[str, Any] | None
|
Baileys message |
None
|
verbose
|
bool | None
|
Override the client's verbose setting for this call. |
None
|
Source code in src/evolution_api/messages.py
send_status
¶
send_status(type: StatusType, content: str, *, caption: str | None = None, background_color: str | None = None, font: int | None = None, all_contacts: bool = False, status_jid_list: list[str] | None = None, verbose: bool | None = None) -> Any
Post a WhatsApp status (story): text or media.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
StatusType
|
One of |
required |
content
|
str
|
Text (for |
required |
caption
|
str | None
|
Optional caption for media types. |
None
|
background_color
|
str | None
|
Hex colour for a text status (e.g. |
None
|
font
|
int | None
|
Integer font id (0-14). |
None
|
all_contacts
|
bool
|
If |
False
|
status_jid_list
|
list[str] | None
|
Specific JIDs to receive the status. |
None
|
Source code in src/evolution_api/messages.py
send_media
¶
send_media(number: str, mediatype: MediaType, mimetype: str, media: str, file_name: str, *, caption: str | None = None, delay: int | None = None, link_preview: bool | None = None, verbose: bool | None = None) -> Any
Send an image, video, or document.
media is flexible: an HTTP(S) URL, a local file path (auto-encoded to
base64, ~ expanded), raw base64, or a data:*;base64, URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Recipient with country code. |
required |
mediatype
|
MediaType
|
One of |
required |
mimetype
|
str
|
e.g. |
required |
media
|
str
|
URL, file path, base64, or data-URI. |
required |
file_name
|
str
|
Suggested filename for the recipient (match the MIME type). |
required |
caption
|
str | None
|
Optional caption displayed with the media. |
None
|
Source code in src/evolution_api/messages.py
send_whatsapp_audio
¶
send_whatsapp_audio(number: str, audio: str, *, delay: int | None = None, quoted: dict[str, Any] | None = None, verbose: bool | None = None) -> Any
Send a voice note (push-to-talk).
audio accepts a URL, base64, or a local file path (~ expanded,
auto-encoded to base64).
Source code in src/evolution_api/messages.py
send_sticker
¶
send_sticker(number: str, sticker: str, *, delay: int | None = None, verbose: bool | None = None) -> Any
Send a sticker.
sticker accepts a URL, base64, or a local file path (~ expanded,
auto-encoded to base64).
Source code in src/evolution_api/messages.py
send_location
¶
send_location(number: str, latitude: float, longitude: float, *, name: str | None = None, address: str | None = None, verbose: bool | None = None) -> Any
Send a geographic location pin.
Source code in src/evolution_api/messages.py
send_contact
¶
send_contact(number: str, contact: dict[str, Any] | list[dict[str, Any]], *, verbose: bool | None = None) -> Any
Send one or more contacts (the wuid field is auto-generated).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Recipient with country code. |
required |
contact
|
dict[str, Any] | list[dict[str, Any]]
|
A single contact dict ( |
required |
Source code in src/evolution_api/messages.py
send_reaction
¶
React to a message with an emoji.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
dict[str, Any]
|
|
required |
reaction
|
str
|
Emoji string; use |
required |
Source code in src/evolution_api/messages.py
send_buttons
¶
send_buttons(number: str, title: str, description: str, footer: str, buttons: list[dict[str, Any]], *, delay: int | None = None, link_preview: bool | None = None, mentions_everyone: bool | None = None, verbose: bool | None = None) -> Any
Send a message with interactive buttons.
Warning
Interactive buttons are not supported on the Baileys connector and
may be discontinued; this works on the Cloud API connector only. A
:class:UserWarning is emitted. Consider :meth:send_poll instead.
Source code in src/evolution_api/messages.py
send_poll
¶
send_poll(number: str, name: str, values: list[str], *, selectable_count: int = 1, verbose: bool | None = None) -> Any
Send a poll (question with selectable options).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Recipient with country code. |
required |
name
|
str
|
Question text. |
required |
values
|
list[str]
|
Poll options (minimum 2). |
required |
selectable_count
|
int
|
How many options a user may select (default 1). |
1
|
Source code in src/evolution_api/messages.py
send_list
¶
send_list(number: str, title: str, description: str, button_text: str, sections: list[dict[str, Any]], *, footer: str = '', delay: int | None = None, verbose: bool | None = None) -> Any
Send an interactive list message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
Recipient with country code. |
required |
title
|
str
|
List message title. |
required |
description
|
str
|
List body text. |
required |
button_text
|
str
|
Text on the list button (e.g. |
required |
sections
|
list[dict[str, Any]]
|
Section dicts, each |
required |
footer
|
str
|
Footer text. Defaults to |
''
|
Warning
Interactive lists are not supported on the Baileys connector and
may be discontinued; this works on the Cloud API connector only. A
:class:UserWarning is emitted. Consider :meth:send_poll instead.
Source code in src/evolution_api/messages.py
Chat utilities¶
Query and verify WhatsApp numbers, and build JIDs.
check_is_whatsapp / check_numbers — both hit chat/whatsappNumbers.
Source code in src/evolution_api/numbers.py
check_is_whatsapp
¶
Verify whether phone numbers are registered on WhatsApp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
numbers
|
list[str] | tuple[str, ...]
|
Phone numbers with country code (e.g. |
required |
verbose
|
bool | None
|
Override the client's verbose setting for this call. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The parsed API response indicating which numbers are registered. |
Source code in src/evolution_api/numbers.py
check_numbers
¶
Alias for :meth:check_is_whatsapp.
Instance-controller endpoints. New vs. the R package (R is send-only).
Source code in src/evolution_api/instance.py
connection_state
¶
Return the channel connection state (health check).
Calls GET /instance/connectionState/{instance}. The response contains
instance.instanceName and instance.state (e.g. "open",
"connecting", "close").
Source code in src/evolution_api/instance.py
evolution_api.jid
¶
Build a WhatsApp JID from a raw phone number.
Strips every non-digit character (including a leading +) and appends
@s.whatsapp.net. Port of the R jid(); like the R version it is
vectorized — pass an iterable to get a list back.
Examples:
>>> jid("+55 81 99999-0000")
'5581999990000@s.whatsapp.net'
>>> jid(["+5581999990000", "5511988887777"])
['5581999990000@s.whatsapp.net', '5511988887777@s.whatsapp.net']
Source code in src/evolution_api/numbers.py
Receiving (webhooks)¶
evolution_api.webhooks.parse_webhook
¶
Parse a webhook POST body into the most specific event model available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
The decoded JSON body of the webhook request. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
BaseEvent
|
class: |
BaseEvent
|
or — for any other event — a :class: |
|
BaseEvent
|
be matched on, and :attr: |
Raises:
| Type | Description |
|---|---|
EvolutionConfigError
|
If |
Source code in src/evolution_api/webhooks/parse.py
evolution_api.webhooks.fastapi.webhook_router
¶
Build an APIRouter that receives Evolution webhooks and calls handler.
Mount it on an existing FastAPI app::
from fastapi import FastAPI
from evolution_api.webhooks import parse_webhook # noqa: F401
from evolution_api.webhooks.fastapi import webhook_router
async def on_event(event):
if event.event_type == "MESSAGES_UPSERT":
print(event.data.key.remote_jid, event.data.message)
app = FastAPI()
app.include_router(webhook_router(on_event))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
EventHandler
|
Called with the parsed :class: |
required |
path
|
str
|
Route path for the POST endpoint (default |
'/webhook'
|
Returns:
| Type | Description |
|---|---|
APIRouter
|
A FastAPI |
Source code in src/evolution_api/webhooks/fastapi.py
evolution_api.webhooks.dataframe.as_dataframe
¶
Turn parsed webhook events into a pandas DataFrame.
Each event becomes a row. MESSAGES_UPSERT events are flattened into the
useful columns (remote_jid, from_me, message_id, push_name,
message_type, message_timestamp, text); other event types fill
only the common columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
Iterable[BaseEvent]
|
Any iterable of parsed events (e.g. from :func: |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A |
Source code in src/evolution_api/webhooks/dataframe.py
Event models¶
Pydantic v2 models for Evolution API v2 webhook events.
Evolution delivers events as an HTTP POST with a common envelope (event,
instance, data and some metadata). Event names arrive dotted and
lowercase in the payload (messages.upsert) but MESSAGES_UPSERT in
configuration — both are accepted; :attr:BaseEvent.event_type normalizes to the
UPPER_SNAKE form. Unknown events still parse as :class:GenericEvent so a
handler never crashes on a new event type.
MessageKey
¶
Bases: BaseModel
The Baileys message key identifying a message.
Source code in src/evolution_api/webhooks/models.py
MessageData
¶
Bases: BaseModel
data payload of a MESSAGES_UPSERT event.
Source code in src/evolution_api/webhooks/models.py
ConnectionData
¶
Bases: BaseModel
data payload of a CONNECTION_UPDATE event.
Source code in src/evolution_api/webhooks/models.py
QrcodeData
¶
BaseEvent
¶
Bases: BaseModel
Common webhook envelope shared by every event.
Source code in src/evolution_api/webhooks/models.py
event_type
property
¶
The event name normalized to UPPER_SNAKE (e.g. MESSAGES_UPSERT).
MessagesUpsert
¶
ConnectionUpdate
¶
QrcodeUpdated
¶
GenericEvent
¶
normalize_event_name
¶
Errors¶
evolution_api.EvolutionError
¶
evolution_api.EvolutionConfigError
¶
Bases: EvolutionError, ValueError
Invalid client configuration or argument.
Raised up front by the client constructor and send_* validation,
mirroring the R package's .assert_scalar_string() / cli_abort checks.
Source code in src/evolution_api/exceptions.py
evolution_api.EvolutionConnectionError
¶
Bases: EvolutionError
A network/connection error occurred before an HTTP response was received.
evolution_api.EvolutionAPIError
¶
Bases: EvolutionError
The Evolution API returned an HTTP error status (>= 400).
Attributes:
| Name | Type | Description |
|---|---|---|
status |
The HTTP status code. |
|
api_message |
The message extracted from the response body
( |
|
body |
The parsed response body ( |
|
path |
The request path that failed, e.g. |