nse


Namense JSON
Version 1.0.6 PyPI version JSON
download
home_pageNone
SummaryUnofficial Python Api for NSE India stock exchange
upload_time2024-11-26 11:20:25
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.0.4** Added new method to download daily bhavcopy PR zip (contains a collection of various reports). [See Docs](https://bennythadikaran.github.io/NseIndiaApi/usage.html#nse.NSE.pr_bhavcopy)

## 🔥 Usage

**Install with Pip**

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

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

```python
with NSE(download_folder=DIR) 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/30/10/a269677453ecbddbeac3d926939e432f27fec757f4076476e11476f94e19/nse-1.0.6.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.0.4** Added new method to download daily bhavcopy PR zip (contains a collection of various reports). [See Docs](https://bennythadikaran.github.io/NseIndiaApi/usage.html#nse.NSE.pr_bhavcopy)\n\n## \ud83d\udd25 Usage\n\n**Install with Pip**\n\n```bash\npip install -U nse\n```\n\nThe class accepts a single argument `download_folder`, a `str` filepath, or a `pathlib object`. The folder stores cookie and any downloaded files.\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)\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) 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.0.6",
    "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": "",
            "digests": {
                "blake2b_256": "4af8f3ae91c06d50bb4bb2d23f16ebe2cb2b5218951a9f11311fe3d4ff3dd2e8",
                "md5": "f05422bb54669a485635d4eeae92599e",
                "sha256": "99e9facc56b76ad0c3e144d8064492b945328c756d31c5c1f003e2d61bceec71"
            },
            "downloads": -1,
            "filename": "nse-1.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f05422bb54669a485635d4eeae92599e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22939,
            "upload_time": "2024-11-26T11:20:23",
            "upload_time_iso_8601": "2024-11-26T11:20:23.118836Z",
            "url": "https://files.pythonhosted.org/packages/4a/f8/f3ae91c06d50bb4bb2d23f16ebe2cb2b5218951a9f11311fe3d4ff3dd2e8/nse-1.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3010a269677453ecbddbeac3d926939e432f27fec757f4076476e11476f94e19",
                "md5": "4d24ee8598aa05463c504cbd78c245a8",
                "sha256": "1fba35dd6009178fc849e7739bd6eecd8e98f99c5e59bba76833da3cf863f32f"
            },
            "downloads": -1,
            "filename": "nse-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "4d24ee8598aa05463c504cbd78c245a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 23693,
            "upload_time": "2024-11-26T11:20:25",
            "upload_time_iso_8601": "2024-11-26T11:20:25.034426Z",
            "url": "https://files.pythonhosted.org/packages/30/10/a269677453ecbddbeac3d926939e432f27fec757f4076476e11476f94e19/nse-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-26 11:20:25",
    "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: 0.41044s