← Back to Blog
Tutorial2 min read

How to Integrate Face Recognition API into a Python Application

Step-by-step Python tutorial for face recognition API integration — register faces, recognize people, verify identities, and detect liveness.

Setup

Install the requests library if you don't have it:

bash
pip install requests

Set your API key:

python
import requests

API_KEY = "your-api-key-here"

BASE_URL = "https://faceapi.arsa.technology/api/v1"

HEADERS = {"x-key-secret": API_KEY}

Register a Face

python
def register_face(face_uid, image_path):

response = requests.post(

f"{BASE_URL}/face_recognition/register_face",

headers={*HEADERS, "x-face-uid": face_uid},

files={"face_image": open(image_path, "rb")}

)

return response.json()

result = register_face("employee_001", "photos/alice.jpg")

print(result) # {"status": "success", "message": "employee_001 registered"}

Recognize a Face

python
def recognize_face(image_path):

response = requests.post(

f"{BASE_URL}/face_recognition/recognize_face",

headers=HEADERS,

files={"face_image": open(image_path, "rb")}

)

return response.json()

result = recognize_face("photos/unknown.jpg")

for face in result.get("faces", []):

print(f"Identity: {face['recognition_uidresult']}")

print(f"Confidence: {face['recognition_confidence']}")

print(f"Real face: {face['passive_liveness']['is_real_face']}")

print(f"Age: {face.get('age')}, Gender: {face.get('gender')}")

Verify Two Faces (1:1)

python
def verify_faces(image1_path, image2_path):

response = requests.post(

f"{BASE_URL}/face_recognition/validate_faces",

headers=HEADERS,

files={

"image1": open(image1_path, "rb"),

"image2": open(image2_path, "rb")

}

)

return response.json()

result = verify_faces("selfie.jpg", "id_photo.jpg")

print(f"Match: {result['match_result']}")

print(f"Similarity: {result['similarity_score']}")

Face Analytics (Age & Gender)

python
def analyze_face(image_path):

response = requests.post(

f"{BASE_URL}/face_analytics",

headers=HEADERS,

files={"face_image": open(image_path, "rb")}

)

return response.json()

result = analyze_face("photo.jpg")

for face in result.get("faces", []):

print(f"Age: {face['age']}, Gender: {face['gender']}")

Error Handling

python
def safe_api_call(func, args):

try:

result = func(*args)

if result.get("status") == "fail":

print(f"API error: {result.get('message')}")

return result

except requests.exceptions.RequestException as e:

print(f"Network error: {e}")

return None

Next Steps

  • Build an attendance system
  • Add liveness detection
  • KYC verification
  • Full API reference
  • Ready to get started?

    Try ARSA Face Recognition API free with 100 API calls/month.

    Start Free Trial