# NSE Finance - Python Library for NSE India Data
A comprehensive Python library to access publicly available historical and real-time data from NSE India with a simple, intuitive API.
## Features
- **Historical Data**: Download OHLCV data for stocks, indices, futures, and options
- **Real-time Data**: Access live market data, option chains, and market depth
- **Market Analysis**: Get gainers/losers, most active stocks, and market statistics
- **Corporate Actions**: Access corporate announcements, insider trading, and upcoming results
- **Holiday Calendar**: Check trading and clearing holidays
- **Type Safety**: Built with Pydantic for robust data validation
## Installation
```bash
pip install nsefin
```
## Quick Start - Simple API
The easiest way to use nsefin is with the module-level functions:
```python
import nsefin
from datetime import datetime, timedelta
# Search for symbols (much clearer than just "search")
bank_stocks = nsefin.search_symbols('BANK', exchange='NSE', exact_match=False)
print(bank_stocks.head())
# Get historical price data
end_date = datetime.now()
start_date = end_date - timedelta(days=30)
# Download stock price history
reliance_data = nsefin.get_price_history('RELIANCE', 'NSE', start_date, end_date, '1d')
print(reliance_data.head())
# Get current price information
current_price = nsefin.get_current_price('RELIANCE')
print(f"RELIANCE current price: ₹{current_price['LastTradedPrice']}")
# Check if today is a trading holiday
is_holiday = nsefin.check_trading_holiday()
print(f"Is today a trading holiday? {is_holiday}")
# Get option chain data
option_data = nsefin.get_option_chain_data('BANKNIFTY', is_index=True)
print(option_data.head())
# Get pre-market data
premarket = nsefin.get_pre_market_data('NIFTY 50')
print(premarket.head())
```
## Advanced Usage - Class-based API
For more control and advanced features, use the NSE class directly:
```python
from nsefin import NSE
from datetime import datetime, timedelta
# Initialize NSE instance
nse = NSE()
# All the same functions are available on the class
data = nse.get_price_history('TCS', 'NSE', start_date, end_date, '5m')
symbols = nse.search_symbols('NIFTY', 'NSE', exact_match=False)
```
## Function Reference
### Core Data Functions
- `search_symbols(symbol, exchange, exact_match)` - Search for stock/index symbols
- `get_price_history(symbol, exchange, start, end, interval)` - Get historical OHLCV data
- `get_current_price(symbol)` - Get live price information
- `check_trading_holiday(date_str)` - Check if date is trading holiday
### Market Data Functions
- `get_pre_market_data(category)` - Get pre-market information
- `get_option_chain_data(symbol, is_index)` - Get option chain data
- `get_index_details(category, symbols_only)` - Get index constituent details
### Holiday Functions
- `get_clearing_holidays(list_only)` - Get NSE clearing holidays
- `is_clearing_holiday(date_str)` - Check if date is clearing holiday
### Corporate Actions Functions
- `get_corporate_actions(from_date, to_date, filter)` - Get corporate actions
- `get_corporate_announcements(from_date, to_date)` - Get corporate announcements
- `get_insider_trading(from_date, to_date)` - Get insider trading data
- `get_upcoming_results()` - Get upcoming results calendar
## Backward Compatibility
All original function names are still supported:
```python
# These still work for backward compatibility
result = nsefin.search('BANK', 'NSE', match=False) # old syntax
data = nsefin.get_history('RELIANCE', 'NSE', start_date, end_date, '1d') # old syntax
price = nsefin.get_price_info('RELIANCE') # old syntax
```
## Supported Time Intervals
- `1m`, `3m`, `5m`, `10m`, `15m`, `30m` - Intraday intervals
- `1h` - Hourly data
- `1d` - Daily data
- `1w` - Weekly data
- `1M` - Monthly data
## Type Safety with Pydantic
The library includes Pydantic models for robust type checking:
```python
from nsefin.models import HistoricalDataRequest, SymbolSearchRequest
# Type-safe requests (optional)
search_req = SymbolSearchRequest(symbol="RELIANCE", exchange="NSE", exact_match=True)
hist_req = HistoricalDataRequest(symbol="TCS", interval="1d")
```
## Examples
### Get Historical Data
```python
import nsefin
from datetime import datetime, timedelta
# Get daily data for last 30 days
end_date = datetime.now()
start_date = end_date - timedelta(days=30)
data = nsefin.get_price_history('RELIANCE', 'NSE', start_date, end_date, '1d')
print(data.head())
```
### Search for Symbols
```python
# Search for bank stocks
bank_stocks = nsefin.search_symbols('BANK', exchange='NSE', exact_match=False)
print(f"Found {len(bank_stocks)} bank-related symbols")
# Exact match search
reliance = nsefin.search_symbols('RELIANCE', exchange='NSE', exact_match=True)
print(reliance)
```
### Get Option Chain
```python
# Get option chain for BANKNIFTY
option_chain = nsefin.get_option_chain_data('BANKNIFTY', is_index=True)
print(option_chain.head())
```
## Requirements
- Python 3.8+
- pandas
- requests
- numpy
- pydantic
## Disclaimer
This library is meant for educational purposes only. Downloading data from NSE website requires explicit approval from the exchange. Hence, the usage of this utility is for limited purposes only under proper/explicit approvals.
## License
MIT License
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## Support
For support, please raise an issue on GitHub.
Raw data
{
"_id": null,
"home_page": "https://github.com/vbhadala/nsefin",
"name": "nsefin",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "nse, stock market, financial data, india, trading, candlestick data",
"author": "Vinod Bhadala",
"author_email": "vinodbhadala@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/8a/f6/b85211f264964078a8bdd31382c87e1a90c2ad98376b8490bcbd281b42fe/nsefin-0.1.2.tar.gz",
"platform": null,
"description": "\n# NSE Finance - Python Library for NSE India Data\n\nA comprehensive Python library to access publicly available historical and real-time data from NSE India with a simple, intuitive API.\n\n## Features\n\n- **Historical Data**: Download OHLCV data for stocks, indices, futures, and options\n- **Real-time Data**: Access live market data, option chains, and market depth\n- **Market Analysis**: Get gainers/losers, most active stocks, and market statistics\n- **Corporate Actions**: Access corporate announcements, insider trading, and upcoming results\n- **Holiday Calendar**: Check trading and clearing holidays\n- **Type Safety**: Built with Pydantic for robust data validation\n\n## Installation\n\n```bash\npip install nsefin\n```\n\n## Quick Start - Simple API\n\nThe easiest way to use nsefin is with the module-level functions:\n\n```python\nimport nsefin\nfrom datetime import datetime, timedelta\n\n# Search for symbols (much clearer than just \"search\")\nbank_stocks = nsefin.search_symbols('BANK', exchange='NSE', exact_match=False)\nprint(bank_stocks.head())\n\n# Get historical price data\nend_date = datetime.now()\nstart_date = end_date - timedelta(days=30)\n\n# Download stock price history\nreliance_data = nsefin.get_price_history('RELIANCE', 'NSE', start_date, end_date, '1d')\nprint(reliance_data.head())\n\n# Get current price information\ncurrent_price = nsefin.get_current_price('RELIANCE')\nprint(f\"RELIANCE current price: \u20b9{current_price['LastTradedPrice']}\")\n\n# Check if today is a trading holiday\nis_holiday = nsefin.check_trading_holiday()\nprint(f\"Is today a trading holiday? {is_holiday}\")\n\n# Get option chain data\noption_data = nsefin.get_option_chain_data('BANKNIFTY', is_index=True)\nprint(option_data.head())\n\n# Get pre-market data\npremarket = nsefin.get_pre_market_data('NIFTY 50')\nprint(premarket.head())\n```\n\n## Advanced Usage - Class-based API\n\nFor more control and advanced features, use the NSE class directly:\n\n```python\nfrom nsefin import NSE\nfrom datetime import datetime, timedelta\n\n# Initialize NSE instance\nnse = NSE()\n\n# All the same functions are available on the class\ndata = nse.get_price_history('TCS', 'NSE', start_date, end_date, '5m')\nsymbols = nse.search_symbols('NIFTY', 'NSE', exact_match=False)\n```\n\n## Function Reference\n\n### Core Data Functions\n\n- `search_symbols(symbol, exchange, exact_match)` - Search for stock/index symbols\n- `get_price_history(symbol, exchange, start, end, interval)` - Get historical OHLCV data\n- `get_current_price(symbol)` - Get live price information\n- `check_trading_holiday(date_str)` - Check if date is trading holiday\n\n### Market Data Functions\n\n- `get_pre_market_data(category)` - Get pre-market information\n- `get_option_chain_data(symbol, is_index)` - Get option chain data\n- `get_index_details(category, symbols_only)` - Get index constituent details\n\n### Holiday Functions\n\n- `get_clearing_holidays(list_only)` - Get NSE clearing holidays\n- `is_clearing_holiday(date_str)` - Check if date is clearing holiday\n\n### Corporate Actions Functions\n\n- `get_corporate_actions(from_date, to_date, filter)` - Get corporate actions\n- `get_corporate_announcements(from_date, to_date)` - Get corporate announcements\n- `get_insider_trading(from_date, to_date)` - Get insider trading data\n- `get_upcoming_results()` - Get upcoming results calendar\n\n## Backward Compatibility\n\nAll original function names are still supported:\n\n```python\n# These still work for backward compatibility\nresult = nsefin.search('BANK', 'NSE', match=False) # old syntax\ndata = nsefin.get_history('RELIANCE', 'NSE', start_date, end_date, '1d') # old syntax\nprice = nsefin.get_price_info('RELIANCE') # old syntax\n```\n\n## Supported Time Intervals\n\n- `1m`, `3m`, `5m`, `10m`, `15m`, `30m` - Intraday intervals\n- `1h` - Hourly data\n- `1d` - Daily data \n- `1w` - Weekly data\n- `1M` - Monthly data\n\n## Type Safety with Pydantic\n\nThe library includes Pydantic models for robust type checking:\n\n```python\nfrom nsefin.models import HistoricalDataRequest, SymbolSearchRequest\n\n# Type-safe requests (optional)\nsearch_req = SymbolSearchRequest(symbol=\"RELIANCE\", exchange=\"NSE\", exact_match=True)\nhist_req = HistoricalDataRequest(symbol=\"TCS\", interval=\"1d\")\n```\n\n## Examples\n\n### Get Historical Data\n\n```python\nimport nsefin\nfrom datetime import datetime, timedelta\n\n# Get daily data for last 30 days\nend_date = datetime.now()\nstart_date = end_date - timedelta(days=30)\n\ndata = nsefin.get_price_history('RELIANCE', 'NSE', start_date, end_date, '1d')\nprint(data.head())\n```\n\n### Search for Symbols\n\n```python\n# Search for bank stocks\nbank_stocks = nsefin.search_symbols('BANK', exchange='NSE', exact_match=False)\nprint(f\"Found {len(bank_stocks)} bank-related symbols\")\n\n# Exact match search\nreliance = nsefin.search_symbols('RELIANCE', exchange='NSE', exact_match=True)\nprint(reliance)\n```\n\n\n\n### Get Option Chain\n\n```python\n# Get option chain for BANKNIFTY\noption_chain = nsefin.get_option_chain_data('BANKNIFTY', is_index=True)\nprint(option_chain.head())\n```\n\n## Requirements\n\n- Python 3.8+\n- pandas\n- requests\n- numpy\n- pydantic\n\n## Disclaimer\n\nThis library is meant for educational purposes only. Downloading data from NSE website requires explicit approval from the exchange. Hence, the usage of this utility is for limited purposes only under proper/explicit approvals.\n\n## License\n\nMIT License\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Support\n\nFor support, please raise an issue on GitHub.\n",
"bugtrack_url": null,
"license": null,
"summary": "A Python library to download publicly available historical candlestick data from NSE India",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/vbhadala/nsefin"
},
"split_keywords": [
"nse",
" stock market",
" financial data",
" india",
" trading",
" candlestick data"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "f8cfcd1de3b8684f1ef76ab2d89f6ca12d8cbeb156aad55730545dacf3c3236a",
"md5": "7960a20ccf97251283772c4e52d10ae7",
"sha256": "b30d234a75dc69fa296058ee8a462b49fb5c3c573d7b2e4f80e7fcff8b40e62e"
},
"downloads": -1,
"filename": "nsefin-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7960a20ccf97251283772c4e52d10ae7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 18009,
"upload_time": "2025-07-09T09:51:40",
"upload_time_iso_8601": "2025-07-09T09:51:40.247015Z",
"url": "https://files.pythonhosted.org/packages/f8/cf/cd1de3b8684f1ef76ab2d89f6ca12d8cbeb156aad55730545dacf3c3236a/nsefin-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "8af6b85211f264964078a8bdd31382c87e1a90c2ad98376b8490bcbd281b42fe",
"md5": "6798d1afe0a7ed6ad761414246dc4b12",
"sha256": "9e16266cfeff8562e7b7ab5bb2e4222b5cc051b9ad38f3349b4a3a54527d0118"
},
"downloads": -1,
"filename": "nsefin-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "6798d1afe0a7ed6ad761414246dc4b12",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 18931,
"upload_time": "2025-07-09T09:51:41",
"upload_time_iso_8601": "2025-07-09T09:51:41.779164Z",
"url": "https://files.pythonhosted.org/packages/8a/f6/b85211f264964078a8bdd31382c87e1a90c2ad98376b8490bcbd281b42fe/nsefin-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-09 09:51:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "vbhadala",
"github_project": "nsefin",
"github_not_found": true,
"lcname": "nsefin"
}