Overview
The ZKTeco Biometric Server is built on Flask and designed to provide REST API access to ZKTeco biometric devices. The architecture supports two distinct operational modes:Single-Device Mode
Direct connection to one biometric device with simple configuration
Multi-Device Mode
Dynamic management of multiple devices with persistence and parallel operations
Flask Application Structure
Both server implementations use Flask as the web framework with a consistent structure:source/servidor.py
Response Format
All endpoints use a consistent JSON response format:source/servidor.py
The
ensure_ascii=False parameter allows Unicode characters in responses, which is important for international names and locations.Threading Model and Concurrency
Single-Device Mode: Simple Lock
In single-device mode (servidor.py), a single threading lock protects all device operations:
source/servidor.py
- Only one request can communicate with the device at a time
- Prevents concurrent access issues and device communication errors
- Simple and sufficient for single-device scenarios
Multi-Device Mode: Per-Device Locks
The multi-device server (server.py) uses a more sophisticated locking strategy:
source/server.py
Registry Lock (devices_lock)
Protects read/write operations on the
DEVICES dictionary and devices.json file. Short-lived and only held during device registration/modification.Parallel Operations Example
The/attendance/all endpoint fetches attendance from all devices in parallel:
source/server.py
Device Connection Management
Connection Pattern
Both servers follow a strict connection lifecycle pattern:Connection Factory Functions
Single-Device Mode:source/servidor.py
source/server.py
Operating Modes Comparison
Single-Device Mode (servidor.py)
Single-Device Mode (servidor.py)
Use Case: Simple deployments with one biometric deviceConfiguration:
- Device IP/port set via environment variables
- No persistence layer required
- Direct connection on every request
- Simple setup and configuration
- Minimal resource overhead
- Easy to understand and debug
- Cannot manage multiple devices
- Configuration changes require server restart
- No device registry or metadata storage
Multi-Device Mode (server.py)
Multi-Device Mode (server.py)
Use Case: Enterprise deployments with multiple biometric devicesConfiguration:
- Devices registered via REST API
- Persistent storage in
devices.json - Each device can have unique settings
- Dynamic device registration without restart
- Parallel operations across devices
- Device metadata and lifecycle tracking
- Centralized management of multiple locations
- More sophisticated locking mechanism
- Persistent state management
- Additional CRUD endpoints for device management
Request Lifecycle
Here’s how a typical request flows through the multi-device server:Error Handling Strategy
The server implements comprehensive error handling:Logging Configuration
Both servers use Python’s standard logging with consistent formatting:source/server.py
Next Steps:
- Learn about Device Management to understand device registration and persistence
- Explore Authentication for SSL/TLS and password security
- See API Reference for complete endpoint documentation