Skip to main content

X Chat SDK - End-to-end encryption for X Direct Messages (Python bindings)

Project description

chat-xdk Python bindings

Python bindings for the X Chat SDK — end-to-end 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

chat = Chat(config_json)
chat.unlock("2580")
# Or load a local key blob + its registered version instead of Juicebox:
# chat.import_keys(private_key_bytes, 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("111", "v1")
chat.set_cache_keys(True)
chat.set_signing_keys([
    {
        "user_id": "111",
        "public_key_version": "v1",
        "public_key": "BASE64...",
        "identity_public_key": "BASE64...",
        "identity_public_key_signature": "BASE64...",
    },
    {
        "user_id": "222",
        "public_key_version": "v1",
        "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(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: conversation keys resolve from
# the cache and signing keys from the store (pass either explicitly to
# override).
event = chat.decrypt_event(new_event_b64)

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

API

See the Python column of the unified tables in docs/API.md for the full method list, parameters, and return types.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

chatxdk-0.4.0-cp310-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

chatxdk-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

chatxdk-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

chatxdk-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

chatxdk-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file chatxdk-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: chatxdk-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.0 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for chatxdk-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4c40e4d046b09852766667eef1f61a28c590ff41a7aad977d50d7a15f1c6316b
MD5 50f63a48735013525851668197bd6386
BLAKE2b-256 497c81b3f3367f23074be4e77b15c2ae2a98a6770236843eba82e24b02483208

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on xdevplatform/chat-xdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatxdk-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3decf7c3ff5b808fd7a9205fd09e1a528a31a73a41fe40b37d71cecd4f3dcff
MD5 e51e059c9c3a5e0058f5c6ad0ea69886
BLAKE2b-256 b4563777353fbf762f073fc5cec85304721871ad9b3ac4e31936267cb637229d

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on xdevplatform/chat-xdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatxdk-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a5a2a8b605953f3e251710ca2df349307877bbdf38a368ba725f928ef0e11aff
MD5 9f86262e27a95558d5fbe6ac2b98dfac
BLAKE2b-256 980578b2e5c7e609e8e39457d9b100e77ef27fb9e5577b41fb738a7f93f25590

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on xdevplatform/chat-xdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatxdk-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55caeecf07ee63a589dda8e8d8210e6b201240dc58c309a7cb9b65fb2a9b35cb
MD5 b17a4d14b02a2484d198744cd7d9b3fc
BLAKE2b-256 930ab87f11354a644d309f676db0670dc86b9d4fa618a5ded938c5639f4ff033

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on xdevplatform/chat-xdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chatxdk-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5cd1cc183557999bef9440c2db78248866a215b8ef4ee901856036e4d86f7a77
MD5 ae689fc6afef3e9a3b54b98e014d740d
BLAKE2b-256 1762c3d63b440dc3328cf30c6b3b04b36e0e44fa8964024755acdf47211e31db

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on xdevplatform/chat-xdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page