Automated Upstox login using Selenium and TOTP
Project description
Upstox Auto Login A Python package to automate the Upstox API v2 login flow using Selenium and TOTP, handling the complete OAuth2 process to retrieve an access_token.
⚠️ Security Disclaimer This package handles sensitive credentials (API keys, PIN, TOTP secret). Storing these as plaintext is a major security risk. It is highly recommended to use environment variables or a secret manager instead of hardcoding credentials. This tool is intended for personal use in secure environments only.
How It Works This tool automates the Upstox login flow by launching a headless Chrome browser to enter your User ID, TOTP, and PIN. It captures the authorization code upon successful login, exchanges it for an access_token, and then safely closes the browser.
Prerequisites Python 3.7+
Google Chrome installed.
An Upstox Developer App with your API_KEY, SECRET_KEY, and a configured redirect_url.
Installation pip install upstox-auto-login
Usage The auto_login function requires your Upstox credentials.
Parameters Parameter
Type
Description
API_KEY
str
Your application's API Key.
SECRET_KEY
str
Your application's Secret Key.
USER_ID
str
Your 10-digit mobile number for Upstox.
PIN
str
Your 6-digit Upstox PIN.
TOTP_SECRET
str
The secret key from your authenticator app.
redirect_url
str
(Optional) The redirect URI from your app settings. Defaults to https://127.0.0.1:5000/.
Example from upstox_auto_login import auto_login import os import logging
Recommended: Load credentials from environment variables
API_KEY = os.getenv("UPSTOX_API_KEY")
Configure logging to see progress
logging.basicConfig(level=logging.INFO)
try: # Call the auto_login function access_token = auto_login( API_KEY="your_api_key", SECRET_KEY="your_secret_key", USER_ID="your_10_digit_mobile_number", PIN="your_6_digit_pin", TOTP_SECRET="your_totp_secret_key" )
if access_token:
print(f"Success! Access Token: {access_token}")
# Use this token with your Upstox API client
else:
print("Login failed. Check logs for details.")
except Exception as e: print(f"An unexpected error occurred: {e}")
Error Handling The function is designed to handle failures gracefully. It logs any errors during the process and returns None on failure.
Contributing Contributions are welcome! Please open an issue or submit a pull request for any bugs or feature requests.
License This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file upstox_auto_login-0.1.3.tar.gz.
File metadata
- Download URL: upstox_auto_login-0.1.3.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
debd61a6b19412189b61f405b0cfc49c728af972542a982e9cc2c4248c67ccdb
|
|
| MD5 |
759d6ae3019610d5923fdd56fdd681ad
|
|
| BLAKE2b-256 |
8bab613c37667d9aa47e759f63bafff7c045daec209131e9a05e73108b44a32e
|
File details
Details for the file upstox_auto_login-0.1.3-py3-none-any.whl.
File metadata
- Download URL: upstox_auto_login-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba2a28406eb427b0a56bf16792c97f794eb18e54c7074d7af6b1e892140189eb
|
|
| MD5 |
276dbc45d5dfe0790c215719a3e38030
|
|
| BLAKE2b-256 |
5c35b550f2147152cb778a03e124438e69d8ac4acf976cb35dd5dfe5ee580664
|