Dhan_Tradehull Library Update: Python 3.12 & Authentication Improvements

We have updated our codebase to align with the latest dhanhq library. To use this version, Python 3.10 or higher is required. Therefore, we need to uninstall the existing Python 3.8 installation and upgrade to Python 3.12. Follow the below steps -

Steps to uninstall python 3.8 -

  1. Press Win + IApps
  2. Go to Installed apps (or Apps & Features)
  3. Search Python
  4. You’ll see entries like:
    Python 3.8.10
  5. Click ⋮ / Uninstall on the version you want to remove
  6. Finish uninstall wizard
  7. After uninstall, manually delete these if they exist
    C:\Users<your-username>\AppData\Local\Programs\Python
    C:\PythonXX\
  8. Clean PATH
  • Press Win + Rsysdm.cpl
  • Advanced → Environment Variables
  • Under User variables, select Path → Edit
  • Remove entries like:
    • Python38

Restart the system and Open and run:

python --version
where python

Confirm that python 3.8 is uninstalled.

Files link - https://drive.google.com/file/d/1aibgaUunBozxNt2s5SgoNbGdkd4rW156/view?usp=sharing

:small_blue_diamond: Python 3.12 Installation Steps (Windows)

  1. Download the python-3.12.9-amd64.exe from the shared drive link.
  2. Double-click the downloaded installer to start the setup.
  3. On the first screen, check the option “Add Python to PATH”.
  4. Click Install Now and wait for the installation to complete.
  5. Once installed, close the installer.

:small_blue_diamond: Install Required Libraries

  1. In the same folder as the Python installer, you’ll find a batch file named install libraries.bat.
  2. Double-click the batch file.
  3. The script will automatically install all required Python libraries.
  4. Wait for the process to complete and close the window once finished.

With this, the installation is complete. You can now refer to the following PyPI link for details on the updated functions and usage.
Dhan-Tradehull · PyPI

We have also added two additional login methods.

Since many users were concerned about access token regeneration every 24 hours, the third login method (PIN + TOTP-based login) eliminates this requirement. In this method, users do not need to pass an access token daily. They only need to provide their Dhan PIN and generate a TOTP key from the Dhan terminal, which does not require frequent changes.

Refer the below file for on how to use new login methods-

Hello @Tradehull_Imran .

My Algo was logging in automatially be generating the Fresh Access Token using pin + totp method. But on 22-04-2026, the Access Token was not generated and was not able to login. So generated Token manually and pasted in .env, the algo logged in and started. As i searched on web came to know that Dhan has Closed all the Backdoors for Auto Access Token Generation using pin + totp mode.

Is that True….?

If the user has to mandatorily login to dhan portal everyday to generate Access Token means, how can we automate this process (Except Selenium).

[2026-04-22 09:17:04.105896] INFO: Cached token is from 2026-04-20, today is 2026-04-22. Generating fresh token.
[2026-04-22 09:17:04.106142] INFO: Attempting automated login for Client ID: 11028***** via PIN + TOTP...
[2026-04-22 09:17:04.106399] INFO: OTP generated: 64**** (attempt 1/2)
[2026-04-22 09:17:14.379615] ERROR [AutoLogin]: PIN+TOTP login failed: {'message': 'Invalid TOTP', 'status': 'error'}
[2026-04-22 09:17:14.380227] INFO: Falling through to Method 2 (Access Token)...
[2026-04-22 09:17:14.380357] INFO: Using Access Token from .env (manual fallback)...
[2026-04-22 09:17:18.672785] INFO: Tradehull Client initialized via Access Token for client ID: 11028*****
[2026-04-22 09:17:18.718464] INFO: Current IP configuration: {'status': 'failure', 'remarks': {'error_code': 'DH-901', 'error_type': 'Invalid_Authentication', 'error_message': 'Client ID or user generated access token is invalid or expired.'}, 'data': ''}

Hi @Mahikbs ,

Thanks for bringing this up. @Tradehull_Imran may be able to assist here

HI @Mahikbs ,

The PIN + TOTP method is still working. It automatically generates the access token during login, so the process can continue to be automated without manual intervention.