Metadata-Version: 2.4
Name: walletconnect
Version: 0.1.0
Summary: walletconnect: WalletConnect v2 (Reown) client implementation in Python
Author-email: "ApeWorX Ltd." <admin@apeworx.io>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ApeWorX/walletconnect-py
Project-URL: Issues, https://github.com/ApeWorX/walletconnect-py/issues
Keywords: ethereum,walletconnect,reown
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic<3,>=2.6
Requires-Dist: cryptography<47,>=42
Requires-Dist: websockets<16,>=13
Provides-Extra: qr
Requires-Dist: segno<2,>=1.6; extra == "qr"
Provides-Extra: cli
Requires-Dist: cyclopts<6,>=3.0; extra == "cli"
Requires-Dist: segno<2,>=1.6; extra == "cli"
Dynamic: license-file

# WalletConnect (Python)

A Python client for [WalletConnect v2](https://specs.walletconnect.com/2.0) (now [Reown](https://reown.com)),
so Python tools (e.g. [Ape](https://github.com/ApeWorX/ape) account plugins) can pair with mobile wallets
and relay signing requests to them.

## Status

> [!WARNING]
> This project is being revived and is **pre-alpha**. Core Sign API flow works against the public relay
> for manual testing; APIs may still change.

- **Target:** WalletConnect v2 / Reown **Sign API** (default relay `wss://relay.walletconnect.org`, `irn` JSON-RPC,
  X25519 + ChaCha20-Poly1305 envelopes, a project ID from the [WalletConnect Dashboard](https://dashboard.walletconnect.com)).
- **WalletConnect v1 is dead.** The v1 bridge servers were shut down, and this library will never
  implement the v1 protocol.
  The `0.1.0a0` release on PyPI is an empty pre-v2 skeleton and should not be used.

Progress is tracked in [#1](https://github.com/ApeWorX/walletconnect-py/issues/1).

## Dependencies

- [Python 3](https://www.python.org/downloads) version 3.10 or greater.

## Installation

### via `pip`

Once a release is available, you can install it via [`pip`](https://pypi.org/project/pip/):

```bash
pip install walletconnect
```

### via source

You can clone the repository and install for development:

```bash
git clone https://github.com/ApeWorX/walletconnect-py.git
cd walletconnect-py
uv sync --group dev
uv run prek install
```

## Quick Usage

### Terminal → mobile wallet (manual demo)

1. Create a free project on the [WalletConnect Dashboard](https://dashboard.walletconnect.com) and copy the
   project ID. Existing project IDs from Reown Cloud / the Reown Dashboard keep working.
2. Install from this repo (with the optional QR extra):

```bash
git clone https://github.com/ApeWorX/walletconnect-py.git
cd walletconnect-py
uv sync --extra qr --group test
export WALLETCONNECT_PROJECT_ID=your_32_char_project_id
uv run --extra qr python examples/terminal_connect.py
```

Or with pip from a checkout:

```bash
pip install -e ".[qr]"
export WALLETCONNECT_PROJECT_ID=your_32_char_project_id
python examples/terminal_connect.py
```

Scan the QR with MetaMask / Rainbow / etc., approve the session, then approve `personal_sign` on the phone.

Async Cyclopts variant (uses `SignClient` instead of `SyncSignClient`):

```bash
uv sync --extra cli
export WALLETCONNECT_PROJECT_ID=your_32_char_project_id
uv run --extra cli python examples/async_cli.py
# or: uv run --with 'cyclopts>=3,<6' --extra qr python examples/async_cli.py
```

HTTP service variant ([FastAPI](https://fastapi.tiangolo.com): pair over `POST /pair`, sign via `POST /sessions/{topic}/sign`):

```bash
uv run --group examples --extra qr uvicorn examples.fastapi_app.app:app  # demo page at http://localhost:8000/
```

MCP server variant (an AI assistant pairs a wallet and requests signatures; you approve on your phone):

```bash
uv run --group examples --extra qr python -m examples.mcp_server  # stdio; see docs/userguides/mcp.md
```

The production MCP integration is planned as a feature of the `ape-walletconnect` plugin.

```python
from walletconnect.qr import print_qr
from walletconnect.sign import SyncSignClient
from walletconnect.types import Metadata

client = SyncSignClient(
    project_id="...",  # or set WALLETCONNECT_PROJECT_ID
    # Shown in the wallet; many wallets display the url's host prominently.
    metadata=Metadata(name="My Script", url="https://example.com"),
)
session = client.connect(chains=(1,), on_uri=print_qr)
sig = client.personal_sign("hello", session.eip155_accounts[0].split(":")[-1])
client.close()
```

The client is stateless: it never writes to disk. To keep sessions across restarts, save
`client.export_state().model_dump_json()` wherever you like (file, database, S3) and pass it back
with `SyncSignClient(state=ClientState.model_validate_json(blob))`. The state contains secret
keys, so store it securely. See the [connecting guide](docs/userguides/connecting.md).

For sessions that stay open for weeks, the client emits events (`client.on("session_delete", ...)`),
can extend sessions before they expire (`auto_extend=True`), and can check whether the wallet is
online (`is_reachable()`). See [Long-running sessions](docs/userguides/long-running.md).

Lower-level helpers still work without a relay connection:

```python
from walletconnect import PairingURI
from walletconnect.qr import print_qr  # requires `pip install "walletconnect[qr]"`

uri = PairingURI.generate()
print_qr(uri)
```

`print_qr` draws for a dark terminal background by default; pass `invert=False` for light
backgrounds. Live relay tests skip unless `WALLETCONNECT_PROJECT_ID` is set.

For an automated interoperability check against the official JS Sign client (wallet peer), see [`e2e-js/`](e2e-js/).

## Development

See [CONTRIBUTING.md](CONTRIBUTING.md). Comments, questions, criticisms and pull requests are welcomed.

## License

This project is licensed under the [Apache 2.0](LICENSE).
