tdjson is a high-performance Python binding for TDLib JSON interface.
By bundling pre-built TDLib binaries, it eliminates the effort for manual compilation and offers performance advantage over traditional ctypes wrappers, making it a reliable core for projects like Pytdbot
tdjson is compatible with the following platforms:
-
Linux (
x86_64andaarch64)- Requires
glibc 2.17+. - Includes most modern distributions like:
- Debian 8+
- Ubuntu 13.10+
- Fedora 19+
- RHEL 7+
- Requires
-
Windows (
x86_64)- Windows 7+
You can install tdjson directly from PyPI:
pip install tdjsonHere’s a quick example to get you started:
import json
import tdjson
# Create a new TDLib client
client_id = tdjson.td_create_client_id()
# Send a request to TDLib
request = {"@type": "getOption", "name": "version"}
tdjson.td_send(client_id, json.dumps(request).encode("utf-8"))
# Receive updates or responses
response = tdjson.td_receive(10.0)
print(response)
# Synchronously execute a TDLib request
result = tdjson.td_execute(
json.dumps(
{
"@type": "getTextEntities",
"text": "@telegram /test_command https://telegram.org telegram.me",
"@extra": ["5", 7.0, "a"],
}
).encode("utf-8")
)
print(result)For more detailed examples, check out the examples folder.
MIT LICENSE