Skip to main content

AlchemyFace

PyPI CI Ruff Python 3.10+

Face detection and recognition built on YuNet and SFace. Small, typed, and dependency-light: OpenCV, NumPy, Typer. Nothing else.

Why

Most Python face-recognition libraries pull in dlib, PyTorch or TensorFlow. AlchemyFace uses two small ONNX models through OpenCV's own DNN runtime, so a working install is a few megabytes of Python and about 37 MB of weights fetched once, on first use.

Install

pip install alchemyface

Use

import cv2
from alchemyface import Recognizer

r = Recognizer()                       # weights download once, then cached

r.enroll("prashant", cv2.imread("me.jpg"))
r.enroll("alice",    cv2.imread("alice.jpg"))

for recognition in r.identify(cv2.imread("group.jpg")):
    face, match = recognition.face, recognition.match
    if match:
        print(f"{match.label} at {face.bbox} ({match.score:.2f})")
    else:
        print(f"unknown face at {face.bbox}")

Enrolled faces live in memory. Persist them when you are done:

r.store.save("gallery.npz")
r.store.load("gallery.npz")

Bring your own components

Recognizer is a thin facade over three protocols — Detector, Embedder and FaceStore. Any object satisfying the protocol can be substituted, which is how a pgvector-backed store or a different embedding model will slot in later without touching the pipeline.

from alchemyface import Recognizer
from alchemyface.detection import YuNetDetector
from alchemyface.embedding import SFaceEmbedder
from alchemyface.store import InMemoryStore

r = Recognizer(
    detector=YuNetDetector(score_threshold=0.8),
    embedder=SFaceEmbedder(),
    store=InMemoryStore(),
    threshold=0.363,
)

Live video

from alchemyface import Recognizer
from alchemyface.capture import VideoSource

r = Recognizer()
r.store.load("gallery.npz")

with VideoSource(0, width=1280, height=720) as camera:
    for frame in camera.frames():
        for recognition in r.identify(frame):
            match = recognition.match
            print(match.label if match else "unknown", recognition.face.bbox)

CLI

alchemyface download-models          # pre-fetch weights
alchemyface enroll  --name prashant --image me.jpg --gallery g.npz
alchemyface identify --image group.jpg --gallery g.npz

Model weights

Weights are resolved in this order, first hit wins:

  1. model_dir= passed to Recognizer
  2. $ALCHEMYFACE_MODEL_DIR
  3. ~/.cache/alchemyface/models/
  4. downloaded from the OpenCV Zoo and SHA256-verified

To work fully offline, point at a directory you already have:

export ALCHEMYFACE_MODEL_DIR=/path/to/onnx

The recognition threshold

The default cosine threshold is 0.363, SFace's published operating point: above it, two embeddings are treated as the same person. Raise it for fewer false accepts, lower it for fewer false rejects. It is a tunable, not a constant — validate it against your own data before relying on it.

Development

Requires pyenv with pyenv-virtualenv.

pyenv install 3.10.6                      # if not already present
pyenv virtualenv 3.10.6 alchemyface       # .python-version activates it here
pip install -e ".[dev]"
Command Does
pytest tests/ -m "not models and not camera" the fast suite — no models, camera or network
pytest tests/ -m "not camera" adds the tests that load the real ONNX weights
ruff check src tests lint
ruff format src tests format
mypy src/alchemyface type check
python -m build build the wheel and sdist

Tests that need the real weights are marked models and skip unless ALCHEMYFACE_MODEL_DIR points at a directory containing them:

export ALCHEMYFACE_MODEL_DIR="$PWD/_local/onnx"

A note on data

This repository contains a _local/ directory that is git-ignored and must stay that way. It holds face embeddings, name recordings and captured images of real, identifiable people, carried over from the internal prototype this library grew out of. Under Japan's APPI and GDPR Article 9 those are sensitive personal data. They are development fixtures only: they are excluded from the wheel, the sdist and version control, and they must never be published.

Licence

MIT — see LICENSE.

The ONNX weights are distributed by the OpenCV Zoo under their own terms — YuNet under MIT, SFace under Apache-2.0 — and are downloaded at runtime rather than redistributed here.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alchemyface-0.4.0.tar.gz (45.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alchemyface-0.4.0-py3-none-any.whl (49.4 kB view details)

Uploaded Python 3

File details

Details for the file alchemyface-0.4.0.tar.gz.

File metadata

  • Download URL: alchemyface-0.4.0.tar.gz
  • Upload date:
  • Size: 45.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alchemyface-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9575ba749fc65714150229881c603a15461314a254fba23a0061c925d2799359
MD5 7d5963815692152a3e99f1bbeb30c521
BLAKE2b-256 8cd291bebcab831f2e66ca48f75b77d73c00fa8f43c509d5b04cc8a534659a9d

See more details on using hashes here.

File details

Details for the file alchemyface-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: alchemyface-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 49.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for alchemyface-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b774d75b0a44e2c338938597100d6d178a2cb64166cf2a026f586d965cec731
MD5 61eed64f6205582f8c26ba2bf029bac6
BLAKE2b-256 e25d47262f0c9a79e1bb87d8654630922f5ca196798f4328f886bbe49cbdbf7a

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.0

2 files

1.1.1

2 files

1.0.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page