{"library":"oathtool","title":"OATHTool","description":"oathtool is a command-line tool and Python library for generating one-time passwords, supporting both HOTP (HMAC-based) and TOTP (Time-based) algorithms. The current version is 2.4.0, and it maintains a stable, albeit infrequent, release schedule, focusing on reliability and security.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install oathtool","pip install 'oathtool[cli]'"],"cli":{"name":"oathtool","version":"Traceback (most recent call last):"}},"imports":["from oathtool.totp import TOTP","from oathtool.hotp import HOTP"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom oathtool.totp import TOTP\n\n# Retrieve your base32-encoded secret key from an environment variable.\n# Example: 'JBSWY3DPEHPK3PXP' (this is a placeholder, use your actual secret)\nsecret_base32 = os.environ.get('OATHTOOL_SECRET', 'JBSWY3DPEHPK3PXP')\n\nif secret_base32 == 'JBSWY3DPEHPK3PXP':\n    print(\"WARNING: Using a placeholder secret. Set OATHTOOL_SECRET environment variable for actual use.\")\n\ntry:\n    # Initialize the TOTP generator with your secret.\n    # oathtool expects the secret to be base32-encoded or raw bytes.\n    # If a base32 string is provided, it will be decoded automatically.\n    totp = TOTP(secret_base32)\n\n    # Generate the current time-based one-time password.\n    current_otp = totp.code()\n    print(f\"Generated TOTP: {current_otp}\")\n\n    # You can also get the remaining time until the next code.\n    # time_left = totp.time_left()\n    # print(f\"Time left until next code: {time_left} seconds\")\n\nexcept Exception as e:\n    print(f\"Error generating OTP: {e}\")\n    print(\"Ensure your OATHTOOL_SECRET is a valid base32 encoded string.\")","lang":"python","description":"This quickstart demonstrates how to generate a TOTP code using a base32-encoded secret key, typically obtained from a 2FA setup process. It emphasizes retrieving the secret securely from an environment variable and includes basic error handling for common key issues.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}