Python
verisec is the official library for Python 3.9 and later, fully typed. PyPI
Install#
pip install verisecCreate a client#
import os
from verisec import VeriSec
client = VeriSec(api_key=os.environ["VERISEC_API_KEY"]) # sk_test_…With no arguments, VeriSec() reads VERISEC_API_KEY. Other options: timeout in seconds per attempt (default 300), max_retries (default 2) and default_headers.
Make a call#
Every endpoint is a method named after its operation, in snake case: face.verify is client.face.verify, cheques.micrLine is client.cheques.micr_line. Fields are keyword arguments spelled exactly as the API spells them (image_front, minAge).
from pathlib import Path
result = client.face.verify(image1="selfie.jpg", image2="id-photo.jpg", threshold=0.8)
print(result.match, result.similarity)
doc = client.documents.read(image_front="id-front.jpg", image_back=Path("id-back.jpg"))
cheque = client.cheques.read(image="cheque.jpg")
bin_record = client.bin.lookup("424242")An image can be a path, bytes, an open file, a data: URI or base64 you already have.
Errors#
from verisec import APIConnectionError, APIError, InsufficientCreditsError, InvalidRequestError, RateLimitError
try:
client.face.verify(image1="selfie.jpg", image2="id-photo.jpg")
except InsufficientCreditsError:
print("Not enough credits: top up.")
except InvalidRequestError as e:
print(e.code, e.param, e.message)
except RateLimitError as e:
print(f"Wait {e.retry_after} s.")
except APIError as e:
print(e.status, e.code, e.request_id)
except APIConnectionError as e:
print(e.message) # says whether the call may have runClasses: InvalidRequestError, AuthenticationError, InsufficientCreditsError, PermissionError (the library's, not the built-in), NotFoundError, RateLimitError, APIServerError, APIConnectionError and APITimeoutError, all from VeriSecError.
Webhooks#
from verisec import Webhook
event = Webhook.construct_event(request.get_data(), request.headers, os.environ["VERISEC_WEBHOOK_SECRET"])See Webhooks for a full handler.