Python SDK for Rango Exchange Main API
Rango Aggregation APIs for dApps and Wallets for cross-chain and on-chain swaps using the best route from all of the available on-chain liquidity protocols, getting multichain balance/portfolio for user wallets, and easiest method to transfer tokens across all blockchain networks.
Requirements
This package supports Python 3.8 and newer.
Installation
Install it with:
python -m pip install rango-sdk-py
Alternatively, install from the source code with this command from the project root:
python -m pip install .
For an editable installation while developing:
python -m pip install -e .
Usage
Synchronous client
Client is the synchronous API. Close it when finished, or use a with block.
from decimal import Decimal
from rango_sdk import Client, models
with Client(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = client.routing.get_best_route(body=models.SingleRouteRequest(from_=models.RequestAsset(blockchain=models.Blockchain.ETH, symbol="ETH"), to=models.RequestAsset(blockchain=models.Blockchain.AVAX_CCHAIN, symbol="USDT.E", address="0xc7198437980c041c805a1edcba50c1ce5db95118"), amount=Decimal("0.28")))
Endpoints are nested under attributes (see client.py):
client.balance→BalanceOperationsclient.metadata→MetadataOperationsclient.multi_routing→MultiRoutingOperationsclient.routing→RoutingOperationsclient.transaction→TransactionOperations
Asynchronous client
AsyncClient is the asynchronous API. Use async with and await each call.
import asyncio
from decimal import Decimal
from rango_sdk import AsyncClient, models
async def main() -> None:
async with AsyncClient(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = await client.routing.get_best_route(body=models.SingleRouteRequest(from_=models.RequestAsset(blockchain=models.Blockchain.ETH, symbol="ETH"), to=models.RequestAsset(blockchain=models.Blockchain.AVAX_CCHAIN, symbol="USDT.E", address="0xc7198437980c041c805a1edcba50c1ce5db95118"), amount=Decimal("0.28")))
asyncio.run(main())
Authentication
The Usage section above and the examples/ / docs/ trees show authentication via constructor keyword arguments; This package also supports environment-variable credentials (using RANGO prefix for env vars).
apiKey — API key (query parameter)
- This sdk uses apiKey auth: the credential is sent as the query parameter
apiKey. - Use constructor option
api_key. - Pass these as keyword arguments to
Client(...)/AsyncClient(...). - Alternatively set environment variable
RANGO_API_KEY. Explicit constructor options override env when both are set.
For private or production authentication parameters, contact Rango via hi@rango.exchange or https://t.me/rangoexchange. See the official API documentation.
API Endpoints Reference
For a complete list of all available SDK methods, including detailed parameter descriptions, return values, and code examples, see the API Reference:
Example Codes
The examples below show only the most commonly used endpoints to help you get started quickly.
For advanced usage and less common operations, consult the API Reference.
Get Balance of a Token
Fetches the balance of a specific token address for the user's wallet
Runnable source: get_token_balance.py
from rango_sdk import Client, models
with Client(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = client.balance.get_token_balance(wallet_address="0x9F8cCdaFCc39F3c7D6EBf637c9151673CBc36b88", blockchain=models.Blockchain.BSC, symbol="USDT", address="0x55d398326f99059ff775485246999027b3197955")
print(result)
Get the Best Swap Route
Get the best route to perform a cross-chain or same-chain swap, the requestId parameter from the response of this endpoint will be used for creating the transaction and checking the transaction status in next steps
Runnable source: get_best_route.py
from decimal import Decimal
from rango_sdk import Client, models
with Client(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = client.routing.get_best_route(body=models.SingleRouteRequest(from_=models.RequestAsset(blockchain=models.Blockchain.ETH, symbol="ETH"), to=models.RequestAsset(blockchain=models.Blockchain.AVAX_CCHAIN, symbol="USDT.E", address="0xc7198437980c041c805a1edcba50c1ce5db95118"), amount=Decimal("0.28")))
print(result)
Create the Transaction
Creates a transaction to be signed by user's wallet and broadcasted to the network
Runnable source: create_transaction.py
from decimal import Decimal
from rango_sdk import Client, models
with Client(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = client.transaction.create_transaction(body=models.CreateTransactionRequest(request_id="1978d8fa-335d-4915-a039-77f1a17315f5", step=1, user_settings=models.UserSettings(slippage=Decimal("8.25"), use_max_native_token_balance=False), validations=models.CreateTransactionValidation(balance=True, fee=True, approve=True)))
print(result)
Check the Transaction Status
Checks the status of the transaction using the requestId from the quote/route and the broadcasted transaction hash (txId)
Runnable source: check_tx_status.py
from rango_sdk import Client, models
with Client(api_key='c6381a79-2817-4602-83bf-6a641a409e32') as client:
result = client.transaction.check_tx_status(body=models.CheckTxStatusRequest(request_id="b3a12c6d-86b8-4c21-97e4-809151dd4036", tx_id="0xfa88b705a5b4049adac7caff50c887d9600ef023ef1a937f8f8b6f44e90042b5", step=1))
print(result)
Additional samples for all endpoints live under the examples/ folder.
Advanced Examples
For more advanced walkthroughs, step-by-step guides and custom samples, check the Advanced Examples folder.
Metadata
Release files for rango-sdk-py 0.0.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 | |
|---|---|---|---|
| rango_sdk_py-0.0.1.tar.gz | 36.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rango_sdk_py-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 74.1 kB
Release files / rango_sdk_py-0.0.1.tar.gz
| Download URL | rango_sdk_py-0.0.1.tar.gz |
|---|---|
| Size | 36.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f16b9a84b5ee482d5632444496b75ca5970629368485bd2b1870191560c2cc9e
|
|
BLAKE2b-256 checksum How to use checksums |
219f90ee9ed6c3f4c616899546348e3e51eb60e404825ce34514a522214ae16c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1
|
Release files / rango_sdk_py-0.0.1-py3-none-any.whl
| Download URL | rango_sdk_py-0.0.1-py3-none-any.whl |
|---|---|
| Size | 37.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf5f57e9af6e3507e199c032f84ec5032aab1fb306d01d527d8c5d1d561b7fcf
|
|
BLAKE2b-256 checksum How to use checksums |
1842184402c197414156df2cf941e80430a90445ff674af3fced84b8d1ae483d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Hatch/1.16.5 cpython/3.12.13 HTTPX/0.28.1
|