nse


Namense JSON
Version 1.2.9 PyPI version JSON
download
home_pageNone
SummaryUnofficial Python Api for NSE India stock exchange
upload_time2025-08-21 16:41:46
maintainerNone
docs_urlNone
authorBenny Thadikaran
requires_python>=3.8
licenseNone
keywords nse nse-stock-data stock-market-api stock-news-api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 💰 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "nse",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "nse, nse-stock-data, stock-market-api, stock-news-api",
    "author": "Benny Thadikaran",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/18/cf/59758494aa844d79c3ea46273e828ae48c4cd03cfd6d0ccf9418c147fc73/nse-1.2.9.tar.gz",
    "platform": null,
    "description": "# \ud83d\udcb0 NseIndiaApi\n\nAn unofficial Python API for the NSE India stock exchange.\n\nPython version: >= 3.8\n\nIf you \u2764\ufe0f my work so far, please \ud83c\udf1f this repo.\n\n## \ud83d\udc7d Documentation\n\n[https://bennythadikaran.github.io/NseIndiaApi](https://bennythadikaran.github.io/NseIndiaApi)\n\n## API limits\n\nAll 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.\n\n- If downloading a large number of reports from NSE, please do so after-market hours (Preferably late evening).\n- Add an extra 0.5 - 1 sec sleep between requests. The extra run time likely wont make a difference to your script.\n- Save the file and reuse them instead of re-downloading.\n\n## Updates\n\n**v1.2.0** NSE package now works in server environments like AWS. [See PR #10](https://github.com/BennyThadikaran/NseIndiaApi/pull/10) for details.\n\n## \ud83d\udd25 Usage\n\n**To install on local machine or PC**\n\n```bash\npip install nse[local]\n```\n\n**To install in a server environment like AWS (Works on local too)**\n\n```bash\npip install nse[server]\n```\n\nThe class accepts two arguments (As of 1.2.0)\n\n- `download_folder` - a `str` filepath, or a `pathlib object`. The folder stores cookie and any downloaded files.\n- `server` - If False (default), use the requests module to make requests. Else uses the httpx module with http2 support for running on server.\n\nNote: `server=True` works both locally and on servers. `httpx[http2]` module is required to be installed for this to work.\n\n**Simple example**\n\n```python\nfrom nse import NSE\nfrom pathlib import Path\n\n# Working directory\nDIR = Path(__file__).parent\n\nnse = NSE(download_folder=DIR, server=False)\n\nstatus = nse.status()\n\nadvDec = nse.advanceDecline()\n\nnse.exit() # close requests session\n```\n\n**Using with statement**\n\n```python\nwith NSE(download_folder=DIR, server=False) as nse:\n    status = nse.status()\n\n    advDec = nse.advanceDecline()\n```\n\n**Catching errors**\n\n```python\nfrom nse import NSE\nfrom datetime import datetime\n\nwith NSE('./') as nse:\n    try:\n        bhavFile = nse.equityBhavcopy(date=datetime.now())\n        dlvFile = nse.deliveryBhavcopy(date=datetime.now())\n        raise RuntimeError('Some error')  # force an exception\n    except RuntimeError as e:\n        # continue execution or exit the script\n        print(repr(e))\n\n    # execution continues if handled without exit\n    actions = nse.actions()\n\n# NSE request session closed - continue processing\n```\n\n## Samples folder\n\nThe `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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Unofficial Python Api for NSE India stock exchange",
    "version": "1.2.9",
    "project_urls": {
        "Bug Tracker": "https://github.com/BennyThadikaran/NseIndiaApi/issues",
        "Homepage": "https://github.com/BennyThadikaran/NseIndiaApi"
    },
    "split_keywords": [
        "nse",
        " nse-stock-data",
        " stock-market-api",
        " stock-news-api"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c02d44b0153dd371ba5ba76d5c65694575d0b853e577ac1a2a18fc438bdcebc8",
                "md5": "cc60cfb3b4ae27a8f45cc3ca6115db8f",
                "sha256": "0760e34e9fe7837150a2b820ad32144158182df853827c167e7df0b6cdd33c7d"
            },
            "downloads": -1,
            "filename": "nse-1.2.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cc60cfb3b4ae27a8f45cc3ca6115db8f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 28248,
            "upload_time": "2025-08-21T16:41:45",
            "upload_time_iso_8601": "2025-08-21T16:41:45.432681Z",
            "url": "https://files.pythonhosted.org/packages/c0/2d/44b0153dd371ba5ba76d5c65694575d0b853e577ac1a2a18fc438bdcebc8/nse-1.2.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "18cf59758494aa844d79c3ea46273e828ae48c4cd03cfd6d0ccf9418c147fc73",
                "md5": "a6509d540fbb98a4f30994d63a25c71b",
                "sha256": "535522d178abf9a8cda0cf7b88a2be0abd18d0a47d9a64ee40f3701c3bf819e8"
            },
            "downloads": -1,
            "filename": "nse-1.2.9.tar.gz",
            "has_sig": false,
            "md5_digest": "a6509d540fbb98a4f30994d63a25c71b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 28899,
            "upload_time": "2025-08-21T16:41:46",
            "upload_time_iso_8601": "2025-08-21T16:41:46.893918Z",
            "url": "https://files.pythonhosted.org/packages/18/cf/59758494aa844d79c3ea46273e828ae48c4cd03cfd6d0ccf9418c147fc73/nse-1.2.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-21 16:41:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BennyThadikaran",
    "github_project": "NseIndiaApi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "nse"
}
        
Elapsed time: 4.44522s