# vsjha18/nsetools architecture

> Architecture diagram of the GitHub repository vsjha18/nsetools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vsjha18/nsetools
- Repository: https://github.com/vsjha18/nsetools

## Overview

NSETools is a Python client for retrieving publicly available NSE market data. Users call its stock, index, or derivatives APIs; those methods fetch NSE responses through a session and return parsed results. The repository also includes a historical bhavcopy downloader with date-range handling. The graph preserves the README’s documented API areas and the downloader visible in the tree. Some source excerpts are partial, so unshown implementation links are omitted.

Main entry points: [`src/nsetools/nse.py`](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py) (Stock APIs), [`src/nsetools/ua.py`](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/ua.py) (Session fetcher), [`src/nsetools/urls.py`](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/urls.py) (NSE endpoints), [`src/nsetools/downloader.py`](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/downloader.py) (Bhavcopy downloader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_market["Market APIs"]
  node_stocks["Stock APIs<br/>[nse.py]"]
  node_indices["Index APIs<br/>[nse.py]"]
  node_derivatives["Derivatives API<br/>[nse.py]"]
end

subgraph group_transport["HTTP transport"]
  node_session["Session fetcher<br/>[ua.py]"]
  node_urls["NSE endpoints<br/>[urls.py]"]
end

subgraph group_support["Shared support"]
  node_base["Exchange interface<br/>[bases.py]"]
  node_conversions["Data conversions<br/>[utils.py]"]
end

subgraph group_history["Historical downloads"]
  node_date["Date handling<br/>[datemgr.py]"]
  node_downloader["Bhavcopy downloader<br/>[downloader.py]"]
end

node_user(("Python user"))
node_nse["NSE website"]

node_user -->|"calls"| node_stocks
node_user -->|"calls"| node_indices
node_user -->|"calls"| node_derivatives
node_stocks -->|"fetches through"| node_session
node_indices -->|"fetches through"| node_session
node_derivatives -->|"fetches through"| node_session
node_session -->|"uses home URL"| node_urls
node_session -->|"requests data from"| node_nse
node_stocks -->|"selects endpoints"| node_urls
node_indices -->|"selects endpoints"| node_urls
node_derivatives -->|"selects endpoint"| node_urls
node_stocks -->|"converts responses"| node_conversions
node_indices -->|"converts responses"| node_conversions
node_derivatives -.->|"implements interface"| node_base
node_downloader -->|"gets date ranges"| node_date
node_downloader -->|"creates NSE client"| node_stocks

click node_stocks "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py"
click node_indices "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py"
click node_derivatives "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py"
click node_session "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/ua.py"
click node_urls "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/urls.py"
click node_base "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/bases.py"
click node_conversions "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/utils.py"
click node_date "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/datemgr.py"
click node_downloader "https://github.com/vsjha18/nsetools/blob/master/src/nsetools/downloader.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_stocks,node_indices,node_derivatives,node_user toneBlue
class node_session,node_urls toneAmber
class node_base,node_conversions toneMint
class node_date,node_downloader toneRose
class node_nse toneIndigo
```

## Components

### Market APIs

- [Stock APIs](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py): `src/nsetools/nse.py`
- [Index APIs](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py): `src/nsetools/nse.py`
- [Derivatives API](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/nse.py): `src/nsetools/nse.py`

### HTTP transport

- [Session fetcher](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/ua.py): `src/nsetools/ua.py`
- [NSE endpoints](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/urls.py): `src/nsetools/urls.py`

### Shared support

- [Exchange interface](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/bases.py): `src/nsetools/bases.py`
- [Data conversions](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/utils.py): `src/nsetools/utils.py`

### Historical downloads

- [Date handling](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/datemgr.py): `src/nsetools/datemgr.py`
- [Bhavcopy downloader](https://github.com/vsjha18/nsetools/blob/master/src/nsetools/downloader.py): `src/nsetools/downloader.py`

### Other components

- **Python user**
- **NSE website**

## Connections

- Python user → Stock APIs: calls (evidence: `README.md`)
- Python user → Index APIs: calls (evidence: `README.md`)
- Python user → Derivatives API: calls (evidence: `README.md`)
- Stock APIs → Session fetcher: fetches through (evidence: `src/nsetools/nse.py`)
- Index APIs → Session fetcher: fetches through (evidence: `src/nsetools/nse.py`)
- Derivatives API → Session fetcher: fetches through (evidence: `src/nsetools/nse.py`)
- Session fetcher → NSE endpoints: uses home URL (evidence: `src/nsetools/ua.py`)
- Session fetcher → NSE website: requests data from (evidence: `src/nsetools/ua.py`)
- Stock APIs → NSE endpoints: selects endpoints (evidence: `src/nsetools/nse.py`)
- Index APIs → NSE endpoints: selects endpoints (evidence: `src/nsetools/nse.py`)
- Derivatives API → NSE endpoints: selects endpoint (evidence: `src/nsetools/nse.py`)
- Stock APIs → Data conversions: converts responses (evidence: `src/nsetools/nse.py`)
- Index APIs → Data conversions: converts responses (evidence: `src/nsetools/nse.py`)
- Derivatives API → Exchange interface: implements interface (evidence: `src/nsetools/nse.py`)
- Bhavcopy downloader → Date handling: gets date ranges (evidence: `src/nsetools/downloader.py`)
- Bhavcopy downloader → Stock APIs: creates NSE client (evidence: `src/nsetools/downloader.py`)
