Skip to main content

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 credentials as plaintext is a major security risk. It is highly recommended to:

  • Use environment variables or a secret manager.
  • Avoid sharing your credentials in public repositories. This tool is intended for personal use in secure environments only.

🧩 How It Works

The tool:

  1. Launches a headless Chrome browser.
  2. Automates the login by entering your User ID, TOTP, and PIN.
  3. Captures the authorization code after successful login.
  4. Exchanges it for an access_token via the Upstox OAuth2 flow.
  5. Closes the browser automatically.

You can then use the returned access_token in your Upstox API client.


🛠️ Prerequisites

Before using this package, make sure you have:

  • 🐍 Python 3.7+

  • 🌐 Google Chrome (latest version)

  • 🔑 An Upstox Developer App with:

    • API_KEY
    • SECRET_KEY
    • Configured redirect_url

📦 Installation

pip install upstox-auto-login

⚙️ Usage

The main function provided is auto_login() — it automates the entire login flow.

Function Parameters

Parameter Type Description
API_KEY str Your Upstox API Key
SECRET_KEY str Your Upstox Secret Key
USER_ID str Your 10-digit Upstox mobile number
PIN str Your 6-digit Upstox trading PIN
TOTP_SECRET str Your TOTP secret key from the authenticator app
redirect_url str (Optional) Redirect URI (default: 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 track the login process
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}")
    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.

  • Logs detailed errors during execution.
  • Returns None if the login or token exchange fails.

Contributing

Contributions are welcome! If you’d like to:

  • Report a bug 🐛
  • Request a feature 💡
  • Submit a pull request 🧩

Please open an issue or PR on the GitHub repository.


##License

This project is licensed under the MIT License. See the LICENSE file for more details.


🧑‍💻 Author

Uttam Kumar Python Developer • Automation & Trading Systems


⭐ If you find this project useful, don’t forget to star the repo!

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

upstox_auto_login-0.1.5.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

upstox_auto_login-0.1.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file upstox_auto_login-0.1.5.tar.gz.

File metadata

  • Download URL: upstox_auto_login-0.1.5.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.10

File hashes

Hashes for upstox_auto_login-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3ec031b745a1c7c90f3c17fbfdc4873b3496e2b477b025b183817befbee53f5c
MD5 ade51a739c0716a3232bcbd1ea7eb15d
BLAKE2b-256 cc5cd4e236242e4cb06d35cb1b38fdc9911ce1d89f19f8a4d1f74138d0e9f215

See more details on using hashes here.

File details

Details for the file upstox_auto_login-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for upstox_auto_login-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e8aafff654290c89255ebaad08a1eddf0dda9cf3ac2b00f3deb4caae2d037274
MD5 22cee3a8f719150d2616c040149e4690
BLAKE2b-256 6bffa6e67d608668366aabafa837f1f629ce25a22c860f8c76437dd96a81500c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page