Install & Compatibility
Where this runs
tested against v2.2.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 3.1s · import 0.000s · 23MB
20MB installed
● package 20MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AuthyApiException
✓ from authy import AuthyApiException
✗ from authy import AuthyApiClient
AuthyException
✓ from authy import AuthyException
AuthyFormatException
✓ from authy import AuthyFormatException
Initializes the Authy API client using an API key and demonstrates how to check user status and verify a 2FA token. Ensure your `AUTHY_API_KEY` environment variable is set or replace the placeholder. Operations will likely fail without a valid API key, Authy ID, and a real token.
import os
from authy import AuthyApiClient
from authy.authy_exceptions import AuthyException
# IMPORTANT: Replace 'YOUR_AUTHY_API_KEY_HERE' with your actual Authy API key
# or, preferably, set it as an environment variable: export AUTHY_API_KEY='...'
api_key = os.environ.get('AUTHY_API_KEY', 'YOUR_AUTHY_API_KEY_HERE')
if api_key == 'YOUR_AUTHY_API_KEY_HERE' or not api_key:
print("WARNING: Please set the AUTHY_API_KEY environment variable "
"or replace 'YOUR_AUTHY_API_KEY_HERE' with your actual key to run this example.")
# In a real application, you might raise an error or handle this differently.
# For a runnable quickstart, we'll try to proceed but expect failures if key is invalid.
try:
authy_api = AuthyApiClient(api_key)
# --- Example 1: Check User Status (requires an existing Authy ID) ---
# Replace with an actual Authy ID from a user registered in your Authy app.
# If using a dummy ID, this call will likely fail with a "User not found" error.
sample_authy_id = "1234567" # Example: Replace with a real Authy ID if you have one
print(f"\n--- Attempting to get status for Authy ID: {sample_authy_id} ---")
user_status_response = authy_api.users.status(sample_authy_id)
if user_status_response.ok():
print(f"SUCCESS: User {sample_authy_id} status: {user_status_response.content}")
# Example of accessing content: user_status_response.content['user']['status']
else:
print(f"FAILURE: Could not get user status. Errors: {user_status_response.errors()}")
print(f"Full API response content: {user_status_response.content}")
# --- Example 2: Verify a 2FA Token (requires an existing Authy ID and a token) ---
# Replace with a real Authy ID and a real token generated for that user.
# If using dummy values, this call will likely fail with "invalid token" or "user not found".
sample_token_authy_id = sample_authy_id # Use the same dummy ID for consistency
sample_token_code = "0000000" # Example: Replace with a real 2FA token
print(f"\n--- Attempting to verify token '{sample_token_code}' for Authy ID: {sample_token_authy_id} ---")
token_verification_response = authy_api.tokens.verify(sample_token_authy_id, sample_token_code)
if token_verification_response.ok():
print(f"SUCCESS: Token '{sample_token_code}' verified for Authy ID {sample_token_authy_id}.")
# Example of accessing content: token_verification_response.content['token']['message']
else:
print(f"FAILURE: Token verification failed. Errors: {token_verification_response.errors()}")
print(f"Full API response content: {token_verification_response.content}")
except AuthyException as e:
print(f"\nAn Authy API specific error occurred: {e}")
except Exception as e:
print(f"\nAn unexpected error occurred: {e}")
print("\n--- Quickstart example finished ---")
Upgrade
Version history
2.2.6latest on PyPI · released Apr 15, 2020
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Authy API.