SkillAgentSearch skills...

Nsemine

Efficient and Reliable Python Library for Scraping Real-Time and Historical Data of Stocks, Futures, Options and Indices From The NSE Exchange.

Install / Use

npx skills add kbizme/nsemine

Installs into whichever agent you are using.

README

Simplest, Cleanest and Efficient Python Library to Scrape Stocks, FnO & Indices Data From The NSEIndia(New) and NiftyIndices Website.

nsemine is a Python library designed to provide a clean and straightforward interface for scraping data from the National Stock Exchange of India (NSE) and the Nifty Indices website. It aims to simplify the process of retrieving various market data, including indices, stock information, futures & options data, and general NSE-related utilities. This library is built to be efficient and user-friendly, catering to developers, traders, investors who need reliable NSE data for financial analysis, algorithmic trading, and data visualization.

Features

  • Asynchronous Data Retrieval:  Experience non-blocking, asynchronous data retrieval for optimal performance. Leverage the power of asyncio to fetch market data without delays, ensuring your applications remain responsive.

  • High-Speed Data Acquisition:  Utilize the speed and efficiency of aiohttp and requests under the hood. This library is designed for rapid data acquisition, enabling you to get the latest market insights quickly.

  • Unparalleled Data Flexibility:   nsemine empowers you with the complete data manipulation. Choose between the raw, unfiltered API response for maximum customization, OR leverage our intelligently processed data structures for streamlined analysis and immediate insights.

  • Intelligent Built-in Caching:  Minimize API requests with the intelligent built-in caching mechanism. Reduce your reliance on the NSE API and save you from getting blocked by the NSE Anti-Scraper Robots.

  • Clean and Intuitive API:  Designed for simplicity and ease of use, the library provides a clean and intuitive API, allowing developers to quickly integrate NSE data into their projects.

  • Comprehensive Data Coverage:  Access a wide range of NSE data, including indices, stocks, futures, and options, all within a single, unified library.

  • Robust Error Handling:  Built with robust error handling to ensure your applications remain stable and resilient, even in challenging network conditions.

Installation

You can install nsemine by pip or via github.

pip install nsemine

OR

pip install git+https://github.com/kbizme/nsemine.git

Why I Built This Library

Well, there are several Python libraries available for scraping NSE data, I developed this library to address specific needs that were not adequately met by the existing solutions. I have used this library in my project. You can use it in yours.

  • Custom Data Requirements:   nsemine is tailored to retrieve specific data points and formats that were essential for the project, which may not be available in other libraries.

  • Unique Data Structures: The project required data in a particular structure and format, which this library delivers directly, eliminating the need for extensive post-processing.

  • Data Availability:   nsemine is designed to access and provide data that may not be available or easily accessible through other existing NSE scraping libraries.

  • Performance and Reliability: Optimized for speed and stability, ensuring reliable data retrieval, especially for real-time and high-frequency data. It uses numpy and pandas vectorized operations for faster data pre-processing. Most of the possible errors are handled with Exceptions, thus, even if any error occurs the application will remain stable.

  • Ease of Use:   nsemine aims to provide a simple and intuitive interface, making it easy for developers to integrate NSE data into their applications. This library is designed to offer a more specialized and efficient solution for users who require precise and customized NSE data.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bug fixes, feature requests, or improvements.

Documentation

Work in progress... Meanwhile, you may explore the library. ReadTheDocs style documentation will be added upon complete library build.

Basic Usage Example: from nsemine import nse, live, historical, fno

  1. get live stock and index quotes
  • quotes = live.get_stock_live_quotes(stock_symbol='TCS')
  • index_quote = live.get_index_live_price(index='NIFTY 50')
  1. You can download stock and index historical data from the historical module.
  2. NSE related any data is available on the nse module.
  3. FNO related data functions are available on fno module [in development].

TIP: You may get all the available function in each modules, by using a dot afte the module name, like this -> live. or -> nse. [Your IDE may highlight all the available functions, all functions contains comprehensive docstring] This is a workaround while the full documentation is ready.

WARNING

Still in Maturing phase, so expect frequent updates..

Documentation

Basic import:

from datetime import datetime
from nsemine import live, historical, nse, fno

Module 1: live.py

get_stock_live_quotes(stock_symbol: str, series: str | None = None, raw: bool = False)

Fetches the live quote for a stock symbol.

  • stock_symbol: NSE stock symbol, such as "TCS" or "INFY".
  • series: NSE series to query. Defaults to "EQ" when not provided.
  • raw: When True, returns the raw NSE JSON response. When False, returns a cleaned dictionary.
  • Returns: dict for quote data, or None if the request or processing fails.

Example:

quote = live.get_stock_live_quotes("TCS")
raw_quote = live.get_stock_live_quotes("TCS", raw=True)

get_index_live_price(index: str = "NIFTY 50", raw: bool = False)

Fetches live price data for a single NSE index.

  • index: Index name, such as "NIFTY 50" or "NIFTY BANK".
  • raw: When True, returns the raw index watch JSON response.
  • Returns: a dictionary with symbol, open, high, low, close, previous_close, change, changepct, year_high, year_low, and sometimes datetime; returns None if the index is not found or an error occurs.

Example:

nifty = live.get_index_live_price()
bank_nifty_raw = live.get_index_live_price("NIFTY BANK", raw=True)

get_all_indices_live_snapshot(raw: bool = False)

Fetches a live snapshot of all available NSE indices.

  • raw: When True, returns the raw JSON response.
  • Returns: a pandas.DataFrame with columns including key, index, symbol, open, high, low, close, previous_close, change, changepct, year_high, year_low, advances, declines, unchanged, one_week_ago, one_month_ago, and one_year_ago; returns None on failure.
  • Note: processed output drops rows containing missing values.

Example:

indices = live.get_all_indices_live_snapshot()

get_all_securities_live_snapshot(series: str | list | None = None, raw: bool = False)

Fetches a live snapshot for all NSE securities.

  • series: Optional series filter, such as "EQ" or ["EQ", "SM"].
  • raw: When True, returns the raw JSON response.
  • Returns: a pandas.DataFrame with symbol, series, close, previous_close, change, changepct, volume, traded_value, and market_cap; returns None on failure.
  • Note: processed volume, traded_value, and market_cap are scaled to absolute values.

Example:

all_securities = live.get_all_securities_live_snapshot()
eq_securities = live.get_all_securities_live_snapshot(series="EQ")

get_index_constituents_live_snapshot(index: str = "NIFTY 50", raw: bool = False)

Fetches live constituent data for an NSE index.

  • index: Index name, such as "NIFTY 50", "NIFTY BANK", or "NIFTY NEXT 50".
  • raw: When True, returns the raw JSON response.
  • Returns: a pandas.DataFrame with symbol, ltp, previous_close, change, changepct, weightage, volume, and turnover; returns None on failure.
  • Note: NSE-provided volume and turnover units are preserved.

Example:

constituents = live.get_index_constituents_live_snapshot("NIFTY 50")

get_fno_indices_live_snapshot(df: bool = True)

Fetches live data for the NSE F&O indices.

  • df: When True, returns a pandas.DataFrame. When False, returns a dictionary keyed by derivative symbols such as NIFTY, BANKNIFTY, FINNIFTY, MIDCPNIFTY, and NIFTYNXT50.
  • Returns: index snapshot data with datetime, open, high, low, close, previous_close, change, changepct, year_high, and year_low; returns None on failure.

Example:

fno_indices = live.get_fno_indices_live_snapshot()
fno_indices_dict = live.get_fno_indices_live_snapshot(df=False)

get_stock_intraday_tick_by_tick_data(stock_symbol: str, candle_interval: int | None = None, raw: bool = False)

Fetches current-day intraday tick data for a stock and can convert it into OHLC candles.

  • stock_symbol: NSE stock symbol.
  • candle_interval: Optional candle interval in minutes. If omitted, tick data is returned.
  • raw: When True and candle_interval is not provided, returns the raw JSON response.
  • Returns: a tick pandas.DataFrame, an OHLC pandas.DataFrame when candle_interval is provided, raw JSON when requested, or None on failure.

Example:

ticks = live.get_stock_intraday_tick_by_tick_data("INFY")
five_minute = live.get_stock_intraday_tick_by_tick_data("INFY", candle_interval=5)

Module 2: historical.py

get_stock_historical_data(stock_symbol: str, start_datetime: datetime, end_datetime: datetime = datetime.now(), interval: int | str = 1, raw: bool = False)

Fetches historical chart data for an equity symbol.

  • stock_symbol: NSE stock symbol.
  • start_datetime: Start of the requested period.
  • end_datetime: End of the requested period. Defaults to the time at module import.
  • interval: Intraday

Related Skills

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated16d ago
Forks2

Languages

Python

Security Score

90/100

Audited on Jul 22, 2026

No findings