Skip to main content

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

import uuid

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:
    # A key per swap attempt (0.1.8+): asking again with it after a lost answer can't build twice.
    # Each answer to an AUTHORIZE step (Hinkal, below) is an execute of its own, with a key of its own.
    execution = client.execute({"quoteToken": quote["quoteToken"], "idempotencyKey": str(uuid.uuid4())})
    # 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
import uuid
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"], "idempotencyKey": str(uuid.uuid4())})
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, "idempotencyKey": str(uuid.uuid4())})  # a new key per step
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; send approval.reset (when present) and wait for it before the approval; never sign or send anything from an execution with sandbox: True; send fee["transaction"] only once the swap's own receipt says success; pass its hash as tx_hash on every get_status poll; keep polling past expired (a refund is due), about once a minute, until refunded, and past not_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, waiting e.details["retryAfterSec"] when it's set. Never re-submit a signature after BUILD_FAILED: the order may be placed. Ask execute again only with the same idempotencyKey, and only after a network error, RATE_LIMITED, VENUE_RATE_LIMITED or UNAVAILABLE.
  • RavnApiError has no status or retry_after_sec. Read e.code and e.details.get("retryAfterSec").
  • timeoutMs isn't in GetQuoteParams yet: pass it anyway (a dict key goes through as is).
  • A network failure raises urllib.error.URLError, not a RavnApiError (the TS client wraps it as NETWORK_ERROR).
  • No check before the wallet on executions (the TS client's from 0.3.0), except Hinkal's: check_authorize, check_hinkal_deposit and the recovery answers (check_recovery, run by recover). 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.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ravnexchange 0.1.8
File Size Uploaded Provenance Actions
ravnexchange-0.1.8.tar.gz 22.0 kB With provenance Details for ravnexchange-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ravnexchange 0.1.8
File Interpreter ABI Platform Actions
ravnexchange-0.1.8-py3-none-any.whl Python 3 none any Details for ravnexchange-0.1.8-py3-none-any.whl

Total release size: 38.2 kB

Release files / ravnexchange-0.1.8.tar.gz

Download URL ravnexchange-0.1.8.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7629cb605bb61f22159b64316ccf14f7298b75187d06f1d5fc8a9b89b99188e0
BLAKE2b-256 checksum
How to use checksums
57bbe1c03c4c250155e41805b5271dc0a91a53afbdd38bd2a77340f2bc8802c6
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 Nov 18, 2026.

Transparency log

Release files / ravnexchange-0.1.8-py3-none-any.whl

Download URL ravnexchange-0.1.8-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cabbd87bf6eadfe2cc1c094d6c1b3b1d4cf5080634aedb7f3b103f87f6f0c45
BLAKE2b-256 checksum
How to use checksums
1692761955f86ff12b6077fa0475ced1bb6aa8429d45120bac1cebf487d8a579
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 Nov 18, 2026.

Transparency log

Security for ravnexchange 0.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ravnexchange-0.1.8.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 Nov 18, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page