touchque-device-risk
The official Python server SDK for Touchque Device Risk: a visitor ID for every browser on your sign-up, password-reset, sign-in or approval page, a risk verdict for an account, a search of your identifications, and the activity your server saw (payments, failed sign-ins, probing, SMS codes, wrong codes).
The browser side is @touchque/device-risk
(the script tag, or identify()). Device risk is a paid add-on: until your workspace
turns it on, every call answers 409 device_risk_off.
📘 Full docs: support.touchque.com
Install
pip install touchque-device-risk
Python 3.7 or later. The package has its own client: it does not need touchque-authenticator.
Setup
Use the API key and secret of your workspace (Touchque dashboard → Developers → API keys):
TQ_API_KEY=tq_your_key
TQ_API_SECRET=your_api_secret
from touchque_device_risk import Config, TouchqueDeviceRisk
device_risk = TouchqueDeviceRisk() # from the environment
# device_risk = TouchqueDeviceRisk(Config(api_key=..., api_secret=...)) # explicit
Config takes api_key, api_secret, base_url (default https://api.touchque.com, or
TQ_API_URL; plaintext http:// only for localhost) and timeout (ms, default 10000).
Every request is signed with HMAC-SHA256, like every Touchque SDK.
Check a page's identification
With the script tag on your page, the form arrives with a touchque_request_id field.
Pass it as it came: missing, empty, made up or expired is still a verdict
(report: missing, unknown, expired; the signal device_identification_missing),
never an exception.
r = device_risk.check(
request.form.get('touchque_request_id'),
event='sign_up', # sign_in (default), sign_up, password_reset, approval
external_username=email,
client_ip=request.remote_addr,
)
if r['stepUp']:
ask_for_email_code() # ask for more: never refuse on it alone
# r['visitorId'], r['signals'], r['bot'], r['network'], r['accountDevice'], r['suspect'], r['caseCode']
device_risk= instead of the request id relays the page's report (collect()) whole.
stepUp: ask for more on this page (an emailed code, a passkey, a number-matched approval). It fails toward asking: anything but an exactFalseisTrue.accountDevice: once an account is named, did it use this device before (known,likely,new,first).suspect: the suspect score in shadow (0-100,band,wouldDo, every reason with its points and who proves it). It decides nothing yet.engine == 'unavailable': the risk engine could not be reached and the verdict is a safe default (an outage, not risk).
For sign-ins approved with Touchque, pass the request id to login.request /
risk.check of the touchque SDK as device_risk_request_id instead.
Read and search identifications
event = device_risk.get_event(request_id) # the trusted identification (dre_...)
cursor = None
while True:
page = device_risk.search_events(signal='device_tampered', from_='2026-11-01', cursor=cursor)
for e in page['events']:
print(e['at'], e['visitorId'], e['caseCode'])
cursor = page['nextCursor']
if not cursor:
break
Filters: from_, to (7 days by default, at most 90), signal, step_up, kind,
origin, ip (an address or CIDR range, a filter only), account, visitor_id,
request_id, cursor, limit (1-100).
Report activity
What a visitor did that your server saw. Touchque counts it per visitor and per network
and answers the abuse codes it raised (abuse_card_testing, abuse_card_shared,
abuse_login_failures, abuse_probing, abuse_otp_pumping, abuse_code_guessing);
for 24 hours the visitor's next checks carry them and the suspect score weighs them.
a = device_risk.activity(
'payment_attempt', # login_failed, not_found, forbidden, otp_sent, code_failed
request_id=request.form.get('touchque_request_id'), # or visitor_id=, or client_ip= alone
client_ip=request.remote_addr,
outcome='declined', # approved, declined, error
card={'bin': '424242', 'last4': '4242'}, # never the card number
)
if 'abuse_card_testing' in a['signals']:
stop_taking_cards() # your call
A card is its BIN (6-8 digits) and last 4 digits only. A card number, in any field of
card, raises TouchqueConfigException before anything is sent. phone= (for
otp_sent) and path= (for not_found / forbidden, answered with its pathClass)
are optional.
Webhooks
DeviceRiskWebhookEvents.DEVICE_RISK_SIGNAL and DEVICE_RISK_ALERT are the event
values of Touchque's Device risk webhooks. Verify a webhook's signature with the
touchque SDK before reading it.
Errors
TouchqueConfigException: a bug in your code (a wrongevent, a card number, a bad request id forget_event), raised before any request.TouchqueAPIException(status,code,case_code): Touchque answered with an error, e.g. 409device_risk_off.TouchqueFeatureNotInPlanException,TouchqueFeatureReadOnlyExceptionandTouchqueFeatureOffException(allTouchqueFeatureException,feature == 'device_risk') when your organization cannot use Device risk here.TouchqueNetworkException: the request never reached Touchque (generally safe to retry).
Development
python3 -m venv .venv && .venv/bin/pip install -e '.[dev]'
.venv/bin/python -m pytest
The contract tests start the shared fake API (../testing/fake-touchque-api.mjs) and
need node on PATH; they skip themselves otherwise.
License
MIT
Metadata
Release files for touchque-device-risk 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| touchque_device_risk-1.0.0.tar.gz | 22.3 kB | Without provenance | Details for touchque_device_risk-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| touchque_device_risk-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for touchque_device_risk-1.0.0-py3-none-any.whl |
Total release size: 40.1 kB
Release files / touchque_device_risk-1.0.0.tar.gz
| Download URL | touchque_device_risk-1.0.0.tar.gz |
|---|---|
| Size | 22.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d568fd0bd0d9dcdc287e07d572577ee2bb7c4df3622a3d7caed02c34a3f5d1b
|
|
BLAKE2b-256 checksum How to use checksums |
d031712be2fde38063e4c703c33e5993eef549c0ab2b440addba6105d474e697
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / touchque_device_risk-1.0.0-py3-none-any.whl
| Download URL | touchque_device_risk-1.0.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
007bb70cbee4a5a6727611654f17ba1afb19871c744d0b0dfe8cbff32cbad70b
|
|
BLAKE2b-256 checksum How to use checksums |
23804303f48ea5e6f8c66be3a16eca55cdfcd44df5953d2980eb104ed7efbeea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for touchque-device-risk 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.