Skip to main content

indiaopt

Enterprise-grade Python library for Indian stock market (NSE & BSE) data.

PyPI version Python 3.10+ License: MIT

indiaopt provides a robust, highly-performant, and production-ready interface to fetch Option Chain and Market Data from both the National Stock Exchange (NSE) and Bombay Stock Exchange (BSE) of India.

It includes built-in circuit breakers, exponential backoff, browser impersonation (via curl_cffi), automatic retry logic, and zero-overhead data models.

Features

  • Multi-Exchange: Unified API for both NSE and BSE.
  • Resilience: Built-in circuit breakers, automatic retries with exponential backoff and jitter.
  • Evasion: Uses curl_cffi to impersonate browsers and avoid NSE rate-limiting/bot-protection.
  • Performance: Asynchronous via thread-pools, memory-efficient dataclasses (slots=True), and connection pooling.
  • Type-Safe: Fully typed with PEP 561 compliance (py.typed).
  • Configuration: Flexible configuration via environment variables, .env files, or code.

Installation

pip install indiaopt

Requires Python 3.10+

Quick Start

import asyncio
from indiaopt import NSEClient

async def main():
    # Context manager automatically handles session lifecycle
    async with NSEClient() as nse:
        # Fetch the option chain for NIFTY
        result = await nse.fetch_option_chain("NIFTY")
        
        print(f"Spot Price: {result.spot_price}")
        print(f"ATM Strike: {result.atm_strike}")
        print(f"Total Call OI: {result.total_call_oi}")
        print(f"Total Put OI: {result.total_put_oi}")
        print(f"PCR: {result.pcr:.2f}")

        # Iterate over the 5 strikes above and below ATM
        for row in result.atm_window(n=5):
            print(f"Strike: {row.strike} | CE OI: {row.call_oi} | PE OI: {row.put_oi}")

if __name__ == "__main__":
    asyncio.run(main())

Advanced Configuration

You can configure indiaopt via a .env file or environment variables:

INDIAOPT_MAX_RETRIES=5
INDIAOPT_FETCH_TIMEOUT=15.0
INDIAOPT_PROXY_URLS=http://proxy1:8080,http://proxy2:8080
INDIAOPT_LOG_LEVEL=INFO

Or configure it in code:

from indiaopt import NSEClient, Settings

settings = Settings(
    max_retries=3,
    fetch_timeout=10.0,
    circuit_failure_threshold=5,
)

async with NSEClient(settings=settings) as nse:
    result = await nse.fetch_option_chain("BANKNIFTY")

Exception Handling

The library provides a detailed exception hierarchy under IndiaOptError:

from indiaopt import RateLimitError, CircuitOpenError, NSEClient

try:
    async with NSEClient() as nse:
        await nse.fetch_option_chain("NIFTY")
except RateLimitError as e:
    print(f"Rate limited by exchange! Try again in {e.retry_after} seconds.")
except CircuitOpenError as e:
    print(f"Circuit breaker is open. Fails fast without hitting network.")

Documentation

Full documentation is available at https://indiaopt.readthedocs.io.

License

MIT License. See LICENSE for details.

Metadata

Release files for indiaopt 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for indiaopt 0.1.1
File Size Uploaded Provenance Actions
indiaopt-0.1.1.tar.gz 30.2 kB Without provenance Details for indiaopt-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for indiaopt 0.1.1
File Interpreter ABI Platform Actions
indiaopt-0.1.1-py3-none-any.whl Python 3 none any Details for indiaopt-0.1.1-py3-none-any.whl

Total release size: 67.7 kB

Release files / indiaopt-0.1.1.tar.gz

Download URL indiaopt-0.1.1.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
02a15d6b99e8eabab0f6081f23454de3c77655f7a3183450a235e7977fe209f7
BLAKE2b-256 checksum
How to use checksums
699587e72c51add2c90981ef81ed7dc003ff5b3c5c328de267a5bb5a3026293c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / indiaopt-0.1.1-py3-none-any.whl

Download URL indiaopt-0.1.1-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3878e5af70a968439175c1451648ed24523caf1c9f533b9eab5d4e01ce3a6b73
BLAKE2b-256 checksum
How to use checksums
5c8b2584162b250bd5fbf34b180af834aa84e322b0a5bd6a31d9f1b76163f51f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for indiaopt 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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