ravnexchange
Typed Python client for RAVN's public /api/v1: quote, execute, submit-signature, submit-transaction, status,
tokens, chains. Zero runtime dependencies (built on urllib.request, not requests).
Same scope as the official TS client (@ravnexchange/sdk); for an agent that already speaks
MCP, RAVN's MCP server (see the root README) covers this
and more; this package is for a plain, non-agent Python backend that wants a typed wrapper
instead of hand-rolling HTTP calls against the JSON API.
Install
pip install ravnexchange
Usage
from ravnexchange import RavnClient, RavnApiError
client = RavnClient(api_key="rvn_live_...") # omit for the anonymous tier
try:
quote = client.get_quote({
"inputChainId": 1,
"outputChainId": 8453,
"inputToken": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"outputToken": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"inputAmount": "1000000000000000000",
# Must be a real 0x-prefixed 40-hex-char address: a malformed one fails as NO_LIQUIDITY,
# not a clear validation error.
"userAddress": "0xYourWalletAddress",
"destinationAddress": "0xYourWalletAddress",
})
except RavnApiError as e:
print(e.code, str(e))
else:
execution = client.execute({"quoteToken": quote["quoteToken"]})
# branch on execution["executionType"]: TRANSACTION / SIGNATURE / DEPOSIT
Pass "sandbox": True on get_quote to test the full quote → execute → status flow with no
real funds; see the API's own docs for per-venue exceptions (THORChain BTC-source,
Chainflip, and Houdini Swap can't be sandboxed).
Hinkal private swaps (0.1.7)
Hinkal races on a confidential quote only when you pass "authorizeSteps": True (or
"onlyVenues": ["hinkal"]). execute then answers executionType: "AUTHORIZE" twice before the
deposit TRANSACTION: check the step with check_authorize, have the paying wallet sign sign
(personal_sign its message, or eth_signTypedData_v4 its typedData) and call execute again
with the same quoteToken, the authorization and the signature. See
AUTHORIZE steps.
import time
from eth_account import Account
from eth_account.messages import encode_defunct
from ravnexchange import check_authorize, check_hinkal_deposit
account = Account.from_key(private_key) # the paying wallet: userAddress
params = {"inputChainId": 8453, "inputToken": USDC, "inputAmount": "20000000", "userAddress": account.address,
"destinationAddress": recipient, "confidential": True, "authorizeSteps": True}
quote = client.get_quote(params)
execution = client.execute({"quoteToken": quote["quoteToken"]})
while execution["executionType"] == "AUTHORIZE":
check_authorize(execution, params) # raises UnsafeExecutionError before anything is signed
sign = execution["sign"]
if sign["method"] == "personal_sign":
signature = account.sign_message(encode_defunct(text=sign["message"])).signature
else:
order_received = time.time() # the deposit must be sent within 10 minutes of this
signature = account.sign_typed_data(full_message=sign["typedData"]).signature
# Bytes or hex without 0x (hexbytes 1.x's .hex()) both go out as 0x hex.
execution = client.execute({"quoteToken": quote["quoteToken"], "authorization": execution["authorization"],
"signature": signature})
check_hinkal_deposit(execution, params) # before sending anything: approval, deposit, RAVN's fee
# then send execution["calls"] (or approval, transaction, fee["transaction"]) as for any TRANSACTION
Sign step 2 within about 6 minutes of receiving it (with under 4 of the 10 left, the order is
refused), and send the deposit within 10 minutes of receiving it: the TRANSACTION has no deadline
field. check_hinkal_deposit raises UnsafeExecutionError unless that TRANSACTION only pays
the deposit, as the TS client's check does: Hinkal's prooflessDeposit of the input token alone
for at most the input amount; on a token sell, an approve() of that token to Hinkal's contract
for at most the input amount; RAVN's fee only to RAVN's fee wallet and at most 1%; all of it within
the input amount; calls exactly those transactions. This client checks only Hinkal's answers:
nothing for other venues.
A failed Hinkal swap isn't refunded on its own. recover_stuck_funds gets the funds back to the
wallet that paid, checking every step before that wallet signs it:
from ravnexchange import recover_stuck_funds
recovered = recover_stuck_funds(
client,
status_ref=execution["statusRef"],
user_address=account.address, # from your own wallet, never from a RAVN answer
sign_message=lambda message: account.sign_message(encode_defunct(text=message)).signature,
sign_typed_data=lambda typed: account.sign_typed_data(full_message=typed).signature,
)
# [{"chainId", "tokenAddress", "amount"}]: amounts before Hinkal's recovery fee
client.recover(params, user_address) makes one call of that flow (POST /v1/recover), checked
the same way (check_recovery; a bad answer raises UnsafeExecutionError). A recovery is public:
an ordinary on-chain payment back to the paying wallet. See
POST /recover.
Parity with @ravnexchange/sdk 0.2.0
Same calls and the same wire shapes: responses are plain dicts, so new API fields such as an
execution's sandbox and approval.reset pass through as they are. What the TS client has and this
one doesn't yet:
- No
execute_and_track. You sequence approval, swap, RAVN's fee and status polling yourself. Do it the way the TS helper does: wait for the approval's receipt before the swap; sendapproval.reset(when present) and wait for it before the approval; never sign or send anything from an execution withsandbox: True; sendfee["transaction"]only once the swap's own receipt says success; pass its hash astx_hashon everyget_statuspoll; keep polling pastexpired(a refund is due), about once a minute, untilrefunded, and pastnot_found(brief right after sending while a venue indexes; otherwise permanent, so bound your polling). - No retries. Retry a status poll yourself on
RATE_LIMITED, a 5xx (INTERNAL,BUILD_FAILED,VENUE_RATE_LIMITED) or a network error, waitinge.details["retryAfterSec"]when it's set. Never re-submit a signature afterBUILD_FAILED: the order may be placed. RavnApiErrorhas nostatusorretry_after_sec. Reade.codeande.details.get("retryAfterSec").timeoutMsisn't inGetQuoteParamsyet: pass it anyway (a dict key goes through as is).- A network failure raises
urllib.error.URLError, not aRavnApiError(the TS client wraps it asNETWORK_ERROR). - No check before the wallet on executions (the TS client's from 0.3.0), except Hinkal's:
check_authorize,check_hinkal_depositand the recovery answers (check_recovery, run byrecover). Check what you sign or send for any other venue yourself.
Status
Published to PyPI via .github/workflows/publish-python-sdk.yml using trusted publishing
(OIDC, no stored token), same model as this repo's npm packages, on a push to main that
bumps pyproject.toml's version.
Metadata
Release files for ravnexchange 0.1.7
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 |
|---|---|---|---|---|
| ravnexchange-0.1.7.tar.gz | 21.2 kB | With provenance | Details for ravnexchange-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ravnexchange-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for ravnexchange-0.1.7-py3-none-any.whl |
Total release size: 36.8 kB
Release files / ravnexchange-0.1.7.tar.gz
| Download URL | ravnexchange-0.1.7.tar.gz |
|---|---|
| Size | 21.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57c79416ce1c614bc98a5cfa015597c645e50ec25b25c835c4675b1d47283542
|
|
BLAKE2b-256 checksum How to use checksums |
044f4908405512c9fd06d4778c5510032d306758e6dfa9471ec94507290824ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logRelease files / ravnexchange-0.1.7-py3-none-any.whl
| Download URL | ravnexchange-0.1.7-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
241366a7900262113aed8f54d1c9dcddbdac6f299b207df56427cf1c1961880a
|
|
BLAKE2b-256 checksum How to use checksums |
c6f2829f37cae295ac64931958965f583e183731ddfdc25262e3010e002a0c51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for ravnexchange 0.1.7
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ravnexchange-0.1.7.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA 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.