Media#

class pywa.types.media.Image#

Represents an received image.

Variables:
  • id (str) – The ID of the file (can be used to download or re-send the image).

  • sha256 (str) – The SHA256 hash of the image.

  • mime_type (str) – The MIME type of the image.

class pywa.types.media.Video#

Represents a video.

Variables:
  • id (str) – The ID of the file (can be used to download or re-send the video).

  • sha256 (str) – The SHA256 hash of the video.

  • mime_type (str) – The MIME type of the video.

class pywa.types.media.Audio#

Represents an audio.

Variables:
  • id (str) – The ID of the file (can be used to download or re-send the audio).

  • sha256 (str) – The SHA256 hash of the audio.

  • mime_type (str) – The MIME type of the audio.

  • voice (bool) – Whether the audio is a voice message or just an audio file.

class pywa.types.media.Document#

Represents a document.

Variables:
  • id (str) – The ID of the file (can be used to download or re-send the document).

  • sha256 (str) – The SHA256 hash of the document.

  • mime_type (str) – The MIME type of the document.

  • filename (str | None) – The filename of the document (optional).

class pywa.types.media.Sticker#

Represents a sticker.

Variables:
  • id (str) – The ID of the file (can be used to download or re-send the sticker).

  • sha256 (str) – The SHA256 hash of the sticker.

  • mime_type (str) – The MIME type of the sticker.

  • animated (bool) – Whether the sticker is animated.


Every media type has the following properties and methods:

property BaseMedia.extension: str | None#

Gets the extension of the media (with dot.)

BaseMedia.get_media_url() str#

Gets the URL of the media. (expires after 5 minutes)

BaseMedia.download(path: str | None = None, filename: str | None = None, in_memory: bool = False, **kwargs) bytes | str#
Download a media file from WhatsApp servers.
>>> 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_memory is False, the file as bytes otherwise.


class pywa.types.media.MediaUrlResponse#

Represents a media response.

Variables:
  • id (str) – The ID of the media.

  • url (str) – The URL of the media (valid for 5 minutes).

  • mime_type (str) – The MIME type of the media.

  • sha256 (str) – The SHA256 hash of the media.

  • file_size (int) – The size of the media in bytes.