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-0.1.1.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

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

aynse-0.1.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aynse-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9999be7bbb841012a7285e26308daae48af37c67a0a0045a5fbac2b1c1d0e297
MD5 8cf9e2c328d313cd0658060c1a4c4aad
BLAKE2b-256 5372360ab15a453664a13c2f5c1a2c5b350803552bc51b2c04abb480ab3a21f2

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for aynse-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 edfd07583ea5277f38bc5c0225b1b454627e29dd2a749ab35013a958d36447fd
MD5 8f527faca15773579c8cd5023c2c585c
BLAKE2b-256 232670b46849c2c2184342a93adcb6d3a3df27767246f8dc1dd44ce24c3142dd

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