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.2.0 NSE package now works in server environments like AWS. See PR #10 for details.

🔥 Usage

To install on local machine or PC

pip install nse[local]

To install in a server environment like AWS (Works on local too)

pip install nse[server]

The class accepts two arguments (As of 1.2.0)

  • download_folder - a str filepath, or a pathlib object. The folder stores cookie and any downloaded files.
  • server - If False (default), use the requests module to make requests. Else uses the httpx module with http2 support for running on server.

Note: server=True works both locally and on servers. httpx[http2] module is required to be installed for this to work.

Simple example

from nse import NSE
from pathlib import Path

# Working directory
DIR = Path(__file__).parent

nse = NSE(download_folder=DIR, server=False)

status = nse.status()

advDec = nse.advanceDecline()

nse.exit() # close requests session

Using with statement

with NSE(download_folder=DIR, server=False) 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.2.9.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

nse-1.2.9-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nse-1.2.9.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nse-1.2.9.tar.gz
Algorithm Hash digest
SHA256 535522d178abf9a8cda0cf7b88a2be0abd18d0a47d9a64ee40f3701c3bf819e8
MD5 a6509d540fbb98a4f30994d63a25c71b
BLAKE2b-256 18cf59758494aa844d79c3ea46273e828ae48c4cd03cfd6d0ccf9418c147fc73

See more details on using hashes here.

Provenance

The following attestation bundles were made for nse-1.2.9.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.2.9-py3-none-any.whl.

File metadata

  • Download URL: nse-1.2.9-py3-none-any.whl
  • Upload date:
  • Size: 28.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for nse-1.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 0760e34e9fe7837150a2b820ad32144158182df853827c167e7df0b6cdd33c7d
MD5 cc60cfb3b4ae27a8f45cc3ca6115db8f
BLAKE2b-256 c02d44b0153dd371ba5ba76d5c65694575d0b853e577ac1a2a18fc438bdcebc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for nse-1.2.9-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 Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page