Skip to main content

Unofficial Python Api for NSE India stock exchange

Project description

💰 NseIndiaApi

An unofficial Python API for the NSE India stock exchange.

Python version: >= 3.8

If you ❤️ my work so far, please 🌟 this repo.

👽 Documentation

https://bennythadikaran.github.io/NseIndiaApi

API limits

All requests through NSE are rate limited or throttled to 3 requests per second. This allows making large number of requests without overloading the server or getting blocked.

  • If downloading a large number of reports from NSE, please do so after-market hours (Preferably late evening).
  • Add an extra 0.5 - 1 sec sleep between requests. The extra run time likely wont make a difference to your script.
  • Save the file and reuse them instead of re-downloading.

Updates

v1.0.4 Added new method to download daily bhavcopy PR zip (contains a collection of various reports). See Docs

🔥 Usage

Install with Pip

pip install -U nse

The class accepts a single argument download_folder, a str filepath, or a pathlib object. The folder stores cookie and any downloaded files.

Simple example

from nse import NSE
from pathlib import Path

# Working directory
DIR = Path(__file__).parent

nse = NSE(download_folder=DIR)

status = nse.status()

advDec = nse.advanceDecline()

nse.exit() # close requests session

Using with statement

with NSE(download_folder=DIR) as nse:
    status = nse.status()

    advDec = nse.advanceDecline()

Catching errors

from nse import NSE
from datetime import datetime

with NSE('./') as nse:
    try:
        bhavFile = nse.equityBhavcopy(date=datetime.now())
        dlvFile = nse.deliveryBhavcopy(date=datetime.now())
        raise RuntimeError('Some error')  # force an exception
    except RuntimeError as e:
        # continue execution or exit the script
        print(repr(e))

    # execution continues if handled without exit
    actions = nse.actions()

# NSE request session closed - continue processing

Samples folder

The src/samples folder contains sample outputs of various methods. The filenames match the method names. The output has been truncated in some places but demonstrates the overall structure of responses.

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

nse-1.0.8.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

nse-1.0.8-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file nse-1.0.8.tar.gz.

File metadata

  • Download URL: nse-1.0.8.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for nse-1.0.8.tar.gz
Algorithm Hash digest
SHA256 27f83081710abed7998dbe9eaa0cfd6df6c24d09fc3ad52867ea27dc0a32970b
MD5 dd122b3f2394b5607770b57173329494
BLAKE2b-256 defaac3fdcaba4a8e4d9e0651d53c1057e9fad2baaa0dc3d0695edcacb497be6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nse-1.0.8.tar.gz:

Publisher: publish-to-pypi.yml on BennyThadikaran/NseIndiaApi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nse-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: nse-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for nse-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ace3a66fc2df8a8b3069190881537b2bade2859054f7f6ad2325710955f72a2a
MD5 f7b5e99a325bcada631d82972dfd1dbc
BLAKE2b-256 ddce05eca4d40371a6aa9031ab024cd24cc353892ef1d4a3c64c3750ec7cf912

See more details on using hashes here.

Provenance

The following attestation bundles were made for nse-1.0.8-py3-none-any.whl:

Publisher: publish-to-pypi.yml on BennyThadikaran/NseIndiaApi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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