Skip to main content

A lean and modern python library to fetch data from NSE

Project description

aynse

build status PyPI version license: CMIT misc badge

aynse is a lean, modern python library for fetching data from the national stock exchange (NSE) of india. it is a fork of the unmaintained jugaad-data library, aiming to provide a robust and regularly updated tool for financial data analysis.

features

  • historical data: fetch historical stock and index data.
  • derivatives data: download futures and options data.
  • bhavcopy: download daily bhavcopy reports for equity, f&o, and indices.
  • live market data: get real-time stock quotes.
  • holiday information: retrieve a list of trading holidays for a given year.
  • command-line interface: a simple cli for quick data downloads.
  • pandas integration: returns data as pandas dataframes for easy analysis.

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aynse-1.0.1.tar.gz (29.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aynse-1.0.1-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

Details for the file aynse-1.0.1.tar.gz.

File metadata

  • Download URL: aynse-1.0.1.tar.gz
  • Upload date:
  • Size: 29.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for aynse-1.0.1.tar.gz
Algorithm Hash digest
SHA256 15f1f3b92f39bfb5c991e7bf4df9722e0a87f64adabe0fd42332d7fe726b1099
MD5 4a39fa64617be03b7acb064e3063ddde
BLAKE2b-256 6b0a5c1bd1fac02d5e4d4d1113a677ccb1237876708e746c3be41a88ae069c2c

See more details on using hashes here.

File details

Details for the file aynse-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aynse-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.18

File hashes

Hashes for aynse-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba136794d8c5e6ead7e4f516ae3d1c9005ebd47f579a4a3a98100f2de08b8c0a
MD5 3c54fd7667438a39b0166881cc21d790
BLAKE2b-256 117e343517dd6b81721542978b3f35c884693bc1e22a4acc10c4449d94c87d1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page