Skip to main content

chat-xdk Python bindings

Python bindings for the X Chat SDK — encryption for X Direct Messages.

Install

pip install chatxdk

The PyPI distribution is chatxdk; import it as chat_xdk.

Architecture

Python (chat_xdk) → PyO3 → chat-xdk-core (Rust)

Prerequisites

  • Python 3.10+
  • Rust (stable) and maturin

Setup

From source (editable install):

cd crates/pyo3
pip install maturin
maturin develop

Release wheel:

maturin build --release
pip install target/wheels/*.whl

Quick Start

from chat_xdk import (
    Chat,
    DecryptEventParams,
    DecryptEventsParams,
    EncryptMessageParams,
    EncryptReactionParams,
    EncryptReplyParams,
    ImportKeysParams,
    SetIdentityParams,
)

chat = Chat(config_json)
chat.unlock("2580")
# Or load a local key blob + its registered version instead of Juicebox:
# chat.import_keys(ImportKeysParams(private_key_bytes, signing_key_version=registered_key_version))

# Set the session once: your user id + registered signing-key version,
# the opt-in conversation-key cache, and the participants' signing keys.
# Each signing-key entry must include the identity public key and its binding
# signature so the SDK can verify the signing key is authentic.
chat.set_identity(SetIdentityParams("111", "1"))
chat.set_cache_keys(True)
chat.set_signing_keys([
    {
        "user_id": "111",
        "public_key_version": "1",
        "public_key": "BASE64...",
        "identity_public_key": "BASE64...",
        "identity_public_key_signature": "BASE64...",
    },
    {
        "user_id": "222",
        "public_key_version": "1",
        "public_key": "BASE64...",
        "identity_public_key": "BASE64...",
        "identity_public_key_signature": "BASE64...",
    },
])

# Initial load — batch decrypt with automatic key extraction. Signing keys
# come from the store; the verified conversation keys populate the cache.
result = chat.decrypt_events(DecryptEventsParams(raw_events))

for dm in result["messages"]:
    if dm["event"]["type"] == "Message":
        print(dm["event"]["sender_id"], dm["event"]["content"]["text"])

# Individual events after the initial load: the empty key map resolves from
# the cache and the unset signing keys from the store (pass either
# explicitly to override).
event = chat.decrypt_event(DecryptEventParams(new_event_b64, {}))

# Sending resolves the identity and conversation key from the session too.
payload = chat.encrypt_message(EncryptMessageParams(event["conversation_id"], "hi!"))
# Reply / react by handing back the raw event being answered.
reply = chat.encrypt_reply(EncryptReplyParams(event["conversation_id"], "pong", new_event_b64))
reaction = chat.encrypt_add_reaction(EncryptReactionParams(new_event_b64, "👍"))

Every method with a params object takes a params class (EncryptMessageParams, DecryptEventParams, EncryptFileParams, …): required fields are positional, optional ones are keywords, and every field is a read/write attribute, so a params object can be built once and adjusted.

API

See the Python column of the unified tables in docs/API.md for the full method list, parameters, and return types. Files (media) are covered under Files (Media).

Network access

Each chat makes one kind of request itself: an anonymous GET https://api.x.com/2/chat/features in the background, which reads the X API's feature switches that pick the format the SDK sends in. A chat reads them once, when it is created, and keeps the answer for its lifetime; chats created while a request is in flight share it. The request carries no credentials and never delays or fails a call; until it answers, and for the chat's lifetime if it fails or is blocked, sends stay in v0, the format 0.5.x sends.

Security limitations

The underlying protocol provides no forward secrecy and no post-compromise security: compromise of an identity private key exposes all conversation keys ever encrypted to that public key — and therefore all past and future messages in those conversations. Key rotation does not retroactively protect messages encrypted under a previous key. See docs/CRYPTO.md — Known Limitations.

License

MIT — see the repo LICENSE. Third-party notices: THIRD_PARTY_NOTICES.md.

Metadata

Release files for chatxdk 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for chatxdk 0.7.0
File Actions
chatxdk-0.7.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for chatxdk-0.7.0-cp310-abi3-win_amd64.whl
chatxdk-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for chatxdk-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
chatxdk-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for chatxdk-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
chatxdk-0.7.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for chatxdk-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
chatxdk-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for chatxdk-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 19.0 MB

Release files / chatxdk-0.7.0-cp310-abi3-win_amd64.whl

Download URL chatxdk-0.7.0-cp310-abi3-win_amd64.whl
Size 3.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
90f41fd31253ff4e55aca14411ee874736e450711db20f557ae8571cd2b1458e
BLAKE2b-256 checksum
How to use checksums
1b964ac3eeffd685baea9e3cf0420a8904ca5292802384d2adb97ba26d9273ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / chatxdk-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL chatxdk-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
922bc1906659bcd9138b745d5d42ddc56d139f388008243b47387d98c6555d3c
BLAKE2b-256 checksum
How to use checksums
0162e5076fd9c9751f8854e7e09dd9e8e9494405256115f9b1c6b621016e9c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / chatxdk-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL chatxdk-0.7.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
c29fb6063cbef5bbede8880d11ad7d3768ff6942217820b53563ca4f1c401a9a
BLAKE2b-256 checksum
How to use checksums
0e4ee30df78d2b1a67331824273cf6680aa73dc0ced7bdef8c2181d98f63d509
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / chatxdk-0.7.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL chatxdk-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Size 3.6 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
199d5286542a9b8016a2068794221431cdf3007b5adb24d5208ce7aefe916656
BLAKE2b-256 checksum
How to use checksums
ff28c77cff06c74c6799b8f48e2b6f101a08d78232c5526144f575dc37c1d4cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / chatxdk-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL chatxdk-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.8 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a970210921133da340f9b2b1d4ad5c5d113442499d21b48c16a3143c84579885
BLAKE2b-256 checksum
How to use checksums
bbe05c55e340c4bc7605ded2ffbfa689000f73997b7b11b44dd410015115e945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for chatxdk 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for chatxdk-0.7.0-cp310-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page