Python SDK
Python SDK
Section titled “Python SDK”pip install openbiometricsInitialize
Section titled “Initialize”import osfrom openbiometrics_sdk import OpenBiometrics
ob = OpenBiometrics( api_key=os.environ["OB_API_KEY"], # base_url="http://localhost:8000", # for self-hosted)Face Detection
Section titled “Face Detection”result = ob.faces.detect("photo.jpg")
for face in result["faces"]: print(f"Age: {face['demographics']['age']}") print(f"Gender: {face['demographics']['gender']}") print(f"Quality: {face['quality']['overall_score']:.0f}/100") print(f"Live: {face['liveness']['is_live']}")1:1 Verification
Section titled “1:1 Verification”result = ob.faces.verify("id_card.jpg", "selfie.jpg")
if result["is_match"]: print(f"Identity verified ({result['similarity']:.1%} match)")else: print("Mismatch")Watchlist Operations
Section titled “Watchlist Operations”# Enrollresult = ob.watchlists.enroll("alice.jpg", label="Alice")print(f"Enrolled: {result['identity_id']}")
# Identifyresult = ob.watchlists.identify("unknown.jpg")for match in result["matches"]: print(f"{match['label']}: {match['similarity']:.1%}")
# Removeob.watchlists.remove(result["identity_id"])
# Listprint(ob.watchlists.list())With Flask
Section titled “With Flask”from flask import Flask, request, jsonifyfrom openbiometrics_sdk import OpenBiometrics
app = Flask(__name__)ob = OpenBiometrics(api_key="any-value", base_url="http://localhost:8000")
@app.route("/verify-identity", methods=["POST"])def verify_identity(): id_photo = request.files["id_photo"].read() selfie = request.files["selfie"].read()
result = ob.faces.verify(id_photo, selfie)
return jsonify({ "verified": result["is_match"], "confidence": result["similarity"], })With FastAPI
Section titled “With FastAPI”from fastapi import FastAPI, UploadFilefrom openbiometrics_sdk import OpenBiometrics
app = FastAPI()ob = OpenBiometrics(api_key="any-value", base_url="http://localhost:8000")
@app.post("/verify-identity")async def verify_identity(id_photo: UploadFile, selfie: UploadFile): result = ob.faces.verify( await id_photo.read(), await selfie.read(), ) return {"verified": result["is_match"], "confidence": result["similarity"]}Document Processing
Section titled “Document Processing”Scan identity documents, extract text via OCR, and parse MRZ zones.
# Full document scan (detect type + OCR + MRZ)doc = ob.documents.scan("id_card.jpg")print(f"Type: {doc['document_type']}")print(f"Surname: {doc['mrz']['parsed']['surname']}")
# OCR onlyocr = ob.documents.ocr("id_card.jpg")print(ocr["text"])
# MRZ onlymrz = ob.documents.mrz("id_card.jpg")print(mrz["parsed"])
# Verify a selfie against the document photoresult = ob.documents.verify("selfie.jpg", "id_card.jpg")print(f"Document match: {result['is_match']} ({result['similarity']:.1%})")Active Liveness
Section titled “Active Liveness”Interactive challenge-response liveness sessions for verifying a real person is present.
# Create a session with specific challengessession = ob.liveness.create_session( challenges=["blink", "turn_left"], ttl_seconds=120,)print(f"Session: {session['session_id']}")print(f"First challenge: {session['challenges'][0]}")
# Submit frames as the user completes challengesupdated = ob.liveness.submit_frame(session["session_id"], frame_bytes)print(f"Status: {updated['status']}")
# Check session statestate = ob.liveness.get_session(session["session_id"])print(f"Completed: {state['status']}")
# Cancel a sessionob.liveness.delete_session(session["session_id"])Video Management
Section titled “Video Management”Manage RTSP camera sources for real-time face processing.
# Add a cameracamera = ob.video.add_camera( name="Lobby", url="rtsp://192.168.1.100/stream", fps=5,)print(f"Camera ID: {camera['camera_id']}")
# List all camerascameras = ob.video.list_cameras()for cam in cameras: print(f"{cam['name']}: {cam['status']}")
# Get a snapshot (returns raw bytes)snapshot = ob.video.get_snapshot(camera["camera_id"])
# Remove a cameraob.video.remove_camera(camera["camera_id"])Events & Webhooks
Section titled “Events & Webhooks”Subscribe to events and register webhooks for real-time notifications.
# Register a webhookwebhook = ob.events.register_webhook( url="https://example.com/hooks/ob", events=["face.identified", "liveness.completed"],)print(f"Webhook ID: {webhook['webhook_id']}")print(f"Secret: {webhook['secret']}")
# List webhookswebhooks = ob.events.list_webhooks()
# Get recent eventsevents = ob.events.get_recent(event_type="face.identified", limit=10)for event in events: print(f"{event['type']} at {event['timestamp']}")
# Delete a webhookob.events.delete_webhook(webhook["webhook_id"])Health checks, model status, and runtime configuration.
# Health checkhealth = ob.admin.health()print(f"Status: {health['status']}, Uptime: {health['uptime_seconds']}s")
# List loaded modelsmodels = ob.admin.models()for model in models: print(f"{model['name']}: {model['status']}")
# Get current configconfig = ob.admin.config()print(config)
# Update configob.admin.config(max_faces=10, det_thresh=0.6)