PNSEA: High-Performance Stealth API for NSE India

PNSEA: High-Performance Stealth API for NSE India

A specialized Python library designed to fetch real-time and historical financial data from the National Stock Exchange of India using advanced browser impersonation.

“NSE’s bot protection is legendary for 403 blocks. PNSEA doesn’t just scrape; it mimics human/browser behavior to provide a stable data pipeline for traders.”


🔧 Project Summary

PNSEA (Python NSE API) is a stealth-focused library that provides a seamless interface for developers to pull Equity, FnO, and Corporate Governance data directly from the National Stock Exchange of India.

It solves the two biggest pain points in Indian financial scraping: persistent IP blocks and messy, deeply nested JSON structures.


💡 The Idea

As an FnO trader and developer, I found that most open-source NSE wrappers were either broken due to nse site updates or lacked critical data points like Insider Trading and Mutual Fund movement.

I needed a library that could power my own trading apps without constant and separate maintenance. I realized that by combining my custom scraping engine, Stealthkit, with a specialized financial parser, I could build the most robust NSE tool on the market.


🧱 Tech Stack

LayerTool/ServiceWhy I Chose It
Core EnginePython 3.10+Standard for financial data and ML
NetworkingStealthkit (Custom)Powered by curl_cffi for TLS/JA3 fingerprinting
Data ProcessingPandasFor instant conversion of JSON to DataFrames
DistributionPyPIEasy installation via pip install pnsea

⚙️ Development Breakdown

1. Bypassing the “403 Forbidden” Wall

  • Integrated Stealthkit to manage browser impersonation.
  • Rotates TLS fingerprints (Chrome, Safari, Firefox) to match legitimate retail traffic.
  • Handles NSE-specific cookie synchronization automatically—no manual session management needed.

📌 Challenge: NSE’s v3 API frequently refreshes session tokens. PNSEA handles this by automatically re-authenticating through a “stealth” entry point before executing data calls.


2. Flattening Financial Chaos

  • NSE endpoints return heavily nested JSON (often 5-6 levels deep).
  • I built a custom normalization engine that flattens these into Pandas DataFrames.
  • Result: Traders can go from nse.options.option_chain() to a strategy-ready table in under 10 lines of code.

3. Expanding the Data Horizon (Insider Trading)

Most libraries stop at stock prices. I went deeper into corporate governance:

  • Insider Trading: Tracks buying/selling by promoters and directors.
  • Pledged Data: Monitors if promoters are borrowing against their shares.
  • MF Insider: Unique tracking of Mutual Fund entry/exit points.

Key Features

  • Stealth Implementation: Uses curl_cffi to bypass Akamai/bot-shields.
  • Option Chain Specialist: Filters by expiry, strike, and underlying index (NIFTY/BANKNIFTY).
  • Corporate Intelligence: Automated extraction of Insider Trading and SAST data.
  • FastAPI-Ready: Lightweight and async-friendly for building financial dashboards.
  • Historical Data: Simple date-range fetching for backtesting.

Data Output Visuals:


Cleaned Option Chain DataFrame


Insider Trading Snapshot


💭 Lessons Learned

  • Fingerprinting Matters: Traditional headers rotation isn’t enough anymore; TLS/JA3 fingerprinting is mandatory for modern financial sites.
  • Developer UX is Key: Providing data in DataFrames instead of raw JSON increases adoption by 10x for the Quant community.
  • The “V3” Shift: NSE’s move to their v3 API required a total rethink of how endpoints are discovered—leading to the creation of the endpoint_tester utility.

🔗 Live Project

👉 PNSEA on PyPI | GitHub Repository