Skip to main content

💰 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.

Download files

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

Source Distribution

nse-4.0.0.post1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

nse-4.0.0.post1-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file nse-4.0.0.post1.tar.gz.

File metadata

  • Download URL: nse-4.0.0.post1.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nse-4.0.0.post1.tar.gz
Algorithm Hash digest
SHA256 7a32bb1efd6b572f8e5993a8a81e414df677d6fa90b423c5d8d88af11bf6f012
MD5 adb89508d46affbb95c5420975a8ce54
BLAKE2b-256 d43385ab3aea9ef66b0061b390be48d0b0dcf13cf0177fac67cbda7c31114d6c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: nse-4.0.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for nse-4.0.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 e12eb76e8aa87e346db520922efa92ac8372d630366016267da8635fcfbc59e3
MD5 93dcc47befb9d9ba863905e656d219cd
BLAKE2b-256 3f39b29142855e5bc90667bd6a014adbb23f8a68b68438be88b9da2deacde587

See more details on using hashes here.

Provenance

The following attestation bundles were made for nse-4.0.0.post1-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.

Release history Release notifications | RSS feed

4.0.1

2 files

This release

4.0.0.post1 This release

2 files

4.0.0

2 files

3.2.1

2 files

3.2.0

2 files

3.1.2

2 files

3.1.1

2 files

3.1.0

2 files

3.0.0

2 files

2.1.3

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.0

2 files

1.3.1

2 files

1.3.0.post1

2 files

1.2.9

2 files

1.2.8

2 files

1.2.7

2 files

1.2.6

2 files

1.2.5

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5.post1

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7.post2

2 files

0.2.6.post2

2 files

0.2.6.post1

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.0.post1

2 files

0.1.1.post1

2 files

0.1.1

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page