iLink SDK — Python
中文版: README.zh.md
Dependency-free (ctypes) Python bindings for the Rust ilink-sdk library.
The platform wheels on PyPI bundle the native library, so pip install works
with no Rust toolchain and no manual library setup.
Install
pip install ilink-sdk
Published on PyPI: https://pypi.org/project/ilink-sdk/.
That installs a platform wheel (ilink_sdk.dll / libilink_sdk.so /
libilink_sdk.dylib is inside the package). The loader looks for the library in
this order, so you can override it when needed:
$ILINK_SDK_LIB(full path to the shared library),- next to the installed package (this is where the wheel puts it),
target/release/of a source checkout,- the system loader path.
From source
Building the wheel yourself requires a Rust toolchain, because the native library is compiled from the crate in this repository:
cargo build --release # from the repository root, produces the library
pip install ./bindings/python # copies it into the wheel
setup.py finds the library at target/release/ (or $ILINK_SDK_LIB) and
copies it into ilink_sdk/; the resulting wheel is tagged for the current
platform (py3-none-<plat>). To build one wheel per platform, run this on each
OS/arch (which is what CI does).
Usage
import ilink_sdk
print(ilink_sdk.version()) # '2.4.11'
print(ilink_sdk.call("mime.info", {"path": "a.png"})) # decoded result object
client = ilink_sdk.Client(account_id="cfe9a2017e77-im-bot")
# Typed helpers return dataclasses from ilink_sdk.models.
info = client.mime_info("a.png") # models.MimeInfo
print(info.mime, info.is_image)
# QR login
start = client.login_start() # models.LoginStart
print(start.qrcode_url)
result = client.login_complete(start.session_key) # blocks until scanned
account_id = result.account_id
# Send a message
sent = client.send_text("someone@im.wechat", "hello from Python")
print(sent.message_id)
# Long-poll for inbound messages
updates = client.get_updates() # models.Updates
for message in updates.messages:
print(message.message_id)
Common workflows
Media
# Upload a file to the CDN (media_type: image | video | file | voice)
uploaded = client.upload("someone@im.wechat", "big.png", media_type="image")
print(uploaded.filekey, uploaded.aes_key_base64)
# Download and decrypt a CDN reference, writing it to disk
got = client.download({"encrypt_query_param": "...", "aes_key": "..."},
dest_path="/tmp/out.png")
print(got.bytes, got.path)
# Fetch a URL; without dest_path the bytes come back inline, base64 decoded
inline = client.fetch("https://example.com/a.bin")
raw = inline.data() # bytes | None
# Download every media referenced by an inbound message item
media = client.download_item(msg.item_list[1], dest_dir="/tmp")
print(media.paths()) # ['/tmp/...']
Context tokens & sync cursor
client.context_set(account_id, user_id, token)
token = client.context_get(account_id, user_id) # str | None
client.context_clear(account_id)
client.context_restore(account_id) # -> int (restored count)
cursor = client.sync_load(account_id)
client.sync_save(account_id, cursor)
client.sync_clear(account_id)
Session guard
client.session_pause(account_id)
status = client.session_status(account_id) # models.SessionStatus
print(status.paused, status.remaining_ms)
client.session_resume(account_id)
client.session_assert(account_id) # raises when paused
Quote cache
policy = client.quote_policy() # models.QuotePolicy
client.quote_put(account_id, conversation_id, message_id, body="hi")
record = client.quote_find(account_id, conversation_id, message_id) # models.QuoteRecord | None
client.quote_gc()
print(client.quote_media_dir(account_id))
Any operation, typed
paths = client.call_into("paths", ilink_sdk.models.Paths)
config = client.config_load() # models.ConfigLoad
raw = client.call("mime.extension", {"mime": "image/png"}) # plain dict
Errors
Failures raise ilink_sdk.IlinkError with the Rust kind attached:
try:
client.send_text("someone@im.wechat", "hi")
except ilink_sdk.IlinkError as err:
if err.kind in ("timeout", "cancelled"):
... # retry or stop cleanly
raise
API
call(op, params=None) reaches every operation (see
docs/reference/ffi.md) and returns decoded
Python data. Client adds typed helpers for the common flows, returning
ilink_sdk.models dataclasses (Account, LoginStart,
LoginResult, SendResult, Updates, MsgContext, UploadedFile,
InboundMedia, MimeInfo, ...), and applies default routing parameters
(account_id, base_url, cdn_base_url, route_tag, bot_agent,
timeout_ms) to every call. Use Client.call_into(op, Model, params) to decode
any operation into a model.
Test
ILINK_SDK_LIB=../../target/release/ilink_sdk.dll python -m pytest
# or, with no pytest:
ILINK_SDK_LIB=../../target/release/ilink_sdk.dll python tests/test_smoke.py
Metadata
Release files for ilink-sdk 2.4.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| ilink_sdk-2.4.11-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| ilink_sdk-2.4.11-py3-none-manylinux_2_34_x86_64.whl | Python 3 | none | Linux glibc 2.34+ x86-64 | Details |
| ilink_sdk-2.4.11-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details |
| ilink_sdk-2.4.11-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details |
Total release size: 9.0 MB
Release files / ilink_sdk-2.4.11-py3-none-win_amd64.whl
| Download URL | ilink_sdk-2.4.11-py3-none-win_amd64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
d75f95dd5310ee3859eaca119623696b077f3303196a634d06ceaa8351d8ebd8
|
|
BLAKE2b-256 checksum How to use checksums |
e86dfa9f25b9f36fe7a0f928381db16eefe60240e285401ed9fa4f552967df00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / ilink_sdk-2.4.11-py3-none-manylinux_2_34_x86_64.whl
| Download URL | ilink_sdk-2.4.11-py3-none-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | Linux glibc 2.34+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
e4bb59cd8105bdd21e6d1b3c06d857632099afa9367396c65bebf2afd7522f11
|
|
BLAKE2b-256 checksum How to use checksums |
c8b642d11ab52a3d4442348fad89e72b259143a228936b73e09a255701841d63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / ilink_sdk-2.4.11-py3-none-macosx_11_0_arm64.whl
| Download URL | ilink_sdk-2.4.11-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0320bbb97f0f24b54528a72ce1899d4f8920a92e61af5c9b8da3236d86146599
|
|
BLAKE2b-256 checksum How to use checksums |
281b57ef39eeed76f69e2df1e8570a0abe362c96b24d8a207d8f1035265d5413
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / ilink_sdk-2.4.11-py3-none-macosx_10_12_x86_64.whl
| Download URL | ilink_sdk-2.4.11-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
954da2a59685f82c02790d6a07fa3e9697d2ab9793bfa8e0254e320461b477c4
|
|
BLAKE2b-256 checksum How to use checksums |
0fb270a144b835207e384b284d3886a431b0ec1d4da5d92a4a9b4f6b49dadeef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|