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 Pythonagent-sdk: XMTP agent SDK for Python (event-driven, middleware-powered)
Content types
content-type-primitives: Primitives for building custom XMTP content typescontent-type-group-updated: Content type for group update messagescontent-type-reaction: Content type for reactions to messagescontent-type-read-receipt: Content type for read receiptscontent-type-remote-attachment: Content type for file attachments stored off-networkcontent-type-reply: Content type for direct replies to messagescontent-type-text: Content type for plain text messagescontent-type-transaction-reference: Content type for on-chain transaction referencescontent-type-markdown: Content type for markdown-formatted messagescontent-type-wallet-send-calls: Content type for wallet transaction requests
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, LogLevel
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="dev",
disable_history_sync=True,
logging_level=LogLevel.WARN,
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, LogLevel
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="dev",
disable_history_sync=True,
logging_level=LogLevel.WARN,
),
)
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_KEYandXMTP_DB_ENCRYPTION_KEYin environment variables or a secrets manager; never commit them to git. - Use a stable
db_pathand 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
Signerprotocol 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_HOSTXMTP_DISABLE_HISTORY_SYNC=1to force identity calls through the primary APIXMTP_RUST_LOGto override Rust logging (defaults tooff)
Common issues:
- Missing
libxmtpv3.so: install will build it automatically, but you need Rust (cargo) andgit. Seebindings/python/README.mdfor overrides. If no prebuilt wheels are available,pip install xmtpwill fall back to a source build. - History sync gRPC errors: leave history sync disabled, or set
XMTP_DISABLE_HISTORY_SYNC=1. To re-enable, passdisable_history_sync=False(and optionallyhistory_sync_url) inClientOptions. - Gateway host errors:
gateway_hostis an advanced setting; only set it when you have a gateway that supports XMTP gRPC. - Noisy Rust logs: set
XMTP_RUST_LOG=erroror passrust_log="error"inClientOptions.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xmtp-0.1.5.tar.gz.
File metadata
- Download URL: xmtp-0.1.5.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7019f30902c26a0f2e56f34ad74a38cd7e64bb1842b8d8711a3ff11c0e549966
|
|
| MD5 |
4c2fe76f52a65f1732da8844e416974c
|
|
| BLAKE2b-256 |
5e07e7499cdfddb491cc1b9363091ea1265415ec87ab195b215a7e26d36c1b5c
|
Provenance
The following attestation bundles were made for xmtp-0.1.5.tar.gz:
Publisher:
publish.yml on pierce403/xmtp-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmtp-0.1.5.tar.gz -
Subject digest:
7019f30902c26a0f2e56f34ad74a38cd7e64bb1842b8d8711a3ff11c0e549966 - Sigstore transparency entry: 844574437
- Sigstore integration time:
-
Permalink:
pierce403/xmtp-py@46ce3dd46f1479bf87b4de2d2e82a55da8039766 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/pierce403
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46ce3dd46f1479bf87b4de2d2e82a55da8039766 -
Trigger Event:
push
-
Statement type:
File details
Details for the file xmtp-0.1.5-py3-none-any.whl.
File metadata
- Download URL: xmtp-0.1.5-py3-none-any.whl
- Upload date:
- Size: 55.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8a370ebe10abf7c299806edf0f0e6fbddac8b71e6d02e2ab095509d92fbab0b
|
|
| MD5 |
0cd4c1859ac56a919dd93f771c3ffe38
|
|
| BLAKE2b-256 |
59f0f2a69cc28306717e27ea131e0e7d98bbdf7cdcee5bd8eb228ed09b9d5b34
|
Provenance
The following attestation bundles were made for xmtp-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on pierce403/xmtp-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xmtp-0.1.5-py3-none-any.whl -
Subject digest:
d8a370ebe10abf7c299806edf0f0e6fbddac8b71e6d02e2ab095509d92fbab0b - Sigstore transparency entry: 844574439
- Sigstore integration time:
-
Permalink:
pierce403/xmtp-py@46ce3dd46f1479bf87b4de2d2e82a55da8039766 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/pierce403
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@46ce3dd46f1479bf87b4de2d2e82a55da8039766 -
Trigger Event:
push
-
Statement type: