dhanhq
The official Python client for communicating with the DhanHQ API
What it is and what it does
DhanHQ-py is the official Python client for the Dhan trading platform's REST and WebSocket APIs. It abstracts the complexity of communicating with Dhan's trading infrastructure, allowing developers to place and manage orders, stream real-time market data, retrieve historical candles, and query account positions and balances programmatically. The library wraps HTTP requests via the requests library and real-time feeds via websockets, with data serialization handled by pandas.
The package is designed for traders and algorithmic trading systems that need to automate execution and data collection on the Dhan platform. It handles authentication via DhanLogin (OAuth or PIN/TOTP flows), manages credentials through a DhanContext object to reduce credential sprawl, and provides a high-level API for common trading workflows such as placing market or limit orders, querying order status, fetching option chains, and accessing fund details. Version 2.2.0 introduced 200-level market depth, expired options data, super orders for risk management, and IP whitelisting capabilities.
Use it for:
- Automate equity and derivatives order placement and cancellation on NSE and BSE exchanges without manual intervention.
- Build algorithmic trading strategies that consume real-time market depth and tick data via the live market feed.
- Retrieve historical OHLC candles and option chain data for backtesting and analysis workflows.
- Monitor and manage open positions, holdings, and account margins programmatically.
- Implement swing trading systems using Forever Orders (single or OCO) for automated risk and profit management.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Python client library for the Dhan trading API, enabling automated order placement, position management, live market data streaming, and historical data retrieval for equity and derivatives trading.
Yes, if you trade on the Dhan platform and need programmatic order execution or market data access. The library has low install friction, active maintenance, permissive licensing, and no known vulnerabilities. However, v2.2.0 contains breaking changes from v2.1.0, so verify compatibility with your codebase or pin to v2.0.2 if stability is critical. Requires valid Dhan credentials and is only useful if you already have a Dhan trading account.
Install
dhanhq on PyPI
pip
pip install dhanhquv
uv add dhanhqpoetry
poetry add dhanhqInstalling dhanhq
Before you install
Low install friction with a pure Python wheel and four standard runtime dependencies (pandas, requests, websockets, pyOpenSSL). Marked as active maintenance with a recent release in April 2026, though repository metadata is not publicly available.
License in practice
Licensed under MIT, a permissive license that allows commercial and private use with minimal restrictions, making it safe to integrate into most projects.
Quickstart
pip install dhanhq
from dhanhq import DhanContext, dhanhq
dhan_context = DhanContext("client_id", "access_token")
dhan = dhanhq(dhan_context)
dhan.place_order(security_id='1333', exchange_segment=dhan.NSE, transaction_type=dhan.BUY, quantity=10, order_type=dhan.MARKET, product_type=dhan.INTRA, price=0)
Requires valid Dhan broker credentials (client_id and access_token) obtained through OAuth or PIN/TOTP authentication; API access is tied to a Dhan trading account.
Verify before relying
- Whether Python version requirements are enforced (requires_python is unspecified in metadata)
- Stability guarantees for v2.2.0 given the documented breaking changes from v2.1.0
- Real-world latency and reliability of websockets-based market feed under production load
Package facts
| License | MIT LICENSE (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — pandas, requests, websockets, pyOpenSSL |
| Maintenance | actively maintained — 112 days since the last release |
| First released | |
| Downloads | 73,452/month — #14,996 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dhanhq-2.2.0-py3-none-any.whl
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
kiteconnectOfficial Python client for the Kite Connect…
permissive · top 15,000 on PyPI
fyers-apiv3Official Python client library for the Fyers…
permissive · top 15,000 on PyPI
growwapiSDK for connecting to Groww's trading platform…
permissive · top 15,000 on PyPI
py-clob-client-v2Python client library for placing and managing…
permissive · top 15,000 on PyPI
python-binanceUnofficial Python wrapper for the Binance…
permissive · top 15,000 on PyPI
tastytradeAn asynchronous Python SDK for Tastytrade's…
permissive · top 15,000 on PyPI
databentoOfficial Python client for accessing live and…
permissive · top 5,000 on PyPI
shioajiShioaji is a trading API for Taiwan's financial…
unclear · top 15,000 on PyPI
alpaca-pyAlpaca-py is the official Python SDK for…
permissive · top 5,000 on PyPI
tardis-clienttardis-client is a deprecated Python client for…
copyleft · top 15,000 on PyPI