Media#
- class pywa.types.media.Image#
Represents an received image.
- class pywa.types.media.Video#
Represents a video.
- class pywa.types.media.Audio#
Represents an audio.
- class pywa.types.media.Document#
Represents a document.
- class pywa.types.media.Sticker#
Represents a sticker.
Every media type has the following properties and methods:
- BaseMedia.download(path: str | None = None, filename: str | None = None, in_memory: bool = False, **kwargs) bytes | str#
- Download a media file from WhatsApp servers.
Same as
download_media()withmedia_url=media.get_media_url()
>>> message.image.download()
- Parameters:
path – The path where to save the file (if not provided, the current working directory will be used).
filename – The name of the file (if not provided, it will be guessed from the URL + extension).
in_memory – Whether to return the file as bytes instead of saving it to disk (default: False).
**kwargs – Additional arguments to pass to requests.get.
- Returns:
The path of the saved file if
in_memoryis False, the file as bytes otherwise.
- classmethod BaseMedia.from_flow_completion(client: WhatsApp, media: dict[str, str]) BaseMedia#
Create a media object from the media dict returned by the flow completion.
Example
>>> from pywa import WhatsApp, types >>> wa = WhatsApp() >>> @wa.on_flow_completion() ... def on_flow_completion(_: WhatsApp, flow: types.FlowCompletion): ... img = types.Image.from_flow_completion(client=wa, media=flow.response['media']) ... img.download()
- Parameters:
client – The WhatsApp client.
media – The media dict returned by the flow completion.
- Returns:
The media object (Image, Video, Sticker, Document, Audio).
- class pywa.types.media.MediaUrlResponse#
Represents a media response.