aynse¶
A lean, modern Python library for fetching data from the National Stock Exchange (NSE) of India.
-
Historical Data
Download OHLCV data for stocks, indices, and derivatives with automatic retry and caching.
-
Live Quotes
Real-time stock quotes, option chains, market status, and more.
-
Bhavcopy
Download daily bhavcopies for equity, F&O, and indices.
-
CLI
Command-line interface for quick downloads without writing code.
Features¶
- Historical data: stocks, indices, derivatives (F&O)
- Bhavcopy: equity, F&O, index downloads
- Live market data: real-time quotes, option chains
- CLI: simple commands for quick downloads
- Resilient networking: HTTP/2, connection pooling, retries with exponential backoff
- Rate limiting: token bucket algorithm prevents API throttling
- Circuit breaker: automatic failure detection and recovery
- Batching & streaming: adaptive concurrency and low-memory processing
- Comprehensive type hints: full typing support for IDE autocomplete
Installation¶
For development:
Quick Start¶
Get Historical Stock Data¶
from datetime import date
from aynse import stock_df
# Fetch RELIANCE data for January 2024
df = stock_df(
symbol="RELIANCE",
from_date=date(2024, 1, 1),
to_date=date(2024, 1, 31)
)
print(df.head())
Get Live Stock Quote¶
from aynse import NSELive
live = NSELive()
quote = live.stock_quote("INFY")
print(f"Price: ₹{quote['priceInfo']['lastPrice']}")
print(f"Change: {quote['priceInfo']['pChange']}%")
Download Bhavcopy¶
from datetime import date
from aynse import bhavcopy_save
# Download equity bhavcopy
bhavcopy_save(date(2024, 7, 26), "downloads/")
CLI Usage¶
# Download historical stock data
aynse stock -s RELIANCE -f 2024-01-01 -t 2024-03-31 -o reliance.csv
# Get live quote
aynse quote -s RELIANCE
# List trading holidays
aynse holidays -y 2024
Architecture¶
aynse/
├── nse/ # NSE data fetching
│ ├── history.py # Historical data (stocks, indices, derivatives)
│ ├── archives.py # Bhavcopy downloads
│ ├── live.py # Live market data
│ ├── http_client.py # Resilient HTTP client
│ ├── connection_pool.py # Connection management
│ ├── request_batcher.py # Batch processing
│ └── streaming_processor.py # Memory-efficient streaming
├── rbi/ # RBI data
│ └── historical.py # Policy rates
├── holidays.py # Trading calendar
├── util.py # Utilities (caching, date handling)
└── cli.py # Command-line interface
Next Steps¶
- Historical Data Guide - Download OHLCV data
- Live Data Guide - Real-time quotes and option chains
- CLI Reference - Command-line usage
- API Reference - Complete API documentation
- Data Calls Reference - All available data calls