skillfed

dhanhq

The official Python client for communicating with the DhanHQ API

dhanhq v2.2.0 73.5K downloads/30d#14,996 on PyPI
Permissive license MIT LICENSE Active released

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 dhanhq

uv

uv add dhanhq

poetry

poetry add dhanhq

Installing 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

trading api client pythonautomated order executionreal-time market data feeddhan broker integrationequity derivatives tradinglive market depth streamingtrading account management
trading-apibroker-integrationmarket-data

More WWW/HTTP packages