{"id":7295,"library":"hyperliquid-python-sdk","title":"Hyperliquid Python SDK","description":"The `hyperliquid-python-sdk` provides a comprehensive SDK for interacting with the Hyperliquid decentralized exchange API in Python. It allows programmatic access to market data, order placement, and account management functionalities. Currently at version 0.23.0, the library maintains a rapid release cadence with frequent minor updates, introducing new features, improvements, and bug fixes.","status":"active","version":"0.23.0","language":"en","source_language":"en","source_url":"https://github.com/hyperliquid-dex/hyperliquid-python-sdk","tags":["crypto","trading","dex","hyperliquid","defi","blockchain"],"install":[{"cmd":"pip install hyperliquid-python-sdk","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Used for fetching public market data and account information.","symbol":"Info","correct":"from hyperliquid.info import Info"},{"note":"Used for authenticated operations like placing orders, managing positions, and transferring funds.","symbol":"Exchange","correct":"from hyperliquid.exchange import Exchange"},{"note":"Helper class to manage cryptographic keys and generate wallet addresses.","symbol":"Wallet","correct":"from hyperliquid.utils import Wallet"}],"quickstart":{"code":"import os\nfrom hyperliquid.info import Info\n\n# Configuration\n# Mainnet API URL for public data\nMAINNET_API_URL = \"https://api.hyperliquid.xyz\"\n\ntry:\n    # Initialize Info client for public market data\n    info_client = Info(MAINNET_API_URL)\n\n    print(f\"Fetching market data from Hyperliquid Mainnet: {MAINNET_API_URL}\")\n\n    # Get all mid prices\n    mids = info_client.all_mids()\n    print(\"\\nMid prices for all assets:\")\n    # Print only a few for brevity\n    for i, (asset, price) in enumerate(mids.items()):\n        if i >= 5: # Limit to first 5 assets\n            break\n        print(f\"  {asset}: {price}\")\n    if len(mids) > 5:\n        print(f\"  ... ({len(mids) - 5} more assets)\")\n\n    # Example of getting an asset's ID\n    eth_asset_id = info_client.asset_to_id(\"ETH\")\n    print(f\"\\nETH Asset ID: {eth_asset_id}\")\n\n    # To use the Exchange client for authenticated operations (e.g., placing orders),\n    # you would need a private key set in an environment variable:\n    # PRIVATE_KEY = os.environ.get(\"HL_WALLET_PRIVATE_KEY\", \"\")\n    # if PRIVATE_KEY:\n    #     from hyperliquid.utils import Wallet\n    #     from hyperliquid.exchange import Exchange\n    #     wallet = Wallet(PRIVATE_KEY)\n    #     exchange_client = Exchange(wallet, MAINNET_API_URL)\n    #     print(f\"\\nExchange client initialized for address: {wallet.address}\")\n    # else:\n    #     print(\"\\nSet HL_WALLET_PRIVATE_KEY environment variable to use Exchange client.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the `Info` client to fetch public market data like mid prices for assets on Hyperliquid Mainnet. It also includes commented-out code showing how to set up the `Exchange` client for authenticated operations, which requires a private key from an environment variable (`HL_WALLET_PRIVATE_KEY`). Ensure Python 3.9+ is used."},"warnings":[{"fix":"Review your code for `perp_dex_class_transfer` calls and update to use alternative or new transfer mechanisms if applicable, or remove the deprecated functionality.","message":"The `perp_dex_class_transfer` action was removed in version `0.16.0`. Any code attempting to use this function will now fail.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"Always pin your dependency to a specific minor version (e.g., `hyperliquid-python-sdk==0.23.*`) and review release notes for each update before upgrading in production environments.","message":"The library is under active and rapid development. Frequent minor version updates often introduce new features, but also new API parameters or slight behavior changes, especially in newer abstraction layers.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Store private keys securely, preferably using environment variables or a secret management service. Always verify you're using the correct key for the targeted network (testnet vs. mainnet).","message":"Handling private keys: The `Exchange` client requires a `Wallet` object initialized with a private key. Incorrect handling (e.g., hardcoding keys, using wrong keys for testnet/mainnet) can lead to 'invalid signature' errors or security risks.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install hyperliquid-python-sdk` to install the library.","cause":"The `hyperliquid-python-sdk` library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'hyperliquid'"},{"fix":"Verify that your `HL_WALLET_PRIVATE_KEY` environment variable holds the correct private key corresponding to the Hyperliquid account you are trying to interact with. Ensure no leading/trailing spaces or incorrect characters. Also confirm you are using the correct network (Testnet/Mainnet) for the key.","cause":"The private key provided to the `Wallet` is incorrect, or the `Exchange` client is attempting to sign a request with a key that doesn't match the associated account on Hyperliquid, or the payload itself is malformed before signing.","error":"hyperliquid.exceptions.HyperliquidError: invalid signature"},{"fix":"Ensure your Hyperliquid account has sufficient funds. You may need to deposit more collateral or reduce the size of your trade.","cause":"An order placement or position adjustment failed because the account does not have enough collateral (margin) to cover the required initial margin for the operation.","error":"hyperliquid.exceptions.HyperliquidError: Insufficient margin"},{"fix":"Check your internet connection, firewall settings, and ensure the base URL for the `Info` and `Exchange` clients is correct (e.g., `https://api.hyperliquid.xyz` for mainnet, `https://api.testnet.hyperliquid.xyz` for testnet). Rarely, it might indicate a temporary issue with Hyperliquid's API servers.","cause":"This specific error indicates an SSL certificate mismatch or a general network connectivity issue to the Hyperliquid API endpoint.","error":"aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host api.hyperliquid.xyz:443 ssl:True [hostname 'api.hyperliquid.xyz' doesn't match 'hyperliquid.xyz']"}]}