KyberSwap Python SDK
This Python SDK provides a simple and easy-to-use interface for interacting with the KyberSwap Aggregator API. It allows you to fetch swap routes, build transactions, and execute swaps on supported chains. The SDK is designed to be modular, extensible, and developer-friendly.
Before Anything, Thank You KyberSwap!
We would like to extend our heartfelt thanks to KyberSwap for providing such an amazing and free service. Your aggregator API has made it incredibly easy for developers to integrate decentralized swaps into their applications. Keep up the great work!
Developed with ❤️ by Harsh from BaseNerds/Basehound.
For questions or feedback, feel free to reach out!
Features
- Chain Selection: Easily switch between supported chains (e.g., Ethereum, Polygon, BSC, Arbitrum, etc.).
- Route Fetching: Fetch the best swap route for a given token pair.
- Swap Execution: Build and execute swaps with encoded transaction data.
Installation - Tested on Python 3.10 or higher.
- Pip install Library
pip install kyberswap_py_sdk
-
Or Directly Clone the repository:
git clone https://github.com/your-repo/kyberswap-python-sdk.git cd kyberswap-python-sdk pip install -r requirements.txt
Usage - Example with Polygon
1. Initialize the SDK
To use the SDK, initialize it with the desired chain, RPC URL, and your private key (optional for read-only operations).
from kyberswap_py_sdk import KyberSwapSDK, ChainName, Token
import asyncio
# Define tokens - 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE represents ETH
token_in = Token(
address="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
chain_id=ChainId.BASE,
decimals=18,
symbol="ETH",
name="Ethereum"
)
token_out = Token(
address="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
chain_id=ChainId.BASE,
decimals=18,
symbol="USDC",
name="USDC"
)
token_in_amount = 0.1
# Initialize SDK
private_key = "YOUR_PRIVATE_KEY" # Replace with your actual private key
sdk = KyberSwapSDK(
chain=ChainName.BASE,
rpc_url="YOUR_RPC_OF_CHOICE",
private_key=private_key)
# get swap route
swap_route = asyncio.run(sdk.get_swap_route(token_in,
token_out,
amount_in=token_in_amount))
# get info about swap route
print(f"Swap Route: {swap_route}")
route_gas = int(swap_route['routeSummary']['gas'])
route_gas_price = int(swap_route['routeSummary']['gasPrice'])
# # Execute swap
# # Legacy Transaction (Type 0)
# tx_receipt = asyncio.run(sdk.execute_swap(
# token_in,
# token_out,
# amount_in=token_in_amount,
# gas=route_gas*1.5,
# gas_fee_wei= route_gas_price,
# txn_type=0
# ))
# # EIP-2930 Transaction (Type 1)
# tx_receipt = asyncio.run(sdk.execute_swap(
# token_in,
# token_out,
# amount_in=0.1,
# slippage_tolerance=10,
# gas=int(route_gas*3),
# gas_fee_wei=int(route_gas_price*1.5),
# txn_type=1,
# access_list=[{
# "address": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", # USDC contract
# "storageKeys": ["0x0000000000000000000000000000000000000000000000000000000000000000"]
# }]
# ))
# EIP-1559 Transaction (Type 2)
tx_receipt = asyncio.run(sdk.execute_swap(
token_in,
token_out,
amount_in=token_in_amount,
slippage_tolerance=10,
gas=route_gas*3,
gas_fee_wei=route_gas_price*1.5,
txn_type=2,
max_priority_fee_wei=route_gas_price*1.1
))
if tx_receipt:
print(f"Swap executed successfully! Transaction: {tx_receipt}")
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for kyberswap-py-sdk 0.2.8
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 | |
|---|---|---|---|---|
| kyberswap_py_sdk-0.2.8.tar.gz | 5.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kyberswap_py_sdk-0.2.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.1 kB
Release files / kyberswap_py_sdk-0.2.8.tar.gz
| Download URL | kyberswap_py_sdk-0.2.8.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4c89b3825637573bb41ded11b315f6ca52f6e2c00bafb96a9123b180aa04f709
|
|
BLAKE2b-256 checksum How to use checksums |
16dac9497454456a0738db1c2cd298d587f85e4ab9a11af171b33949d050a0d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.9
|
Release files / kyberswap_py_sdk-0.2.8-py3-none-any.whl
| Download URL | kyberswap_py_sdk-0.2.8-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2db89a825f994139246f928bac0590494879b9fb8eb6c6170bb1baf6642ebbf
|
|
BLAKE2b-256 checksum How to use checksums |
61d5a95ec2329b60df54c97cd8289e3d1086cd1dc1c06bc385326788d3878cd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.10.9
|
Security for kyberswap-py-sdk 0.2.8
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.