A lean and modern python library to fetch data from NSE
Project description
aynse
aynse is a lean, modern python library for fetching data from the National Stock Exchange (NSE) of India. It includes a resilient HTTP client (HTTP/2, retries with jitter, connection pooling), adaptive batching, and efficient streaming utilities.
Features
- Historical data: stocks, indices, derivatives
- Bhavcopy: equity, F&O, index downloads
- Live market data: real-time quotes
- CLI: simple commands for quick downloads
- Resilient networking: HTTP/2, pooling, retries, rate limit, circuit breaker
- Batching & streaming: adaptive concurrency and low-memory processing
etymology / musings
aynse is a portmanteau of "ayn" from miss ayn rand and "nse" from national stock exchange. ayn rand was a russian-american writer and philosopher known for her philosophy of objectivism, which emphasizes individualism and rational self-interest and among other things, she was a strong advocate for laissez-faire capitalism. the name serves as a fun ironical reminder of the library's purpose: to provide a tool for individuals to access and analyze financial data independently, without relying on large institutions or complex systems. in a cruel twist of fate, this open source library wouldn't be encouraged under ayn rand's philosophy, as she discouraged altruism and believed in the pursuit of one's own happiness as the highest moral purpose. and as the final act of irony, we gather to use this library to analyze financial markets while generating zero (and possibly, negative) intrinsic value for humans or human kind as a whole - this is capitalism.
Installation
you can install aynse directly from PyPI:
pip install aynse
Usage
here are a few examples of how to use aynse to fetch data.
Get historical stock data
retrieve historical data for a stock as a pandas dataframe.
from datetime import date
import pandas as pd
from aynse.nse import stock_df
# set pandas display options to view all columns
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
# fetch data for reliance from january 1, 2024, to january 31, 2024
df = stock_df(symbol="RELIANCE",
from_date=date(2024, 1, 1),
to_date=date(2024, 1, 31))
print(df.head())
Download daily bhavcopy
download the daily bhavcopy for a specific date to a local directory.
from datetime import date
from aynse.nse import bhavcopy_save
# download equity bhavcopy for july 26, 2024, into the "tmp" directory
bhavcopy_save(date(2024, 7, 26), "tmp")
Get live stock quote
fetch live price information for a stock.
from aynse.nse import NSELive
n = NSELive()
quote = n.stock_quote("INFY")
print(quote['priceInfo'])
get trading holidays
get the list of trading holidays for a specific year.
from aynse.holidays import holidays
# get trading holidays for the year 2024
trading_holidays = holidays(2024)
print(trading_holidays)
Command-line interface
aynse also comes with a simple command-line tool for quick downloads.
download today's bhavcopy:
aynse bhavcopy -d /path/to/your/directory
download bhavcopy for a specific date range:
aynse bhavcopy -d /path/to/your/directory -f 2024-01-01 -t 2024-01-31
download historical stock data:
aynse stock --symbol RELIANCE -f 2024-01-01 -t 2024-01-31 -o reliance_data.csv
Migration notes (breaking changes)
- Networking is centralized via a connection pool and resilient clients.
- If you previously managed
requests.Sessionmanually, prefer:from aynse.nse.connection_pool import get_connection_pool client = get_connection_pool().get_client("https://www.nseindia.com") data = client.get_json("/api/marketStatus")
- Legacy behavior is preserved via
get_session(url)shim on the pool.
Contributing
contributions are welcome! if you find a bug or have a feature request, please open an issue on the github repository.
License
this project has a (custom) MIT* license but extends limitations. if you're a agency/corporate with >2 employees alongside of you, you cannot wrap this project or use it without prior written permission from me. if you're an individual, you can use it freely for personal projects. this project is not intended for commercial use without prior permission. if caught using this project in violation of the license, it may result in automated reporting and/or legal action. please see the license file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aynse-1.1.0.tar.gz.
File metadata
- Download URL: aynse-1.1.0.tar.gz
- Upload date:
- Size: 54.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0abc71e1abe97ecf7376126729760d0ed65f454f7a16abfba9c57d2e1f870a2a
|
|
| MD5 |
15a2b02f353bf76a1b3a514aa827551d
|
|
| BLAKE2b-256 |
83a6911bd68416a1468e07a6f8acb6f8007f3d2aab3ced99c8d968d08e53c8d3
|
File details
Details for the file aynse-1.1.0-py3-none-any.whl.
File metadata
- Download URL: aynse-1.1.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5debd8d1ac0e1aef5e762a377a887c5f6fbbc0d6b161a4901791587fbe93eda
|
|
| MD5 |
547f5a00a2d2e44406a8af002e9e3971
|
|
| BLAKE2b-256 |
0dc0d1db92f490042f91423f0b8805fd82f93c5788f4cc314bb139947c17bd09
|