Quick Reference · NSE India REST APIs in Python

nsepython cheat sheet

One idea unlocks the whole library: nsepython talks straight to NSE's own REST APIs — the very JSON endpoints nseindia.com and NIFTY Indices call in your browser. Under everything sits nsefetch(url): it primes cookies, GETs a payload URL, and hands back raw JSON. Higher-level helpers wrap specific endpoints and return a dict or a tidy pandas DataFrame. The one thing to pick: editionnsepython (local) vs nsepythonserver (cloud).

setup & mode live quotes ★core options & OI history indices & movers deals · FII · corporate gotcha / caveat most common

Distilled & cross-checked against: unofficed.com/nse-python (official docs) · forum.unofficed.com (docs thread 376) · PyPI · github.com/aeron7/nsepython — verified live against installed nsepython 2.97 (66 functions introspected).

The mental model — nsefetch is the engine; dict or DataFrame comes back
YOUR CALL THE ENGINE NSE · PUBLIC REST API BACK IN PYTHON a helper call nse_eq("SBIN") option_chain("NIFTY") equity_history(…) nsefetch(url) 1 · prime cookies @ nseindia 2 · GET the payload URL 3 · return .json() the primitive under everything NSE / NIFTY Indices nseindia.com/api/… niftyindices.com JSON datacenter IPs blocked → raw dict (JSON) nse_eq · nse_fno · option_chain pandas DataFrame history · movers · fiidii SAME FUNCTION NAMES — PICK THE EDITION THAT MATCHES YOUR ENVIRONMENT nsepython LOCAL · laptops, Windows, Jupyter uses Python requests works from an Indian residential / VPN IP ✗ won't run on AWS / GCP / web servers nsepythonserver SERVER · AWS, Colab, DigitalOcean uses the curl method must run from an Indian server IP ✗ some countries fully blocked or
quickstart.py
# pip install nsepython   (laptops)   ·   pip install nsepythonserver   (cloud)
from nsepython import *          # same names in both editions

# 1 · live quotes — helpers return raw NSE JSON as a dict
q   = nse_eq("SBIN")                 # full equity quote (dict)
ltp = nse_quote_ltp("RELIANCE")        # just last-traded price

# 2 · option chain + OI in one shot
oc, spot, ts = oi_chain_builder("NIFTY", "latest", "full")   # (DataFrame, LTP, time)
ratio = pcr(nse_optionchain_scrapper("NIFTY"))          # put/call ratio

# 3 · history — dd-mm-YYYY strings; auto-chunked in 40-day loops
df  = equity_history("SBIN", "EQ", "01-01-2024", "31-03-2024")

# 4 · everything is built on one primitive — call any NSE endpoint yourself
raw = nsefetch("https://www.nseindia.com/api/marketStatus")
01Setup & the two editionsget going
02The shape of nsepythonhow it thinks
03Live equity quoteraw JSON dicts
04Live F&O quotederivatives
05Option chainthe raw chain
06OI chain builder & PCRthe workhorse
07Option Greeks — Black-Scholespure math, no fetch
08Equity historyDataFrames · dd-mm-YYYY
09Derivative & index historyDataFrames
10Indices & VIXNIFTY Indices data
11Market movers & pre-openlive session
12F&O universe & participantsderivatives structure
13Dealsbulk · block · large
14FII/DII & corporateflows & filings
15Bhavcopy · holidays · statusdaily files & calendar
16Beta & analysisderived metrics
17The nsefetch escape hatchcall any endpoint
18Gotchas & production notesread before you ship

Four ideas worth a picture

How a call resolves, the two editions, the options toolkit, and the history-call shape.

1 · How a call resolves

One primitive underneath — the return shape is all that differs.

nse_eq("SBIN") equity_history(…) nsefetch(url) cookies → GET → json NSE endpoint /api/… returns JSON dict DataFrame

2 · Two editions, one API

Same function names — the package you install depends on where it runs.

nsepython laptop · Windows · Jupyter Python requests ✓ Indian residential / VPN IP nsepythonserver AWS · Colab · DigitalOcean curl method ✓ Indian server IP NSE REST APIs datacenter / foreign IPs blocked

3 · The options toolkit

From one symbol to a chain, OI, a ratio, and the Greeks.

symbol "NIFTY" nse_optionchain_scrapper() raw chain JSON oi_chain_builder() → (OI df, spot LTP, timestamp) pcr() · black_scholes_dexter() put/call ratio · 10 Greeks oi_mode = "full" · "compact" · expiry = "latest" or a date

4 · The history-call shape

Every history helper reads: what, over which dates, in what form.

derivative_history ( symbol, start, end, instrumentType, expiry … ) dates dd-mm-YYYY strings instrumentType FUTIDX FUTSTK OPTIDX OPTSTK for OPTIONS add strikePrice + optionType pandas DataFrame OHLC · OI · volume · turnover equity_history needs series="EQ" · index_history takes just symbol + dates

Worth memorizing

two editionsnsepython (local) vs nsepythonserver (cloud) — same names
IP ruleNSE blocks datacenter IPs; server edition needs an Indian server
the enginensefetch(url) primes cookies → GETs → returns JSON
return typequotes/chains = dict; history/movers = DataFrame
history datesdd-mm-YYYY strings; auto-looped in 40-day chunks
equity_historyalso needs a series arg — usually "EQ"
oi_chain_builderreturns a tuple: (oi_df, spot, timestamp)
instrumentTypeFUTIDX FUTSTK OPTIDX OPTSTK; options add strike+type
pcrput OI ÷ call OI; black_scholes_dexter → 10 Greeks
live hoursquotes / chain / movers: 09:15–15:30 IST only
heritageabsorbed NSEpy + NSETools function names
debuglogging.basicConfig(level=logging.DEBUG) to see URLs