Python icon

Python Quick Start Guide

Get started with FacePing's face recognition API using Python

Prerequisites

Installation

First, create a new Python project and install the required dependencies:

mkdir faceping-python
cd faceping-python
pip install requests python-dotenv

Step 1: Create Face Group

Create a new file create_group.py:

import os
import requests
from dotenv import load_dotenv

load_dotenv()

def create_group(group_name):
    try:
        response = requests.post(
            f"https://api.faceping.ai/groups/{group_name}",
            headers={
                'Authorization': f'Bearer {os.getenv("FACEPING_API_KEY")}'
            }
        )
        response.raise_for_status()
        print('Group created successfully')
        return response.json()
    except Exception as error:
        print('Error creating group:', error)
        return None

# Usage
result = create_group('my-group')
print(result)

Step 2: Upload Face Image

Create a new file upload_face.py:

import os
import requests
from dotenv import load_dotenv

load_dotenv()

def upload_face(group_name, image_path):
    try:
        with open(image_path, 'rb') as image_file:
            response = requests.post(
                f"https://api.faceping.ai/groups/{group_name}/faces",
                headers={
                    'Authorization': f'Bearer {os.getenv("FACEPING_API_KEY")}'
                },
                files={'image': image_file}
            )
            response.raise_for_status()
            print('Face uploaded successfully')
            return response.json()
    except Exception as error:
        print('Error uploading face:', error)
        return None

# Usage
result = upload_face('my-group', 'path/to/face.jpg')

Step 3: Search for Faces

Create a new file search_faces.py:

import os
import requests
from dotenv import load_dotenv

load_dotenv()

def search_faces(group_name, image_path):
    try:
        with open(image_path, 'rb') as image_file:
            response = requests.post(
                f"https://api.faceping.ai/groups/{group_name}/search",
                headers={
                    'Authorization': f'Bearer {os.getenv("FACEPING_API_KEY")}'
                },
                files={'image': image_file}
            )
            response.raise_for_status()
            data = response.json()
            matches = data.get('matches', [])
            print(f'Found {len(matches)} matches')
            return matches
    except Exception as error:
        print('Error searching faces:', error)
        return []

# Usage
matches = search_faces('my-group', 'path/to/search_face.jpg')
for match in matches:
    print(f"Match Score: {match['score']}")

Security Notes

  • Images are immediately discarded after vector conversion
  • Face vectors cannot be reverse-engineered into images
  • Always use HTTPS for all API calls
  • Store your API keys in environment variables (.env file)

Ready to get started?

Take a look at the API documentation
API docs