opentele2.api
The official client API classes, with every value from the core. Each client class holds the
default profile of that client, and Generate a device picked for a seed.
from opentele2.api import API, APIData, CreateNewSession, LoginFlag, UseCurrentSessionAPI
| Class | api_id | lang_pack | Default device | Generate |
|---|---|---|---|---|
API.TelegramDesktop | 2040 | tdesktop | Desktop, Windows 11 x64 | Windows, macOS or Linux device |
API.TelegramAndroid | 6 | android | samsungSM-S938B, SDK 36 | Android device |
API.TelegramAndroidX | 21724 | android | samsungSM-S938B, SDK 36 | Android device |
API.TelegramIOS | 10840 | ios | iPhone 17 Pro | iOS device |
API.TelegramMacOS | 2834 | macos | MacBook Air M4 | Mac, bare version |
API.TelegramWeb_A | 2496 | empty | browser user agent, Windows | browser, OS name |
API.TelegramWeb_K | 2496 | macos | browser user agent, Win32 | browser, navigator.platform |
API.Webogram | 2496 | empty | browser user agent, Win32 | browser, navigator.platform |
API.TelegramWeb_Z is API.TelegramWeb_A. Every class has lang_code en and
system_lang_code en-US. The app versions come from PLATFORM_VERSIONS: on import they follow
the fetched versions, and Webogram’s 0.7.0 stays fixed.
class API:
class TelegramDesktop(APIData):
@classmethod
def Generate(cls, system: str | None = None, unique_id: str | None = None) -> Self: ...
class TelegramAndroid(APIData): ...
class TelegramAndroidX(APIData): ...
class TelegramIOS(APIData): ...
class TelegramMacOS(APIData): ...
class TelegramWeb_A(APIData):
@classmethod
def Generate(cls, unique_id: str | None = None) -> Self: ...
TelegramWeb_Z = TelegramWeb_A
class TelegramWeb_K(APIData):
@classmethod
def Generate(cls, unique_id: str | None = None) -> Self: ...
class Webogram(APIData):
@classmethod
def Generate(cls, unique_id: str | None = None) -> Self: ...API.TelegramDesktop.Generate takes the platform first: Generate("windows", "id"), with
"windows", "macos" or "linux" matched case-sensitively. A single positional argument that is
not a platform name is the unique_id, as in Generate("id"); without a platform the core picks
one from the unique_id hash. The app version gets x64 on Windows and arm64 on macOS.
APIData
The base class of every profile, and a profile of its own when built with an api_id and
api_hash.
class APIData:
api_id: int
api_hash: str
device_model: str
system_version: str | None = None
app_version: str | None = None
lang_code: str | None = None
system_lang_code: str | None = None
lang_pack: str | None = None
def __init__(
self,
api_id: int | None = None,
api_hash: str | None = None,
device_model: str | None = None,
system_version: str | None = None,
app_version: str | None = None,
lang_code: str | None = None,
system_lang_code: str | None = None,
lang_pack: str | None = None,
) -> None: ...
def copy(self) -> APIData: ...
def get_cls(self) -> type[APIData]: ...
def destroy(self) -> None: ...
@staticmethod
def from_json(data: dict) -> APIData: ...
def to_json(self, extra: dict | None = None) -> dict: ...
@classmethod
def Generate(cls, unique_id: str | None = None) -> Self: ...| Name | Description |
|---|---|
APIData(...) | A profile; every argument left out takes the class value. APIData itself needs api_id and api_hash (else NoInstanceMatched) and defaults device_model to the local machine (PC 64bit, PC 32bit or the machine name). |
copy() | A new instance with the same values; works on a class and on an instance. |
get_cls() | The class of an instance, or the class itself. |
destroy() | Does nothing. |
from_json(data) | The profile of a session .json object: app_id, app_hash, device, sdk, app_version, system_lang_code (falling back to system_lang_pack), lang_pack and lang_code. Raises NoInstanceMatched without app_id or app_hash. |
to_json(extra) | The session .json object of the profile: the nine profile keys, then the account keys with their defaults (twoFA, role, id, phone, username, … ipv6, session_file), updated with extra. |
Generate(unique_id) | A profile with a device picked for unique_id: the same id gives the same device. Android, Android X, iOS and macOS use it as is; the desktop and web classes override it; any other class raises NotImplementedError. |
Two profiles are equal when api_id, api_hash, device_model, system_version and
app_version are; the language fields are not compared. str() of a class or instance lists its
values.
from opentele2.api import API
desktop = API.TelegramDesktop.Generate("windows", "account-42")
android = API.TelegramAndroid.Generate("account-42")
print(desktop.device_model, desktop.system_version, desktop.app_version)
print(desktop == API.TelegramDesktop.Generate("windows", "account-42")) # TrueLogin flags
class LoginFlag(int): ...
class UseCurrentSession(LoginFlag): ...
class CreateNewSession(LoginFlag): ...Passed as the classes themselves, never instances, to ToTelethon, FromTelethon, ToTDesktop,
FromTDesktop and FromSessionJson:
UseCurrentSession: the converted client or folder uses the existing auth key. Offline.CreateNewSession: the existing session logs a new one in by QR code, with the 2FA password when the account has one, on the device of theapipassed. Needs the network.
Any other value raises LoginFlagInvalid.