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.
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
- Language: Python 3.8–3.12
- Automation: Playwright Headless Chromium
- Security & 2FA: pyotp (TOTP calculation), hashlib
- Distribution: PyPI (Pip Package Manager), GitHub Actions CI/CD