Skip to main content

A lean and modern python library to fetch data from NSE

Project description

aynse

build status PyPI version license: mit

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 exist under ayn rand's philosophy, as she was against 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 is in the public domain. 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.0.tar.gz (27.4 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.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aynse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 38a31a41541388cd0ab64eb7338a5334309b1e8cb7344bd78fa9adf350183d6a
MD5 f253c54ff8c8d4098063ae9e0d2fc5cb
BLAKE2b-256 2ed492dae9574f83c9b0c54acc452c6edecf4529a295c7715cb4386bde88b6d0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for aynse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f32d336d5d6f6958831ed1ee442a191f61c710d6b661a48cc64982cc064de5e0
MD5 889bf69c0f4c2cc1ef46439e6d9c4aa0
BLAKE2b-256 71e001db53ab016d605b2d62baca56f0294b6dd8940a055a747d9c297794782e

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