Skip to main content

faceliveness

On-device face liveness checks for Python. The user is asked to do a few random actions (blink, turn left, turn right, open mouth) in front of the camera, and the check passes only if they do them in order. Face detection and landmarks run inside the package (MediaPipe's face models on a Rust core): no OpenCV, MediaPipe or cloud service needed.

pip install faceliveness

Python 3.9+, prebuilt for Linux (x86_64, aarch64), macOS (Intel, Apple Silicon) and Windows.

Quick start: webcam with OpenCV

import time

import cv2
import faceliveness

engine = faceliveness.Engine.random(3)  # e.g. ["turn_left", "blink", "open_mouth"]
camera = cv2.VideoCapture(0)
start = time.monotonic()

while True:
    ok, frame = camera.read()
    if not ok:
        break
    timestamp_ms = int((time.monotonic() - start) * 1000)
    result = engine.process(frame, timestamp_ms, format="bgr")  # OpenCV frames are BGR

    if result.done:
        print("liveness:", result.status, result.fail_reason or "")
        break
    print("please:", result.current_challenge, end="\r")

API

Engine(challenges, *, total_timeout_ms=30000, step_timeout_ms=10000, face_lost_ms=1000, min_real_score=None)

One liveness attempt. challenges is a list of "blink", "turn_left", "turn_right", "open_mouth". Engine.random(count) picks them in an unpredictable order (from OS randomness), which is what you want in production so attempts can't be pre-recorded. min_real_score fails a completed session whose mean real_score is below it; it's off by default, so calibrate it first (see Security notes).

engine.process(frame, timestamp_ms, *, format=None, rotation=0, mirrored=False) -> FrameResult

  • frame: uint8 array (height, width, 3) or (height, width, 4), e.g. from NumPy, OpenCV or numpy.asarray(pil_image). NV21 (Android) frames as (height * 3 // 2, width). Raw bytes work too with width=, height= and format=.
  • format: "rgb" (default for 3 channels), "bgr" (OpenCV), "rgba" (default for 4), "bgra" or "nv21".
  • rotation: clockwise degrees (0/90/180/270) that turn the frame upright, for phone cameras.
  • mirrored: True for selfie-preview frames, so "left" still means the user's left.

The Python GIL is released while a frame is processed, so other threads keep running.

FrameResult

Field
status "in_progress", "passed" or "failed"
done True once passed or failed (it won't change after that)
current_challenge, remaining what to ask the user for now, and how many are left
fail_reason "timeout", "step_timeout", "face_lost", "multiple_faces" or "spoof_suspected"
actions actions recognised in this frame
face_count, faces faces in view and their boxes
signals ear (eye openness), mouth (mouth openness), yaw (head turn)
landmarks 478 face-mesh points (x, y) of the main face
real_score passive anti-spoofing: 0-1 probability the face is real, not a photo or screen (measured on every 3rd frame with a face, otherwise empty)

Session(challenges, ...) and session.update(timestamp_ms, *, face_count=1, ear=, mouth=, yaw=)

The same challenge logic without image processing, for when you already compute face measurements yourself (for example with MediaPipe in a browser).

Server-side tickets and receipts

A result computed on the user's device can't be trusted. Run the engine on your server and let other services check a signed receipt:

key = faceliveness.SigningKey.generate()      # once; store key.to_bytes() as a secret
ticket = key.issue_ticket(count=3)            # signed JWT: random challenges, 2 min expiry

engine = faceliveness.Engine.from_ticket(ticket, key.public_key)
# ... engine.process(frame, ts) for each frame the client streams, until result.done ...
receipt = engine.receipt(key)                 # signed JWT with the outcome and a frame hash

# Any other service, with only the public key:
r = faceliveness.verify_receipt(receipt, key.public_key)
if r.passed and not already_used(r.nonce):    # accept each nonce once
    ...

Tickets and receipts are standard Ed25519 (EdDSA) JWTs, so any JWT library can verify them.

Face record for matching

Each session keeps its best face: the frame that is most frontal, eyes open, mouth closed, sharp, well lit and large enough, aligned to the standard 112x112 template most face-recognition models expect (ArcFace, SFace, MobileFaceNet...). Pass capture_size= for another size.

c = engine.capture                  # FaceCapture or None
c.png                               # aligned face as PNG bytes: store/send these exact bytes
c.quality                           # 0-1; below ~0.3 matching will be unreliable
np.frombuffer(c.rgb, np.uint8).reshape(c.size, c.size, 3)   # as a NumPy array

The signed receipt records face_sha256 (the PNG's hash) and face_quality, so liveness and the face record are one signed fact. In your face-matching service, accept a face only like this:

r = faceliveness.verify_face_record(receipt, public_key, face_png)
# raises unless: genuine and unexpired receipt, session passed, and face_png is the exact
# image the receipt vouches for. Then also reject a nonce you've seen before.

This stops someone from passing liveness with their own face and then submitting a photo of someone else for matching.

Security notes

  • Challenge-response stops printed photos (they can't blink, and tilting one doesn't count as a head turn) and makes pre-recorded video unlikely to match. It does not stop a live deepfake or an injected virtual camera.
  • real_score is uncalibrated for your cameras, so it is only reported by default. Record genuine and attack videos and run tools/calibrate_spoof.py before setting min_real_score.
  • Full details: threat model.

Develop

Requires Rust and uv. uv sync builds the extension.

uv sync
uv run pytest

License

Apache-2.0. Bundles MediaPipe face models (Apache-2.0); see models/README.md.

Metadata

Release files for faceliveness 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for faceliveness 0.1.0
File Size Uploaded Provenance Actions
faceliveness-0.1.0.tar.gz 6.6 MB With provenance Details for faceliveness-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for faceliveness 0.1.0
File Actions
faceliveness-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for faceliveness-0.1.0-cp39-abi3-win_amd64.whl
faceliveness-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for faceliveness-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
faceliveness-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for faceliveness-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
faceliveness-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for faceliveness-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
faceliveness-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for faceliveness-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 78.7 MB

Release files / faceliveness-0.1.0.tar.gz

Download URL faceliveness-0.1.0.tar.gz
Size 6.6 MB
Tags Source
SHA-256 checksum
How to use checksums
5ffac99221eab59c268df85b5908274bb5296834c5ab31c98daf6c0dc0b0a767
BLAKE2b-256 checksum
How to use checksums
52301ebf41c55930fee87d83021d50d11e29f476eac3f5edf2a2e379c4b800e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / faceliveness-0.1.0-cp39-abi3-win_amd64.whl

Download URL faceliveness-0.1.0-cp39-abi3-win_amd64.whl
Size 15.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d126e0391c697fe2590a3f42a2bf8a0fa384c690cf06868be1f25f9acd586b4c
BLAKE2b-256 checksum
How to use checksums
f5b491bffe17e108f1bc5f8516932006439a204ed788574423747448bce3855a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / faceliveness-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL faceliveness-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 14.9 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
ec29a17026b437876cb478758056b66f65706468a626d5f8d95f4c6a08fa9c2a
BLAKE2b-256 checksum
How to use checksums
b17ca620be9fe87838bb1d13a2da7b26af280466f5240c582eae3015767c691c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / faceliveness-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL faceliveness-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 13.8 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
007d0a207435fb0494ac1dc8e29493db859eb651c8592a79c4c3bfe4642cba52
BLAKE2b-256 checksum
How to use checksums
c5afe9f6287c97db860064aac08e37475f6c00ff433c77db623c0ba53aa640fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / faceliveness-0.1.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL faceliveness-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 13.5 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e20e42e781260fb4dce0c8f8d2ae4602e37881165ebe1a9ba96959e2031c1baa
BLAKE2b-256 checksum
How to use checksums
f6cb9a9d3b4f8f8fdcb4ad348375f53e843c14bd2734e18230c69aa2ed41f855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / faceliveness-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL faceliveness-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 14.5 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c1bedfc09d59664c23b24a52b14f817d87ec8b8ed75423ff0ed76b6c95b42687
BLAKE2b-256 checksum
How to use checksums
e20bbe519d549fb8cc17094d81469ed666fc04bb323d5c6a278e17382ecd7aa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for faceliveness 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for faceliveness-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files Full provenance

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