PassportFile

class telegram.PassportFile(file_id, file_unique_id, file_date, file_size, credentials=None, *, api_kwargs=None)[source]

Bases: telegram.TelegramObject

This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don’t exceed 10MB.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their file_unique_id is equal.

Parameters:
  • file_id (str) – Identifier for this file, which can be used to download or reuse the file.

  • file_unique_id (str) – Unique identifier for this file, which is supposed to be the same over time and for different bots. Can’t be used to download or reuse the file.

  • file_size (int) – File size in bytes.

  • file_date (datetime.datetime) –

    Time when the file was uploaded.

    Changed in version 22.0: Accepts only datetime.datetime instead of int. The default timezone of the bot is used for localization, which is UTC unless telegram.ext.Defaults.tzinfo is used.

file_id[source]

Identifier for this file, which can be used to download or reuse the file.

Type:

str

file_unique_id[source]

Unique identifier for this file, which is supposed to be the same over time and for different bots. Can’t be used to download or reuse the file.

Type:

str

file_size[source]

File size in bytes.

Type:

int

file_date[source]

Time when the file was uploaded.

Changed in version 22.0: Returns datetime.datetime instead of int. The default timezone of the bot is used for localization, which is UTC unless telegram.ext.Defaults.tzinfo is used.

Type:

datetime.datetime

classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

classmethod de_json_decrypted(data, bot, credentials)[source]

Variant of telegram.TelegramObject.de_json() that also takes into account passport credentials.

Parameters:
  • data (dict[str, …]) – The JSON data.

  • bot (telegram.Bot | None) –

    The bot associated with these object. May be None, in which case shortcut methods will not be available.

    Changed in version 21.4: bot is now optional and defaults to None

    Deprecated since version 21.4: This argument will be converted to an optional argument in future versions.

  • credentials (telegram.FileCredentials) – The credentials

Return type:

telegram.PassportFile

classmethod de_list_decrypted(data, bot, credentials)[source]

Variant of telegram.TelegramObject.de_list() that also takes into account passport credentials.

Changed in version 20.0:

  • Returns a tuple instead of a list.

  • Filters out any None values

Parameters:
  • data (list[dict[str, …]]) – The JSON data.

  • bot (telegram.Bot | None) –

    The bot associated with these object. May be None, in which case shortcut methods will not be available.

    Changed in version 21.4: bot is now optional and defaults to None

    Deprecated since version 21.4: This argument will be converted to an optional argument in future versions.

  • credentials (telegram.FileCredentials) – The credentials

Return type:

tuple[telegram.PassportFile]

async get_file(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Wrapper over telegram.Bot.get_file(). Will automatically assign the correct credentials to the returned telegram.File if originating from telegram.PassportData.decrypted_data.

For the documentation of the arguments, please see telegram.Bot.get_file().

Returns:

telegram.File

Raises:

telegram.error.TelegramError