iWAN Python Client
A Python client for Wanchain iWAN (WebSocket) RPC API.
English
Installation
pip install iwan
Or from source:
git clone https://github.com/Nevquit/iWAN.git
cd iWAN
python setup.py install
Usage
import json
from iwan import IwanClient
# Configuration
URL = 'wss://apitest.wanchain.org:8443/ws/v3/'
API_KEY = 'your_api_key'
SECRET_KEY = 'your_secret_key'
# Initialize Client
client = IwanClient(URL, API_KEY, SECRET_KEY)
# Prepare Request
request = {
"jsonrpc": "2.0",
"method": "getBalance",
"params": {
"address": "your_wanchain_address",
"chainType": "WAN"
}
}
# Send Request
try:
response = client.send_request(request)
print(json.dumps(response, indent=2))
finally:
client.close()
Features
- Automatic Signing: Automatically generates timestamps and signatures for your requests.
- Request ID Handling: Ensures unique IDs for each request using
uuid4if not provided. - Retry Mechanism: Built-in retry logic that validates response IDs.
- SSL Support: Option to skip SSL verification if needed.
API Reference
IwanClient(url, api_key, secret_key, timeout=30, skip_ssl_verify=False)
url: WebSocket endpoint (e.g.,wss://api.wanchain.org:8443/ws/v3/).api_key: Your iWAN API key.secret_key: Your iWAN secret key.timeout: Connection timeout in seconds.skip_ssl_verify: Set toTrueto skip SSL certificate verification.
send_request(request_src, retry=10)
request_src: Dictionary containing the JSON-RPC request.retry: Number of retries on network error or ID mismatch.
中文
安装
pip install iwan
或从源码安装:
git clone https://github.com/Nevquit/iWAN.git
cd iWAN
python setup.py install
使用示例
import json
from iwan import IwanClient
# 配置信息
URL = 'wss://apitest.wanchain.org:8443/ws/v3/'
API_KEY = 'your_api_key'
SECRET_KEY = 'your_secret_key'
# 初始化客户端
client = IwanClient(URL, API_KEY, SECRET_KEY)
# 准备请求
request = {
"jsonrpc": "2.0",
"method": "getBalance",
"params": {
"address": "your_wanchain_address",
"chainType": "WAN"
}
}
# 发送请求
try:
response = client.send_request(request)
print(json.dumps(response, indent=2))
finally:
client.close()
项目特性
- 自动签名:自动为请求生成时间戳(timestamp)和签名(signature)。
- 请求 ID 处理:如果请求中未提供 ID,自动使用
uuid4生成唯一 ID。 - 重试机制:内置重试逻辑,并校验响应中的 ID 是否与请求匹配。
- SSL 支持:支持跳过 SSL 证书校验。
项目结构
iwan_project/
├── src/
│ └── iwan/ # 源代码目录
│ ├── __init__.py
│ └── client.py # 核心客户端逻辑
├── tests/ # 测试代码
├── pyproject.toml # 核心配置文件
├── README.md # 项目说明
└── LICENSE # 许可证
License
This project is licensed under the MIT License.
Metadata
Release files for iwan 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iwan-0.1.1.tar.gz | 5.7 kB | Without provenance | Details for iwan-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iwan-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for iwan-0.1.1-py3-none-any.whl |
Total release size: 10.9 kB
Release files / iwan-0.1.1.tar.gz
| Download URL | iwan-0.1.1.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
add0eae222b6e79ae148268eabcff0d90d75b6e2f26fd5c215c5965c4184cc58
|
|
BLAKE2b-256 checksum How to use checksums |
93a04f89e70e81fdcf32ef74c1ba50d7dee28f8269d4e5193094058df2962c92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Release files / iwan-0.1.1-py3-none-any.whl
| Download URL | iwan-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30f8a515da0d19f996277b025525d809eb3bb0a8856dd17793a037dcb90f2b9c
|
|
BLAKE2b-256 checksum How to use checksums |
3e9037396f0e69e799a75072860d3e75f861acedce9e253fab6128c55bbbd846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.10
|
Security for iwan 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.