Skip to main content

Unofficial Python SDK for the XMTP network.

Project description

xmtp

Unofficial Python client SDKs for the XMTP network.

Primary goal: feature parity with xmtp-js.

This is a community project that mirrors the structure and interfaces of the official xmtp-js SDK, adapted for Python.

What's inside?

SDKs

  • python-sdk: XMTP client SDK for Python
  • agent-sdk: XMTP agent SDK for Python (event-driven, middleware-powered)

Content types

Requirements

  • Python 3.10+
  • libxmtp bindings >= 1.7.0-r3

Installation

pip install xmtp

This installs the client SDK, agent SDK, and built-in content types in one package.

Install from GitHub main

pip install "xmtp @ git+https://github.com/pierce403/xmtp-py.git@main"

From source (dev)

Clone the repo and install into a virtualenv. Install the bindings first so the local editable package can resolve them:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip

pip install -e bindings/python
pip install -e ".[dev]"

Quick start

Agent SDK (recommended)

import asyncio
import xmtp

from xmtp_agent import Agent
from xmtp_agent.name_resolver import create_name_resolver
from xmtp_agent.user import create_user, create_signer
from xmtp.types import ClientOptions

recipient = "deanpierce.eth"


async def main() -> None:
    # Create a user and signer
    user = create_user()
    signer = create_signer(user)

    # Create the agent
    agent = await Agent.create(
        signer,
        ClientOptions(
            env="production",
            disable_history_sync=True,
            db_path=None,
        ),
    )

    # Resolve the recipient and send a message
    resolver = create_name_resolver()
    address = await resolver(recipient)
    if address is None:
        raise ValueError(f'Could not resolve address for "{recipient}"')

    dm = await agent.client.conversations.new_dm(address)
    await dm.send(f"Hello from xmtp-py {xmtp.__version__}")


if __name__ == "__main__":
    asyncio.run(main())

Python SDK (client)

import asyncio
import xmtp

from xmtp import Client
from xmtp.signers import create_signer
from xmtp.types import ClientOptions
from xmtp_agent.name_resolver import create_name_resolver

recipient = "deanpierce.eth"


async def main() -> None:
    signer = create_signer(private_key)
    client = await Client.create(
        signer,
        ClientOptions(
            env="production",
            disable_history_sync=True,
        ),
    )

    resolver = create_name_resolver()
    address = await resolver(recipient)
    if address is None:
        raise ValueError(f'Could not resolve address for "{recipient}"')

    dm = await client.conversations.new_dm(address)
    await dm.send(f"Hello from xmtp-py {xmtp.__version__}")


if __name__ == "__main__":
    asyncio.run(main())

Key management tips

  • create_user() generates an in-memory key; persist the private key yourself if you want a stable inbox across restarts.
  • Prefer XMTP_WALLET_KEY and XMTP_DB_ENCRYPTION_KEY in environment variables or a secrets manager; never commit them to git.
  • Use a stable db_path and keep the database directory between runs. Losing it creates a new installation and can hit installation limits.
  • For production, wrap a hardware wallet or KMS signer by implementing the Signer protocol instead of storing raw keys.

Configuration & troubleshooting

History sync is disabled by default. To enable it, pass disable_history_sync=False (and optionally history_sync_url) in ClientOptions, or set XMTP_HISTORY_SYNC_URL.

Endpoint overrides via env:

  • XMTP_ENV, XMTP_API_URL, XMTP_HISTORY_SYNC_URL, XMTP_GATEWAY_HOST
  • XMTP_DISABLE_HISTORY_SYNC=1 to force identity calls through the primary API
  • XMTP_RUST_LOG to override Rust logging (defaults to off)

Common issues:

  • Missing libxmtpv3.so: install will build it automatically, but you need Rust (cargo) and git. See bindings/python/README.md for overrides. If no prebuilt wheels are available, pip install xmtp will fall back to a source build.
  • History sync gRPC errors: leave history sync disabled, or set XMTP_DISABLE_HISTORY_SYNC=1. To re-enable, pass disable_history_sync=False (and optionally history_sync_url) in ClientOptions.
  • Gateway host errors: gateway_host is an advanced setting; only set it when you have a gateway that supports XMTP gRPC.
  • Noisy Rust logs: set XMTP_RUST_LOG=error or pass rust_log="error" in ClientOptions.

LibXMTP bindings

This SDK uses libxmtp Python bindings for core XMTP functionality including cryptography, networking, and protocol implementation.

Minimum version: 1.7.0-r3

Documentation

Contributing

See CONTRIBUTING.md for guidelines.

License

Apache 2.0

Project details


Download files

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

Source Distribution

xmtp-0.1.6.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

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

xmtp-0.1.6-py3-none-any.whl (56.1 kB view details)

Uploaded Python 3

File details

Details for the file xmtp-0.1.6.tar.gz.

File metadata

  • Download URL: xmtp-0.1.6.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xmtp-0.1.6.tar.gz
Algorithm Hash digest
SHA256 ce35a57efa7ade29ffc9be5b6c3ed1ce8f90e9ff65941df507108e2d8e18b960
MD5 14efbcdf3bf31a0ee06d24f7e67fa2d1
BLAKE2b-256 4a114859af77a27e834b4b345f5ff873a2805d088bd91f6fdd8af7557378d9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for xmtp-0.1.6.tar.gz:

Publisher: publish.yml on pierce403/xmtp-py

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

File details

Details for the file xmtp-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: xmtp-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 56.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xmtp-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 a0d1e1cc1de1b7202f099b632c6023c3400abff6d357b404ca93ecba1e53a8a3
MD5 c8247cfdca83a8bdef7a21165d08b39c
BLAKE2b-256 09e14fee8ab6675b2f931a4948f6939c7fca6c6017e5f12eccffbe7b7f2c2309

See more details on using hashes here.

Provenance

The following attestation bundles were made for xmtp-0.1.6-py3-none-any.whl:

Publisher: publish.yml on pierce403/xmtp-py

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