Quick Reference · NSE India market data in Python

nselib cheat sheet

One idea unlocks the whole library: nselib is a thin, read-only façade over NSE India's public web reports — no client to build, no API key. You pick the module for your market segment (capital_market, derivatives, indices …), call the function for the report you want, and get a tidy pandas DataFrame back. Bound time with a date range or a period shorthand.

setup & shape capital market ★core derivatives · F&O indices & lists filings & activity FPI · debt · funds gotcha / caveat most common

Distilled & cross-checked against: github.com/RuchiTanmay/nselib (official README + API reference) · PyPI · nseindia.com report pages · community guides (Medium/AlgoTrading) — verified live against installed nselib 2.5.1. Re-verified 2026-08-30: 2.5.1 (1 May 2026) still current on PyPI; NSE-endpoint dependent.

The mental model — module = segment, function = report, DataFrame back
YOUR CODE NSE INDIA · PUBLIC WEB PANDAS a module function capital_market. price_volume_data( symbol="SBIN", period="1M") one call no key · no client NSE India nseindia.com report / archive endpoint scraped & parsed for you IP-gated · rate-limited → CSV / JSON pandas DataFrame tidy, ready to analyze Symbol Series Date Open High Low Close Volume Delivery%… → straight into pandas/plots PICK THE MODULE FOR YOUR SEGMENT — ALL ROADS LEAD TO A DATAFRAME capital_market prices · bhav · deals derivatives futures · options · OI indices lists · constituents debt tradable secs nsdl_fpi / cash FPI flows · AMFI nselib (utils) holidays · logging one pandas DataFrame (a few return a list or dict)
quickstart.py
# pip install nselib   —   no key, no client, just import the segment
from nselib import capital_market as cm, derivatives as fno, indices

# 1 · price + delivery history — pass EITHER a date range OR a period
df = cm.price_volume_and_deliverable_position_data("SBIN", period="1M")
df = cm.index_data(index="NIFTY 50", from_date="01-01-2024", to_date="31-03-2024")

# 2 · one trading day's EOD bhav copy (single trade_date)
bhav = cm.bhav_copy_with_delivery(trade_date="20-06-2024")

# 3 · derivatives — futures history + a live option chain
fut  = fno.future_price_volume_data("BANKNIFTY", "FUTIDX", period="1M")
oc   = fno.nse_live_option_chain("NIFTY", oi_mode="compact")

# 4 · index constituents — everything comes back as a DataFrame
n50  = indices.constituent_stock_list("BroadMarketIndices", "Nifty 50")
# dates are dd-mm-YYYY strings · run from an Indian IP · unofficial & read-only
01Setup & importget going
02The shape of nselibhow it thinks
03Price · volume · deliverycapital_market · the workhorse
04Historical index & VIXcapital_market
05Bhav copies (EOD dumps)one trade_date each
06Symbol & universe listswho's tradable
07Deals & short sellingcapital_market · range or period
08Live market activitycurrent session
09Corporate filingscapital_market
10VaR, volatility & 52-wkrisk reports · one trade_date
11Derivatives: futures & optionsderivatives
12Live option chain & expiriesderivatives · live
13F&O flows & participantsderivatives · one trade_date
14Indices moduleindices
15FPI / FII activitynsdl_fpi
16Debt & AMFI fundsdebt · cash_market
17Business growth & turnoversegment aggregates
18Utilities · constants · loggingnselib top level
19Gotchas & production notesread before you ship

Four ideas worth a picture

The call anatomy, the two ways to bound time, the segment map, and the derivatives decoder.

1 · Anatomy of a call

Every request reads the same way: which segment, which report, for what window.

capital_market .price_volume_data ( "SBIN", period="1M" ) module = segment function = the report subject + time window returns pandas DataFrame Symbol Series Date OHLC Volume %DlyQttoTradedQty …

2 · Two ways to bound time

Pick one — an explicit range, or a rolling period ending today.

from_date + to_date "01-01-2024" → "31-03-2024" exact custom range period="1M" 1D 1W 1M 3M 6M 1Y rolling window, ends today or never both t from → to period today trade_date reports want a single point on this line, not a span.

3 · The segment map

Six modules, each owning a slice of NSE — all returning DataFrames.

capital_market price · bhav · deals · VaR derivatives futures · options · OI indices lists · constituents debt tradable securities nsdl_fpi / cash FPI flows · AMFI market nselib (utils) holidays · logging DataFrame

4 · Derivatives decoder

The instrument code is just index-vs-stock × future-vs-option.

FUTURE OPTION INDEX STOCK FUTIDX OPTIDX FUTSTK OPTSTK for OPTIONS add option_type "CE" · "PE" oi_mode "full" · "compact" future_price_volume_data(symbol, instrument, …) option_price_volume_data(symbol, instrument, option_type, …) live chain instead? → nse_live_option_chain(symbol, expiry_date, oi_mode)

Worth memorizing

date format'dd-mm-YYYY' strings — '01-06-2024', never ISO
time windowpass from_date+to_date OR period — not both
period codes1D 1W 1M 3M 6M 1Y (futures: no 1Y)
trade_datebhav/VaR/vol reports = one session; holidays → empty
no clientno key, no object — import the segment, call a function
returnsa pandas DataFrame (a few give a list/dict)
losersto_get="loosers" — the library's double-o spelling
index_datawants the name "NIFTY 50", not "NIFTY"/"^NSEI"
IP + rateNSE gates non-Indian IPs; add sleeps/retries, avoid loops
live hoursoption chain / gainers / market_watch: 09:15–15:30 IST
2.5.1 bugcash_market/mutual_funds may ImportError → use nsdl_fpi
debugnselib.enable_logging(logging.DEBUG) to see the requests