Python SDK
Official Python wrapper for the Shoonya OAuth API — handles the OAuth handshake, and gives typed methods for orders, market data, positions, and the WebSocket feed.
Official Python wrapper for the Shoonya OAuth API — handles the OAuth handshake, and gives typed methods for orders, market data, positions, and the WebSocket feed.
Overview
The Python SDK (package name
NorenRestApiOAuth, classNorenApi) wraps every REST endpoint covered elsewhere in this documentation — orders, market data, positions, holdings, calculators — plus the OAuth login handshake and the WebSocket feed, behind typed Python methods. Use it instead of hand-rollingrequestscalls againstjData/jKeypayloads directly.getOAuthURL→getAccessToken→injectOAuthHeader. It is a separate build from the password/TOTP-basedNorenApiPywrapper; don't mix credential styles between the two.Installation
NorenRestApiOAuthNorenApicred.yml— holdsoauth_url,API_KEY,SECRET_KEY,client_id,UID;Access_tokenandAccount_IDare written back to it after login.Dependencies (from
requirements.txt):NorenRestApiOAuthNorenApiclass itself.selenium>=4.15.0webdriver-manager>=4.0.0pyotp>=2.9.0NorenApiclass itself only needsNorenRestApiOAuth.selenium,webdriver-manager, andpyotpexist to automate the browser-based OAuth handshake (getOAuthURL→ login →auth_code) end-to-end — skip them if you're completing that step manually and only need the REST wrapper.OAuth & Session Methods
getOAuthURL(oauth_url, API_KEY)cred.yml. Open it in a browser; after login, the redirect URL carries theauth_code.getAccessToken(auth_code, SECRET_KEY, client_id, UID)auth_codefor an access token. Returns(access_token, userid, refresh_token, account_id)and writesAccess_token/Account_IDback intocred.yml.injectOAuthHeader(Access_token, UID, Account_ID)logout(){"stat": "Ok", "request_time": ...}on success.forgot_passwordOTP(userid, pan)Available Functionality
searchscrip,get_security_info,get_quotes,get_time_price_series,get_daily_price_series,get_option_chainplace_order,modify_order,cancel_order,exit_order,position_product_conversion,get_orderbook,get_tradebook,single_order_historyget_holdings,get_positions,get_limitsspan_calculator,get_option_greekstart_websocket,subscribe,unsubscribeEvery method mirrors the field-level request/response contract documented on this site's individual API pages — e.g.
place_order'sprice_typeargument maps to theprctypfield on Place Order. Refer to those pages for allowed values and error responses; the SDK doesn't change the underlying validation rules.Quick Start Example
Best Practices
cred.ymlas a secrets file —SECRET_KEY,Access_token, andAccount_IDlive in it once populated. Never commit it to source control.getAccessTokenrewritesAccess_token/Account_IDincred.ymlon every successful login — build your credential loading to read the file fresh rather than caching it across runs.injectOAuthHeaderonce per session immediately after obtaining the token; every wrapped method depends on it being set first.stat/emsgconvention — always checkstat == "Ok"before trusting a response field, the same as with raw REST calls. See Error Handling.