class telegram.File(file_id, bot=None, file_size=None, file_path=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a file ready to be downloaded. The file can be downloaded with download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile.


Maximum file size to download is 20 MB


str – Unique identifier for this file.


str – Optional. File size.


str – Optional. File path. Use download to get the file.

  • file_id (str) – Unique identifier for this file.
  • file_size (int, optional) – Optional. File size, if known.
  • file_path (str, optional) – File path. Use download to get the file.
  • bot (telegram.Bot, optional) – Bot to use with shortcut method.
  • **kwargs (dict) – Arbitrary keyword arguments.
download(custom_path=None, out=None, timeout=None)

Download this file. By default, the file is saved in the current working directory with its original filename as reported by Telegram. If a custom_path is supplied, it will be saved to that path instead. If out is defined, the file contents will be saved to that object using the out.write method.


custom_path and out are mutually exclusive.

  • custom_path (str, optional) – Custom path.
  • out (object, optional) – A file-like object. Must be opened in binary mode, if applicable.
  • timeout (int | float, optional) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).

ValueError – If both custom_path and out are passed.