Skip to Content
ReferencePythonopentele2.fingerprint

opentele2.fingerprint

The initConnection fingerprint API, computed by the core. Importing the module fetches the current platform versions once, unless OPENTELE_NO_FETCH is set, and applies them to PLATFORM_VERSIONS.

from opentele2.fingerprint import ( PLATFORM_VERSIONS, FingerprintConfig, StrictMode, validate_init_connection_params, )

Versions

opentele2/fingerprint.py
@dataclass class PlatformVersions: android_app_version: str android_app_version_code: int android_sdk_range: tuple[int, int] android_latest_sdk: int ios_app_version: str ios_build_number: int ios_version_range: tuple[str, str] ios_system_version: str macos_system_version: str desktop_app_version: str desktop_app_version_suffix: str macos_app_version: str macos_build_number: int android_x_app_version: str web_a_version: str web_k_version: str chrome_version: str user_agent: str firefox_version: str PLATFORM_VERSIONS: PlatformVersions def get_platform_versions() -> PlatformVersions: ...
NameDescription
PlatformVersionsThe client and browser versions the profiles and checks use; the defaults are the built-in offline set.
PLATFORM_VERSIONSThe process-wide instance, with the fetched versions applied on import. Edit it to pin versions; the profiles and checks read it as it is.
get_platform_versions()PLATFORM_VERSIONS.

desktop_app_version is bound to the version stamped into written tdata and is never fetched.

Validation

opentele2/fingerprint.py
def validate_init_connection_params( api_id: int | None, device_model: str | None, system_version: str | None, app_version: str | None, system_lang_code: str | None, lang_pack: str | None, lang_code: str | None, *, strict: bool = False, ) -> list[str]: ... class StrictMode(Enum): OFF = "off" WARN = "warn" STRICT = "strict" @dataclass class FingerprintConfig: strict_mode: StrictMode = StrictMode.WARN auto_validate: bool = True preferred_transport: str = "obfuscated" warn_on_layer_mismatch: bool = True layer_override: int | None = None randomize_msg_id_offset: bool = True def get_effective_layer(self) -> int: ... def validate_params(self, **kwargs: Any) -> None: ... DEFAULT_CONFIG = FingerprintConfig()
NameDescription
validate_init_connection_params(...)The messages of every issue the seven initConnection fields have: an unknown lang pack, a lang code under two characters, an Android or iOS system_lang_code without a region, an empty device, system or app version; with strict=True also an api_id that is not the official one for the lang pack, an app version behind the latest known major and an Android SDK level outside the range, against PLATFORM_VERSIONS. An empty list is a clean profile.
StrictModeOFF: no extra checks. WARN: warn about inconsistencies. STRICT: raise for any inconsistency the server could detect.
FingerprintConfigThe fingerprint options of a TelegramClient.
FingerprintConfig.get_effective_layer()layer_override when set; otherwise the installed Telethon layer, with a warning when it is more than 15 layers from LAYER.
FingerprintConfig.validate_params(**kwargs)Validates initConnection fields given by name; warns in WARN mode, raises ValueError in STRICT mode, and does nothing in OFF mode or with auto_validate off.
DEFAULT_CONFIGThe config a TelegramClient uses without fingerprint_config.

preferred_transport is one of full, intermediate, abridged and obfuscated. randomize_msg_id_offset adds a small random offset to msg_id generation, as official clients do; the offset itself is drawn from the OS random source for every config.

validate.py
from opentele2.api import API from opentele2.fingerprint import validate_init_connection_params api = API.TelegramDesktop.Generate("windows", "account-42") issues = validate_init_connection_params( api.api_id, api.device_model, api.system_version, api.app_version, api.system_lang_code, api.lang_pack, api.lang_code, strict=True, ) print(issues or "clean")

Layer, time zone and msg_id

opentele2/fingerprint.py
LAYER: int # 230 def get_advertised_layer() -> int: ... def get_recommended_layer() -> int: ... def tdesktop_tz_offset(now: datetime | None = None) -> float: ... def generate_msg_id_offset() -> int: ... def is_valid_msg_id(msg_id: int, *, from_client: bool = True) -> bool: ...
NameDescription
LAYERThe TL schema layer opentele2 advertises: the layer of the api.tl shipped by Telegram Desktop 7.3.1.
get_advertised_layer()LAYER, independent of the installed Telethon.
get_recommended_layer()The installed Telethon layer; warns when it is more than 15 layers from LAYER.
tdesktop_tz_offset(now)The tz_offset Telegram Desktop puts into initConnection params: the local UTC offset in seconds, wrapped into -12 h..+14 h and rounded to a multiple of 900. now defaults to the current local time.
generate_msg_id_offset()A msg_id offset in 0..=0xFFFF from the OS random source; random.seed does not reproduce it.
is_valid_msg_id(msg_id, from_client)Whether msg_id is a plausible 64-bit msg_id now: positive, odd from the client and even from the server, its time within 300 seconds of now.

Transport

opentele2/fingerprint.py
class TransportRecommendation: @staticmethod def get_connection_class(lang_pack: str = "tdesktop") -> type[Connection]: ... @staticmethod def get_available_transports() -> dict[str, type[object]]: ...
MethodDescription
get_connection_class(lang_pack)Telethon’s ConnectionTcpObfuscated, the transport every official client uses (ConnectionTcpFull when it cannot be imported); lang_pack is accepted and ignored.
get_available_transports()The Telethon connection classes that import, by name: full, abridged, intermediate, obfuscated.
Last updated on