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/nsemineInstalls 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
asyncioto fetch market data without delays, ensuring your applications remain responsive. -
High-Speed Data Acquisition: Utilize the speed and efficiency of
aiohttpandrequestsunder the hood. This library is designed for rapid data acquisition, enabling you to get the latest market insights quickly. -
Unparalleled Data Flexibility:
nsemineempowers 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:
nsemineis 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:
nsemineis 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
numpyandpandasvectorized 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:
nsemineaims 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
- 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')
- You can download stock and index historical data from the
historicalmodule. - NSE related any data is available on the
nsemodule. - FNO related data functions are available on
fnomodule [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: WhenTrue, returns the raw NSE JSON response. WhenFalse, returns a cleaned dictionary.- Returns:
dictfor quote data, orNoneif 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: WhenTrue, 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 sometimesdatetime; returnsNoneif 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: WhenTrue, returns the raw JSON response.- Returns: a
pandas.DataFramewith columns includingkey,index,symbol,open,high,low,close,previous_close,change,changepct,year_high,year_low,advances,declines,unchanged,one_week_ago,one_month_ago, andone_year_ago; returnsNoneon 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: WhenTrue, returns the raw JSON response.- Returns: a
pandas.DataFramewithsymbol,series,close,previous_close,change,changepct,volume,traded_value, andmarket_cap; returnsNoneon failure. - Note: processed
volume,traded_value, andmarket_capare 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: WhenTrue, returns the raw JSON response.- Returns: a
pandas.DataFramewithsymbol,ltp,previous_close,change,changepct,weightage,volume, andturnover; returnsNoneon failure. - Note: NSE-provided
volumeandturnoverunits 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: WhenTrue, returns apandas.DataFrame. WhenFalse, returns a dictionary keyed by derivative symbols such asNIFTY,BANKNIFTY,FINNIFTY,MIDCPNIFTY, andNIFTYNXT50.- Returns: index snapshot data with
datetime,open,high,low,close,previous_close,change,changepct,year_high, andyear_low; returnsNoneon 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: WhenTrueandcandle_intervalis not provided, returns the raw JSON response.- Returns: a tick
pandas.DataFrame, an OHLCpandas.DataFramewhencandle_intervalis provided, raw JSON when requested, orNoneon 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
node-connect
385.5kDiagnose OpenClaw Android, iOS, or macOS node pairing, QR/setup code, route, auth, and connection failures.
blender-python-addon
40.5kBlender Python add-on rules for operators, panels, properties, registration, testing, and API-safe scripting
flutter-development-guidelines-cursorrules-prompt-file
40.5kCursor rules for Flutter development with MVVM architecture, Riverpod state management, Material widgets, and Dart style guidelines.
commit-push-pr
140.6kCommit, push, and open a PR
