Unofficial Python Api for NSE India stock exchange
A lightweight Python client for the National Stock Exchange of India. Built for traders, analysts, and quant developers who need reliable programmatic access to NSE data without having to worry about cookie handling, rate limits, and retries under flaky network conditions.
If you ❤️ my work so far, please 🌟 this repo.
pip install "nse[http2]" See the documentation for installation, configuration, and usage examples.
Documentation has been rewritten for version 5 with updated examples, new code samples, and practical guidance for running the package on servers and in production environments.
It handles the plumbing of talking to NSE so you don't have to. A dedicated Transport layer wraps an httpx.Client session with connection pooling, sends browser-like headers on every request, loads and persists cookies via a pluggable cookie store, and restarts the session transparently if a protocol error occurs.
Every request is rate-limited (default: 3 requests/second) and wrapped in exponential backoff with jitter. Retryable status codes (429, 502, 503, 504) and network errors trigger automatic retries, and Retry-After headers are respected.
Choose the storage backend that fits your deployment:
One consistent interface for the data you actually need:
Tune everything at initialization: custom Limiter for throttling, custom RetryConfig for backoff behaviour, HTTP/2 toggle, per-request timeout, etc.
from datetime import date, datetime from nse import NSE with NSE(download_folder=".") as nse: # Live quote print(nse.equity_quote("HDFCBANK")) # current, next and far month expiry expiry_dates = nse.get_futures_expiry(index="nifty") expiry = datetime.strptime(expiry_dates[0], "%d-%b-%Y") print(expiry) # Compiled option chain with max pain, PCR, ATM chain = nse.compile_option_chain("nifty", expiry_date=expiry) print(chain["max_pain"], chain["pcr"], chain["atm"]) # Historical data with automatic chunking data = nse.fetch_equity_historical_data( "RELIANCE", from_date=date(2023, 1, 1), to_date=date(2024, 1, 1), ) print(len(data), "rows") Credits The retry mechanism in this library is heavily influenced by the excellent httpx-retries package.
That said, the implementation here is not a copy — it is a from-scratch rewrite with a different design. httpx-retries hooks into the httpx transport layer, which is elegant but does not provide full control over the request–response lifecycle. This library needs finer-grained control (for example, to restart the session on RemoteProtocolError, and to integrate with the cookie store). For that reason, the retry logic is implemented directly as a decorator rather than as an httpx transport.
Credit and thanks go to the httpx-retries authors for the API design and for the well-tested header-parsing reference.
nse nse-stock-data stock-market-api stock-news-api
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
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 verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.




