Skip to main content

NSE — Unofficial Python API for NSE India

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.

Python: >= 3.8

Important Notices

[!CAUTION] Breaking changes in v5.0.0

Upgrading from 4.x? Read the v5.0.0 Migration Guide.

[!WARNING] NSE domain update — v5.1.3

NSE has changed its website domain from nseindia.com to nseindia.in. Upgrade to v5.1.3 or later to maintain compatibility with NSE APIs.

[!NOTE] Python 3.8 and 3.9 support restored in v5.1.0

Python 3.8 and 3.9 are supported again, alongside Python 3.10 and above. See Shared rate limiter configuration for Python 3.8 and 3.9 if you use a shared rate limiter.

If you ❤️ my work so far, please 🌟 this repo.

Installation

pip install nse

For http2 support

pip install "nse[http2]"

See the documentation for installation, configuration, and usage examples.


👽 Documentation

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.

https://bennythadikaran.github.io/NseIndiaApi

Why Use This Library?

🔒 Built-In Session Management

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.

⚡ Automatic Throttling & Retries

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:

  • FileCookieStore (default) — Mozilla-format cookie jar on disk
  • MemoryCookieStore — isolated per-process state for multi-worker servers
  • Custom — subclass CookieStore for Redis, databases, or anything else

📊 Comprehensive Market Coverage

One consistent interface for the data you actually need:

Category Methods
Quotes & Depth quote, equity_quote, get_detailed_scrip_data, equity_meta_info
Options option_chain, compile_option_chain, max_pain, get_futures_expiry
Historical fetch_equity_historical_data, fetch_historical_fno_data, fetch_historical_index_data, fetch_historical_vix_data
Bhavcopies equity_bhavcopy, fno_bhavcopy, delivery_bhavcopy, pr_bhavcopy, indices_bhavcopy
Corporate Filings actions, announcements, board_meetings, annual_reports, financial_results, shareholding, results_comparison
Market Screeners gainers, losers, live_volume_gainers, advance_decline
Listings list_equity_stocks_by_index, list_indices, list_etf, list_sme, list_sgb
IPOs & Deals list_current_ipo, list_upcoming_ipo, list_past_ipo, block_deals, bulk_deals
Misc status, lookup, holidays, circulars, fno_lots

🛠️ Thoughtful Conveniences

  • compile_option_chain — one call gives you max pain, PCR, ATM, max OI strikes, and a clean per-strike structure ready for analysis
  • Fetch Historical data for various segments — chunk large date ranges automatically and return results in chronological order
  • Automatic archive handling — downloads and extracts .zip / .gz bhavcopies transparently
  • Atomic file downloads — writes to .part files, never leaves partial downloads behind
  • Skip-if-exists — already-downloaded files are returned immediately

🧪 Flexible Configuration

Tune everything at initialization: custom Limiter for throttling, custom RetryConfig for backoff behaviour, HTTP/2 toggle, per-request timeout, etc.


Quick Start

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")

Python 3.8 and 3.9 users: Shared rate limiter configuration

When using Python 3.8 or 3.9 with pyrate-limiter 3.9.0, if you pass a shared Limiter instance to NseIndiaApi, initialize it with the additional raise_when_fail=False and max_delay=2000 parameters:

from pyrate_limiter import Duration, Limiter, Rate

throttle = Limiter(
Rate(3, Duration.SECOND),
raise_when_fail=False,
max_delay=2000,
)

This maintains the default behaviour seen in pyrate-limiter v4.x.x versions.

This requirement applies only to Python 3.8 and 3.9, which use pyrate-limiter 3.9.0. Python 3.10 and above use pyrate-limiter 4.5.x and do not require these additional parameters.

Credits

The retry mechanism in this library is heavily influenced by the excellent httpx-retries package.

In particular:

  • The RetryConfig field names (total, max_backoff_wait, backoff_factor, respect_retry_after_header, backoff_jitter) follow the naming used in httpx-retries, so users familiar with that library will feel at home.
  • The _parse_retry_after function is adapted from httpx-retries, which in turn derives its parsing logic from RFC 7231.

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.

Metadata

Release files for nse 5.1.3

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

Source distribution (sdist)

Source distribution for nse 5.1.3
File Size Uploaded Provenance Actions
nse-5.1.3.tar.gz 48.6 kB With provenance Details for nse-5.1.3.tar.gz

Built distribution (wheel)

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

Total release size: 98.6 kB

Release files / nse-5.1.3.tar.gz

Download URL nse-5.1.3.tar.gz
Size 48.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d463ec54e5b1f14d34843aceab2e9d1ae685da4dc4444d0702ebee847cd074a3
BLAKE2b-256 checksum
How to use checksums
664ff76e0e9346c0ecd911416fc0fda243fe2a27206ad09541e4b821c15b27fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 14, 2026.

Transparency log

Release files / nse-5.1.3-py3-none-any.whl

Download URL nse-5.1.3-py3-none-any.whl
Size 50.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25a192de7ce6eaa5d652d6b9d0bec74cd42080dcd765b644aa77c0292b0603f7
BLAKE2b-256 checksum
How to use checksums
7a43e5766e4a22ca6e6fa8ac13efb51d865b3f5a6abae5e3b3560424d13a9537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 14, 2026.

Transparency log

Security for nse 5.1.3

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 nse-5.1.3.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 14, 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.

Release history Release notifications | RSS feed

This release

5.1.3 This release

2 release files Full provenance

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