Skip to main content

PyZData

PyPI Python License

Download historical prices from Zerodha — stocks, indices, futures, options and commodities — as CSV, Excel or a pandas DataFrame.

It's free: you need a Zerodha account, but not the paid Kite Connect API.

The PyZData web app, showing a year of daily RELIANCE prices The web app (sample data).


Get started

  1. Install (Python 3.10 or newer):

    pip install "pyzdata[web]"
    
  2. Start the app — your browser opens at http://localhost:8501:

    pyzdata-web
    
  3. Log in with your enctoken, or your Zerodha user ID, password and TOTP.

  4. Pick a stock or contract, a period and a candle size, then press Download.

  5. Save the result as CSV or Excel.

How to get your enctoken

  1. Log in to kite.zerodha.com in your browser.
  2. Press F12 (Mac: Cmd + Option + I) to open Developer Tools.
  3. Open Application (Firefox: Storage) → Cookies → kite.zerodha.com.
  4. Copy the value of the enctoken cookie.

The enctoken changes every time you log in to Kite. If PyZData says you were logged out, copy a fresh one.

What you get

One row per candle, with times in IST, in these columns:

tradingsymbol, datetime, open, high, low, close, volume, open_interest

open_interest is included for futures and options when you ask for it.

  • Candle sizes: 1, 2, 3, 4, 5, 10, 15 and 30 minutes · 1, 2, 3 and 4 hours · 1 day
  • Exchanges: NSE and BSE (stocks, indices) · NFO and BFO (futures & options) · MCX and NCO (commodities) · CDS (currency)

Use it from Python

from pyzdata import PyZData, Interval

with PyZData(enctoken="your_enctoken") as client:
    token = client.get_instrument_token("RELIANCE", "NSE")
    df = client.get_data(token, "2024-01-01", "2024-12-31", Interval.DAY)

df.to_csv("reliance.csv", index=False)
  • Not sure of the symbol? client.search_instruments("NIFTY", exchange="NSE")
  • Futures & options with open interest: client.get_data(token, start, end, Interval.MINUTE_5, oi=True)
  • Log in with your user ID instead: PyZData(user_id="AB1234", password="...", totp="123456")
  • Candle sizes are Interval.MINUTE_1 … Interval.MINUTE_30, Interval.HOUR_1 … Interval.HOUR_4 and Interval.DAY.
  • Errors: AuthenticationError (login failed or logged out), InstrumentNotFoundError (unknown symbol), DataFetchError (logged out during a download). All are importable from pyzdata.

Only need Python, not the web app? pip install pyzdata is enough.

Use it from the command line

# A year of daily candles, saved to a CSV file
pyzdata download --enctoken TOKEN --symbol RELIANCE --exchange NSE \
    --start 2024-01-01 --end 2024-12-31 --output reliance.csv

# 5-minute candles of a futures contract, with open interest
pyzdata download --enctoken TOKEN --symbol NIFTY24JANFUT --exchange NFO \
    --start 2024-01-01 --end 2024-01-25 --interval 5minute --oi --output nifty.csv

# Find the exact symbol
pyzdata search --enctoken TOKEN --query NIFTY --exchange NSE
  • Skip typing the token: set it once with export PYZDATA_ENCTOKEN=TOKEN (PowerShell: $env:PYZDATA_ENCTOKEN = "TOKEN").
  • Log in with your user ID: use --user-id AB1234 instead of --enctoken. PyZData asks for the password and TOTP, so they stay out of your shell history.
  • All options: pyzdata download --help

Good to know

  • Downloads don't give up. If the internet drops or Zerodha is busy, PyZData waits a few seconds and tries again until it works. To stop, press Ctrl+C in the terminal or Log out in the web app.
  • Only a logout stops a download — for example when you log in to Kite somewhere else. Log in again and download once more.
  • Long periods are fine. Zerodha returns a limited span per request (60 days of 1-minute candles, for example), so PyZData splits longer periods for you. Five years of daily candles is a single request.
  • Expired contracts can't be downloaded — Zerodha only lists active futures and options.
  • Your login stays private. It goes only to Zerodha, and the web app is reachable only from your own computer.
  • PyZData is an independent project, not made by or affiliated with Zerodha.

Settings (optional)

Set these environment variables to change how PyZData behaves:

Variable Default What it does
PYZDATA_ENCTOKEN — Enctoken for the command line
PYZDATA_RATE_LIMIT 3 Most requests per second sent to Zerodha
PYZDATA_TIMEOUT 30 Seconds to wait for Zerodha to answer
PYZDATA_CACHE_TTL_HOURS 24 How often the list of instruments is refreshed
PYZDATA_LOG_LEVEL — INFO or DEBUG to see what PyZData is doing

The full list is in .env.example.


Release notes · Report a security issue · MIT License

Made by Vikas Sharma

Metadata

Release files for pyzdata 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyzdata 1.2.0
File Size Uploaded Provenance Actions
pyzdata-1.2.0.tar.gz 52.0 kB With provenance Details for pyzdata-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyzdata 1.2.0
File Interpreter ABI Platform Actions
pyzdata-1.2.0-py3-none-any.whl Python 3 none any Details for pyzdata-1.2.0-py3-none-any.whl

Total release size: 93.3 kB

Release files / pyzdata-1.2.0.tar.gz

Download URL pyzdata-1.2.0.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c13aab28e3d5ceafc2db686d8e43908a999d74371f4b389b74cdcb08e0bbf815
BLAKE2b-256 checksum
How to use checksums
c7ff01751dad11b871a56d3694e8cf9ebbe2ea8bd1714c323bc26b5afc97b7fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Release files / pyzdata-1.2.0-py3-none-any.whl

Download URL pyzdata-1.2.0-py3-none-any.whl
Size 41.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a684a64c10017560acaf7b60e1348b45e355bc7760f03f97e4df249b2faef1c6
BLAKE2b-256 checksum
How to use checksums
93799d0bd7cc9a22eabcf90860445e488c6687e5612a8072bfcbeeea5c2e65ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

Security for pyzdata 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyzdata-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page