telegram.file module

This module contains an object that represents a Telegram File.

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

Bases: telegram.base.TelegramObject

This object represents a Telegram File.

file_id

str

file_size

str

file_path

str

Parameters:
  • file_id (str) –
  • bot (telegram.Bot) –
  • file_size (Optional[int]) –
  • file_path (Optional[str]) –
  • **kwargs (dict) – Arbitrary keyword arguments.
static de_json(data, bot)
Parameters:
Returns:

Return type:

telegram.File

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.

Parameters:
  • custom_path (Optional[str]) – Custom path.
  • out (Optional[object]) – A file-like object. Must be opened in binary mode, if applicable.
  • timeout (Optional[int|float]) – 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).
Raises:

ValueError – If both custom_path and out are passed.