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

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

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.0.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 nse 5.0.0
File Size Uploaded
nse-5.0.0.tar.gz 46.8 kB Details

Built distribution (wheel)

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

Total release size: 95.3 kB

Release files / nse-5.0.0.tar.gz

Download URL nse-5.0.0.tar.gz
Size 46.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c2d2240507f74de4afe1fd9ba2ba83d569aff974d6cb38a34afcd82daa8d56a0
BLAKE2b-256 checksum
How to use checksums
89af28e84b542ba0268b39ad73f4a6ad4020e201f05593e3c624c14eeac0ada6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

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

Download URL nse-5.0.0-py3-none-any.whl
Size 48.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b67fbdd95d4ae7dacfeb2b1d8e2f6403f8e381cb4d0618055bc74acdd95540e1
BLAKE2b-256 checksum
How to use checksums
a2cae1b5ba986a14b8db37c7c7572747c03d632853db12925c169dd5cd6f9e3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

5.0.0 This release

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.1

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.1.1

2 release files

0.0.1

2 release files

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