A Python package for interfacing with Dhali
Project description
dhali-py
A Python library for managing payment channels (XRPL & Ethereum) and generating auth tokens (i.e., payment-claims) for use with Dhali APIs.
Includes support for Machine-to-Machine (M2M) payments using seamless off-chain claims.
Installation
pip install dhali-py
Quick Start: Machine-to-Machine Payments
1. XRPL
All signing is performed locally using xrpl-py.
from dhali.dhali_channel_manager import DhaliChannelManager, ChannelNotFound
from dhali.config_utils import get_available_dhali_currencies
from xrpl.wallet import Wallet
from xrpl.clients import JsonRpcClient
seed = "sXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
wallet = Wallet.from_secret(seed=seed)
rpc_client = JsonRpcClient("https://testnet.xrpl-labs.com/")
currencies = get_available_dhali_currencies()
xrpl_testnet = currencies["XRPL.TESTNET"]["XRP"]
# Use the Factory to get an XRPL Manager
manager = DhaliChannelManager.xrpl(
wallet=wallet,
rpc_client=rpc_client,
protocol="XRPL.TESTNET",
currency=xrpl_testnet.currency
)
# Generate a claim (Base64 encoded)
try:
claim = manager.get_auth_token()
except ChannelNotFound:
manager.deposit(1_000_000) # deposit 1 XRP
claim = manager.get_auth_token() # 🔑 regenerate after deposit
print("XRPL Claim:", claim)
2. Ethereum (EVM)
Supports Ethereum, Sepolia, Holesky, etc. Requires eth-account and web3.py.
from dhali.dhali_channel_manager import DhaliChannelManager, ChannelNotFound
from dhali.config_utils import get_available_dhali_currencies
from eth_account import Account
from web3 import Web3
# 1. Setup Account & Provider
private_key = "0x..."
account = Account.from_key(private_key)
w3 = Web3(Web3.HTTPProvider("https://ethereum-sepolia.publicnode.com"))
# 2. Fetch Available Currencies
currencies = get_available_dhali_currencies()
sepolia_rlusd = currencies["SEPOLIA"]["RLUSD"] # or "USDC"
# 3. Instantiate Manager with Dynamic Config
manager = DhaliChannelManager.evm(
account=account,
w3=w3,
protocol="SEPOLIA",
currency=sepolia_rlusd.currency
)
# 4. Generate EIP-712 Signed Claim
# Note: For RLUSD (18 decimals), 1 unit = 10^18. For USDC (6 decimals), 1 unit = 10^6.
amount = int(0.1 * 10**sepolia_rlusd.currency.scale) # 0.01 RLUSD
try:
claim = manager.get_auth_token()
except ChannelNotFound:
manager.deposit(amount)
claim = manager.get_auth_token(amount=amount)
print("EVM Claim:", claim)
Usage in API Calls
Once you have the claim string, include it in your API request query parameters or headers as required by the Dhali Gateway.
import requests
url = f"https://xrplcluster.dhali.io?payment-claim={claim}"
response = requests.post(url, json={"data": "..."})
if response.status_code == 402:
print("Payment Required: Channel may need topping up.")
Classes
DhaliChannelManager (Factory)
xrpl(wallet, rpc_client, protocol, currency, client=None, public_config=None) -> DhaliXrplChannelManagerevm(account, w3, protocol, currency, client=None, public_config=None) -> DhaliEthChannelManager
get_available_dhali_currencies()
Fetches current Dhali configuration and returns a dict:
{
"SEPOLIA": {
"USDC": NetworkCurrencyConfig(currency=..., destination_address=...),
...
},
...
}
Here’s a clean, minimal addition you can append near the end of the README (for example, just before the “Classes” section or after it):
Async Workflows
Currently, dhali-py provides a synchronous interface for managing payment channels and generating claims.
If you would like to see native async/await support (e.g., async workflows using asyncio, async Web3 providers, or async XRPL clients), please drop us a message and let us know. Community feedback helps us prioritise features 🚀
Project details
Release history Release notifications | RSS feed
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 dhali_py-2.0.0.tar.gz.
File metadata
- Download URL: dhali_py-2.0.0.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cde9b9fb9a1ac93e521d708d6bf1423c5843ff5e4f6db7300dd6caedddf2d39e
|
|
| MD5 |
d44dac18415a49b446f481505af9ec1d
|
|
| BLAKE2b-256 |
26e7c11871dcf2475d7c51adafc74ebce3e8bd658dbe7b05ca865a4f0cea584a
|
File details
Details for the file dhali_py-2.0.0-py3-none-any.whl.
File metadata
- Download URL: dhali_py-2.0.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f303a2da9ffbd5b9b0cb08cc443dc984d02c145e8973be9228f218235732a4fc
|
|
| MD5 |
93cdc3651b933be4f2929345c41e2e94
|
|
| BLAKE2b-256 |
1297347900d6e6185128a79ffb8a798b1956e917d7e2ee4c161bafefa8e1be15
|