Metadata-Version: 2.4
Name: nse
Version: 1.2.8
Summary: Unofficial Python Api for NSE India stock exchange
Project-URL: Bug Tracker, https://github.com/BennyThadikaran/NseIndiaApi/issues
Project-URL: Homepage, https://github.com/BennyThadikaran/NseIndiaApi
Author: Benny Thadikaran
License-File: LICENSE
Keywords: nse,nse-stock-data,stock-market-api,stock-news-api
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Requires-Dist: mthrottle>=0.0.1
Provides-Extra: dev
Requires-Dist: furo==2023.9.10; extra == 'dev'
Requires-Dist: sphinx==7.4.7; extra == 'dev'
Provides-Extra: local
Requires-Dist: requests>=2.31; extra == 'local'
Provides-Extra: server
Requires-Dist: httpx[http2]==0.28.1; extra == 'server'
Description-Content-Type: text/markdown

# 💰 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](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](https://github.com/BennyThadikaran/NseIndiaApi/pull/10) for details.

## 🔥 Usage

**To install on local machine or PC**

```bash
pip install nse[local]
```

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

```bash
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**

```python
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**

```python
with NSE(download_folder=DIR, server=False) as nse:
    status = nse.status()

    advDec = nse.advanceDecline()
```

**Catching errors**

```python
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.
