Generate Dhan Token Automatically with Python

Looking for a simple way to generate your Dhan token using Python?

You don’t need bots, Streamlit, Selenium, or any scraping hacks—just import the token module and generate the token directly.

:pushpin: Sample code: tinyurl.com/dhan-token
:movie_camera: Quick demo: YouTube - Token Generation Walkthrough

It’s lightweight, straightforward, and easy to integrate into your workflow.

@Hardik Thanks :pray: for Dhan Api V2.0 auth mechanism

2 Likes

why are you sharing an encrypted file ? share the source code

@Kush

Good question, but I think the DHAN team is the right person to explain why they have encrypted the payload passed to the backend during API calls (as shown in the image below).

I don’t have the right to disclose DHAN’s encryption/decryption logic.

But if your concern is about data security, there’s nothing to worry about. Still, if you want to verify, you can trace all data transfers from/to tool using Wireshark or similar TCPDump tools.

If you don’t want to rely on third-party library, you can also automate the process with a Python script, though it will take some effort.

Also, the video I shared was only to demonstrate possibilities, nothing more is possible beyond that.

1 Like

no issue . thanks for showing the proof
the workaround you have coded is selenium based or you have reverse engineered apis @Titamazon

I don’t have the right to disclose DHAN’s encryption/decryption logic.

its all right there in the browser code tho :stuck_out_tongue:

Can we trust the sample code especially the pye file, is it from dhan or personal made file?

no, sharing creds literally means you are handling over the full access of your account.,

Reverse engineering something is totally valid, idk what is his problem with sharing the code. Dont share if you dont want to, share if you do,

But not posting source code of something that involves user’s money is dumb af