Skip to main content

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

Project description

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

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 — see the repo LICENSE. Third-party notices: THIRD_PARTY_NOTICES.md.

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.1-cp310-abi3-win_amd64.whl (3.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

chatxdk-0.4.1-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.1-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.1-cp310-abi3-macosx_11_0_arm64.whl (3.1 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

chatxdk-0.4.1-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.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: chatxdk-0.4.1-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.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2b351012cba965e1c2d253381a3ad0e7a6b4858404fc30e811fae70d78b18af3
MD5 8d3a73e310dfe09d9547d4f5779b4735
BLAKE2b-256 1ebb41a3bf9ddd8875a0d3f7445c90324a6039d65bfdd8ddb6de5c29b2139a87

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.1-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.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dba2c5248adaaeafada52980ec739f8068488564a1861d1ca2be0d7a96006a1c
MD5 3d17a4cc72745adc7646f513dd0c6789
BLAKE2b-256 9c3a975e25b900aa5c1a5d27387f72ac43a5930bc6bbea96f01efc343dcd31f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.1-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.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ed165dffe8c6336d1bbbf6423034e3303c6645c9be72154afae624fb3148e03
MD5 4ac59d92cd0b361e65c0da3d76d7d349
BLAKE2b-256 8768c0fa19bd67593feb4ffbd965a461bebf685381eeab0ab18551499e740280

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.1-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.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 704c753d474a7c3d3b4dffae0d1a4be3ba78ca911a0b0cc65e85afb3dade37b0
MD5 7072e633b51882fb9b0d4dc764819b55
BLAKE2b-256 bf8081b3bad83a4c986f322d6d591993658c4734a5986453e3186ba85280cf21

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.1-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.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for chatxdk-0.4.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a89d6735417d4c44fbf4d7d7799e58b4cde658536e71eaf37371c9648ef10792
MD5 12d5a43726614f034049615a4772b6a2
BLAKE2b-256 292d38e13cfdf9d0dcee7e13f41015aa4b2648a0f42e0142be12790aa48bdf3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for chatxdk-0.4.1-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