Upstox Auth Pro (Python SDK)

Published open-source Python library automating daily Upstox OAuth2 login, Playwright TOTP 2FA authentication, pluggable token storage, and diagnostic screenshot capture.

Python 3.8–3.12 Playwright pyotp (TOTP) PyPI Release CLI
PyPI Package (v1.1.3) → GitHub Repository → Read Engineering Case Study →

1. Overview & Installation

pip install upstox-auth-pro

Financial regulations mandate daily OAuth2 token expiration for brokerage APIs. upstox-auth-pro automates authorization code extraction using Playwright headless browser sessions and TOTP generation, ensuring valid daily token acquisition without human intervention.

2. Automation Sequence Architecture

OAuth2 TOTP 2FA Sequence
sequenceDiagram
    participant App as Client Application
    participant SDK as UpstoxAuthPro SDK
    participant Browser as Playwright Engine
    participant Upstox as Upstox Auth Server

    App->>SDK: get_valid_token()
    alt Valid Token in Storage (< 24h IST)
        SDK-->>App: Return Cached Token
    else Token Expired / Missing
        SDK->>Browser: Launch Headless Browser
        Browser->>Upstox: Submit Mobile & PIN
        SDK->>SDK: Generate TOTP 2FA (pyotp)
        Browser->>Upstox: Submit 6-digit TOTP
        Upstox-->>Browser: Redirect with Auth Code
        Browser-->>SDK: Extract Auth Code
        SDK->>Upstox: Exchange Code for Access Token
        SDK-->>App: Return Valid Access Token
    end
            

3. Technology Stack