$ pip install nsepython★ LOCALThe laptop/Windows/Jupyter edition — uses Pythonrequests. Works from an Indian residential or VPN IP.$ pip install nsepythonserverThe cloud edition (AWS, Colab, DigitalOcean) — uses thecurlmethod. Same function names; importnsepythonserverinstead.from nsepython import *★Flat namespace — every helper is top-level. Docs usensepythoneven for server code for simplicity.nsesymbolpurify("M&M")Cleans a symbol for NSE's URL encoding (e.g. ampersands) before you pass it on.NSE blocks datacenter IPs★NSE's robots.txt blocks all web servers. The local edition can't run on cloud hosts — use nsepythonserver on an Indian server.
helper(…) → nsefetch(url) → JSON★ MODELEvery helper wraps a specific NSE/NIFTY endpoint; all of them go through the onensefetchprimitive.returns dict | DataFrame★Live quotes & chains come back as raw dicts; history, movers & FII/DII come back as DataFrames. Watch which you're getting.nse_marketStatus()Full market-status payload (all segments) as JSON.is_market_open(segment="FO")Boolean — is that segment open right now.running_status()Cheap clock check:Truebetween 09:15 and 15:30 IST (doesn't hit the network).
nse_eq("SBIN")★ MOST USEDThe full equity quote payload — price, OHLC, 52wk, delivery, industry, everything NSE shows on the quote page.nse_quote_ltp("RELIANCE")★Just the last-traded price as a number — the lightweight call for a live LTP.nse_quote("SBIN", section="trade_info")Lower-level quote fetch; passsectionto target a sub-block of the payload.quote_equity("SBIN") · nsetools_get_quote("SBIN")NSEpy-/NSETools-compatible aliases (their function names were migrated here).nse_eq_symbols()List of all equity symbols on NSE — your master lookup.
nse_fno("BANKNIFTY")★Full derivatives quote payload for an underlying — futures & options data as JSON.quote_derivative("SBIN")Derivative quote alias (migrated NSEpy name).nse_expirydetails_by_symbol("NIFTY", meta="Futures")Expiry details for a symbol;meta="Futures"/"Options".nse_custom_function_secfno("SBIN", attribute="lastPrice")Pull one named field straight out of a security's F&O payload.
nse_optionchain_scrapper("NIFTY")★The full raw option-chain JSON (records + filtered) — the source every other option helper parses.option_chain("RELIANCE")Convenience alias for the scrapper — same raw chain payload.nse_optionchain_ltp(payload, strikePrice, optionType, inp=0)Pluck the LTP for one strike/type out of an already-fetched chain payload.indices vs equitiesNIFTY/BANKNIFTY hit the index option-chain endpoint; stock symbols hit the equities one — the helper picks for you.
oi, spot, ts = oi_chain_builder("NIFTY", expiry="latest", oi_mode="full")★ MOST USEDReturns a tuple: OI DataFrame, underlying LTP, and the timestamp.oi_mode="full"/"compact".pcr(nse_optionchain_scrapper("NIFTY"))★Put-Call Ratio = total put OI ÷ total call OI, straight from a chain payload.ATM ≈ round(spot)Use the returnedspotfromoi_chain_builderto find the at-the-money strike (nearest step).
black_scholes_dexter(S0, X, t, σ, r=10, q=0.0, td=365)★Spot, strike, days-to-expiry, volatility → a 10-tuple: call/put theta, call/put premium, call/put delta, gamma, vega, call/put rho.σ = implied volatilityris the rate (%),qthe dividend yield,tdthe day-count basis. No network call — this is local maths.norm(…)The standard-normal helper used inside the Black-Scholes computation.
equity_history("SBIN", "EQ", "01-01-2024", "31-03-2024")★ MOST USEDClean OHLCV history DataFrame. Args:symbol,series(usually"EQ"),start_date,end_date— dates aredd-mm-YYYY.equity_history_virgin("SBIN", "EQ", "…", "…")Same call, but the raw un-processed frame (the "virgin" variant) if you want NSE's original columns.security_wise_archive("01-01-2024", "31-03-2024", "SBIN", series="ALL")Security-wise price/volume archive over a range, from the bhavcopy archive endpoint.auto 40-day chunking★NSE caps history at ~40 days/request — the library loops and stitches the range for you automatically.
derivative_history("NIFTY", "01-01-2024", "31-03-2024", "FUTIDX", "28-03-2024")★F&O history. Args: symbol, start, end,instrumentType,expiry_date, thenstrikePrice+optionTypefor options.index_history("NIFTY 50", "01-01-2024", "31-03-2024")★Historical index OHLC (from the NIFTY Indices endpoint). Use the index display name.expiry_list("NIFTY", type="list")Available expiry dates for a symbol.expiry_history("NIFTY", type="options")Historical expiry-wise data;type="options"/"futures".
nse_get_index_quote("NIFTY 50")★Live quote for one index — last, change, %chg, OHLC.nse_get_index_list() · nse_index()All index names;nse_index()returns the full live all-indices snapshot.index_pe_pb_div("NIFTY 50", "01-01-2024", "31-03-2024")Historical PE, PB & dividend-yield series for an index.index_total_returns("NIFTY 50", "…", "…") · index_info("NIFTY 50")Total-return index history; static index metadata.indiavix()Current India VIX value — the market's volatility gauge.
nse_get_top_gainers() · nse_get_top_losers()★Top gainers / losers as DataFrames — no typo traps here, unlike some sibling libraries.nse_most_active(type="securities", sort="value")Most active by"value"/"volume";type="securities"/"etf"/"sme".nse_get_advances_declines(mode="pandas")Market breadth — advances vs declines across indices.nse_preopen(key="NIFTY", type="pandas")Pre-open session book for a segment key ("NIFTY","FO","BANKNIFTY"…).nse_preopen_movers(key="FO", filter=1.5)Pre-open gainers/losers past a %-move threshold. Alsonse_price_band_hitters(bandtype, view).
fnolist()★List of all F&O-eligible symbols.nse_get_fno_lot_sizes(symbol="all", mode="list")Current lot sizes; pass a symbol for one, ormode="pandas"for a frame.get_fao_participant_oi("28-03-2024")Participant-wise open interest (Client / DII / FII / Pro) for a date.nse_expirydetails(payload, i=0)Extract the i-th expiry from an F&O payload.
get_bulkdeals() · get_blockdeals()★Today's bulk & block deals as DataFrames.nse_largedeals(mode="bulk_deals")Unified large-deals feed;mode="bulk_deals"/"block_deals"/"short_deals".nse_largedeals_historical("01-01-2024", "31-03-2024", mode="bulk_deals")Historical large deals over a date range.nse_blockdeal()Legacy block-deal fetch (migrated name).
nse_fiidii(mode="pandas")★Daily FII & DII cash-segment buy/sell figures.nse_results(index="equities", period="Quarterly")Financial results feed;period="Quarterly"/"Annual".nse_past_results("SBIN")A single company's historical results.nse_events()Corporate event calendar (board meetings, dividends, etc.).nse_circular(mode="latest")NSE circulars feed.
get_bhavcopy("28-03-2024")★Full end-of-day bhavcopy for one trading session as a DataFrame.nse_holidays(type="trading")Holiday list;type="trading"/"clearing".holiday_master()gives the full master.is_market_open(segment="FO")Live open/closed check for a segment — pair with the holiday list before scheduling jobs.
get_beta("SBIN", days=365, symbol2="NIFTY 50")Beta of a stock vs a benchmark over N days.getbetais the shorthand alias.get_beta_df_maker("SBIN", 365)Builds the daily-returns DataFrame that the beta calc runs on — handy for custom stats.whoistheboss()A fun/utility helper bundled with the library.
nsefetch("https://www.nseindia.com/api/marketStatus")★The primitive: primes cookies, GETs any NSE API URL, returns parsed JSON. If no helper exists, build the URL and call this.headers · niftyindices_headersThe pre-built header dicts nsefetch uses — reuse them for your own requests to the NSE / NIFTY Indices hosts.logging.basicConfig(level=logging.DEBUG)The library logs via the stdlibloggingmodule — flip to DEBUG to see the URLs and chunk loops.migrated: NSEpy + NSEToolsThose two unmaintained libraries' function names were absorbed here, so old snippets often just work.
local won't run on cloud★NSE blocks datacenter IPs. On AWS/GCP/Colab usensepythonserver, and it must be an Indian server IP.dict vs DataFrame★Quotes/chains return raw dicts (index into the JSON yourself); history/movers return DataFrames. Mixing them up is the #1 bug.history dates = dd-mm-YYYY★Strings like"01-06-2024", not ISO.equity_historyalso needs aseries("EQ").oi_chain_builder returns a tuple(oi_df, spot_ltp, timestamp)— unpack all three; don't treat it as a single frame.live = market hours onlyQuotes, option chain & movers are empty/stale outside 09:15–15:30 IST and on holidays.rate-limit & cookiesNSE throttles bursts; nsefetch re-primes cookies each call. Add sleeps/retries, don't hammer in tight loops.unofficial · pin your versionScrapes NSE's public JSON APIs; endpoints shift often. Pin the version, expect breakage, personal research only.