opentele2.devices
The device classes. Every device is picked by the core from a weighted catalog;
RandomDevice(unique_id) returns the same device for the same unique_id (a str as given,
anything else as its str()) and a random device without one.
from opentele2.devices import AndroidDevice, IOSDevice, WebBrowserDevice, WindowsDeviceDeviceInfo
opentele2/devices.py
class DeviceInfo:
def __init__(self, model: str, version: str) -> None: ...
model: str
version: strA device model and system version; str() is "<model> <version>".
Device classes
opentele2/devices.py
class SystemInfo:
deviceList: list[DeviceInfo]
device_models: list[str]
system_versions: list[str]
@classmethod
def RandomDevice(cls, unique_id: str | None = None) -> DeviceInfo: ...
class GeneralDesktopDevice(SystemInfo): ...
class WindowsDevice(GeneralDesktopDevice): ...
class LinuxDevice(GeneralDesktopDevice): ...
class macOSDevice(GeneralDesktopDevice):
@classmethod
def RandomDevice(cls, unique_id: str | None = None,
variant: str = "tdesktop") -> DeviceInfo: ...
class AndroidDevice(SystemInfo): ...
class IOSDevice(SystemInfo): ...
iOSDevice = IOSDevice
class WebBrowserDevice(SystemInfo):
BROWSER_WEIGHTS: dict[str, int]
@classmethod
def RandomDevice(cls, unique_id: str | None = None, variant: str = "z") -> DeviceInfo: ...| Class | RandomDevice gives |
|---|---|
WindowsDevice | A Telegram Desktop Windows device: Windows 11 or Windows 10, with x64 on AMD64. |
LinuxDevice | A Telegram Desktop Linux device: Linux, the desktop environment, the display server and glibc <version>. |
macOSDevice | A Mac; variant="tdesktop" formats the version as Telegram Desktop does (macOS 26.7.1), variant="swift" keeps the bare 26.7.1 of Telegram for macOS. Both pick the same Mac for the same unique_id. |
AndroidDevice | A Telegram Android device: manufacturer and model as one string, SDK <level>. |
IOSDevice | A marketing name such as iPhone 15 Pro and an iOS version such as 17.4.1. |
WebBrowserDevice | A browser user agent with the OS name (variant="z", Web A) or the navigator.platform string (variant="k", Web K and Webogram). |
SystemInfo | Raises NotImplementedError. |
Catalog attributes
| Attribute | Description |
|---|---|
deviceList | Every catalog pair as a DeviceInfo, repeated by its weight, in catalog order. |
device_models | The catalog’s models in file order (desktop, Mac and iOS classes; empty for Android). |
system_versions | The catalog’s system versions in file order (desktop, Mac and iOS classes). Mac versions are bare. |
Web | The browser weights of the web pool: chrome 19, edge 2, firefox 1. |
The attributes are read only: each read returns a new list or dict, so editing one changes nothing
RandomDevice picks. The web devices are drawn with opentele2-browser and are deterministic per
unique_id and per Chrome and Firefox major.
devices.py
from opentele2.devices import AndroidDevice, macOSDevice
print(AndroidDevice.RandomDevice("account-42"))
print(macOSDevice.RandomDevice("account-42", variant="swift"))
print(len(AndroidDevice.deviceList))Last updated on