Skip to content
Request a review

Hyperliquid API & Python SDK · SDK Setup & Authentication · 1/8

Hyperliquid Python SDK: Installation and Setup

Overview

The hyperliquid-python-sdk is the official Python SDK for interacting with the Hyperliquid exchange (source). It wraps the HTTP API (POST /info for reads, POST /exchange for signed actions) and the WebSocket feed, handling request signing and nonces for you. Code in this course matches SDK v0.24.0 (October 2026), which requires Python 3.9 or newer.

Installation

pip install hyperliquid-python-sdk

Or with a virtual environment (recommended):

python -m venv venv
source venv/bin/activate  # Linux/Mac
pip install hyperliquid-python-sdk

Core Classes

The SDK is built around two classes, Info and Exchange; WebSocket streaming is reached through Info:

1. Info — Read-Only Data

from hyperliquid.info import Info
from hyperliquid.utils import constants

info = Info(base_url=constants.MAINNET_API_URL, skip_ws=True)  # skip_ws=True: REST only

The Info class provides read-only access to:

2. Exchange — Trading Operations

import os
import eth_account
from hyperliquid.exchange import Exchange
from hyperliquid.utils import constants

wallet = eth_account.Account.from_key(os.environ["HL_PRIVATE_KEY"])  # never hardcode keys
exchange = Exchange(wallet, base_url=constants.TESTNET_API_URL)  # testnet while learning

The Exchange class handles authenticated operations:

3. WebSocket — Real-Time Data

There is no separate WebSocket class. Unless you pass skip_ws=True, Info opens a connection to wss://api.hyperliquid.xyz/ws (derived from base_url) and you subscribe with callbacks:

from hyperliquid.info import Info
from hyperliquid.utils import constants

info = Info(base_url=constants.MAINNET_API_URL)
info.subscribe({"type": "allMids"}, print)

Testnet vs Mainnet

Always develop on testnet first:

Environment API URL WebSocket URL
Mainnet https://api.hyperliquid.xyz wss://api.hyperliquid.xyz/ws
Testnet https://api.hyperliquid-testnet.xyz wss://api.hyperliquid-testnet.xyz/ws

Authentication

Hyperliquid uses Ethereum-style signatures instead of exchange-issued API keys. Every /exchange request is signed by a private key. This means:

import eth_account

# From private key
wallet = eth_account.Account.from_key("0x...")

# Your address
print(wallet.address)  # 0x...

Security Note: Never hardcode private keys. Use environment variables or a secrets manager.