{"id":23537,"library":"dhanhq","title":"DhanHQ - Official Python Client","description":"The official Python client for communicating with the DhanHQ API, version 2.2.0. Provides access to trading, order management, market data, and portfolio endpoints for the Dhan stock trading platform. Release cadence is irregular.","status":"active","version":"2.2.0","language":"python","source_language":"en","source_url":"https://github.com/dhanhq/dhanhq-python","tags":["trading","stock-market","dhan","api-client"],"install":[{"cmd":"pip install dhanhq","lang":"bash","label":"Latest stable"}],"dependencies":[],"imports":[{"note":"Main client class","symbol":"Dhanhq","correct":"from dhanhq import Dhanhq"}],"quickstart":{"code":"from dhanhq import Dhanhq\n\nclient_id = os.environ.get('DHAN_CLIENT_ID', '')\naccess_token = os.environ.get('DHAN_ACCESS_TOKEN', '')\n\nclient = Dhanhq(client_id, access_token)\n# Get account balance\nfunds = client.get_fund_limits()\nprint(funds)","lang":"python","description":"Initialize the client with your credentials and fetch fund limits."},"warnings":[{"fix":"Implement token refresh logic using the refresh_token endpoint or generate a new token before each trading session.","message":"The access token must be generated via DhanHQ's API flow (not a password). The token is short-lived (typically 1 day) and must be refreshed. Hardcoding tokens will cause auth failures.","severity":"gotcha","affected_versions":"all"},{"fix":"Change import to `from dhanhq import Dhanhq`.","message":"The old import `from dhanhq.dhanhq import Dhanhq` is deprecated. Use `from dhanhq import Dhanhq` instead.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Use `client.place_order(...)` instead of `Order.place_order(...)`.","message":"In version 2.0.0, the `Order` class was removed. All order functions are now methods on the `Dhanhq` client instance.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install dhanhq` in your Python environment.","cause":"The package is not installed or installed in a different environment.","error":"ModuleNotFoundError: No module named 'dhanhq'"},{"fix":"Use `from dhanhq import Dhanhq` (not `from dhanhq.dhanhq import Dhanhq`).","cause":"Incorrect import path, often due to using deprecated import style.","error":"AttributeError: module 'dhanhq' has no attribute 'Dhanhq'"},{"fix":"Generate a new access token via DhanHQ API and ensure it is passed correctly. Check that client_id and access_token are both valid.","cause":"The access token is expired, malformed, or does not match the client ID.","error":"dhanhq.exceptions.InvalidTokenException: Invalid access token"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}