Skip to main content

pyzkaccess-native logo

pyzkaccess-native

Talk to ZKTeco access-control devices from any OS, in pure Python. No DLL, no Windows, no ZKAccess.

PyPI Python Tests HACS License: MIT

ZKTeco panels and readers that are managed by ZKAccess (C3-100/200/400, inBio, MA500...) speak a binary TCP protocol. The only official way to use it is the PullSDK (plcommpro.dll), a 32-bit Windows DLL. This project reimplements that protocol from scratch, from captures of the DLL's own traffic, so you can:

  • read and manage users, RFID cards, PIN codes and fingerprint templates;
  • grant and revoke door access;
  • receive access events in real time (who opened which door, refused attempts...);
  • open doors, drive auxiliary outputs, set the clock, read and write parameters;
  • back up and restore a whole device, fingerprint templates included, byte for byte;

from Linux, macOS, Windows, a Raspberry Pi or a container, with no dependency at all.

It comes with:

🐍 Python library pip install pyzkaccess-native
💻 Command line tool zkaccess --host 192.168.1.201 users
🏠 Home Assistant integration installable from HACS, see below
🧪 Device emulator test your code without hardware
📖 Protocol documentation docs/PROTOCOL.md

Contents

Supported devices

Any device that ZKAccess / the PullSDK can manage should work, since they share the protocol.

Device Status
MA500 (fingerprint + RFID reader), firmware 6.64 ✅ tested (reboot and normal-open state excepted)
C3-100 / C3-200 / C3-400 🟡 expected to work (same protocol); please report
inBio 160/260/460 🟡 expected to work; please report
Push-protocol / "standalone attendance" devices (pyzk, port 4370 UDP) ❌ different protocol

If you try another model, please open an issue with the output of zkaccess info and zkaccess tables: it helps a lot.

Installation

pip install pyzkaccess-native

Python 3.10 or newer, no other dependency.

Quick start

from pyzkaccess_native import ZKAccess

with ZKAccess("192.168.1.201") as dev:          # password="..." if one is set
    info = dev.info()
    print(info.serial_number, info.firmware)

    for user in dev.get_users():
        print(user.pin, user.name, user.card_no)

    for event in dev.events():                  # Ctrl+C to stop
        print(event.time, event.pin, event.label, "granted" if event.granted else "")

From a shell:

zkaccess --host 192.168.1.201 info
zkaccess --host 192.168.1.201 events

Library guide

Connecting

from pyzkaccess_native import ZKAccess

dev = ZKAccess("192.168.1.201", port=4370, password="", timeout=5.0)
dev.connect()
...
dev.disconnect()

Or, better, with ZKAccess(...) as dev:. The client is thread-safe: requests from several threads are serialized on its session.

Device information, parameters and clock

info = dev.info()            # DeviceInfo(serial_number, firmware, lock_count, ...)
dev.get_params(["~SerialNumber", "Door1Drivertime", "MThreshold"])
dev.set_params({"Door1Drivertime": 5})

dev.get_time()               # naive datetime, device local time
dev.set_time()               # sync with this computer (or pass a datetime)

Users

from pyzkaccess_native import User

dev.get_users()                                  # list[User]
dev.get_user(105)                                # User | None

# Create, or update only the given fields (the others are kept):
dev.save_user(User(pin=105, name="Alice", card_no=12345678, password="1234"))
dev.save_user(User(pin=105, name="Alice Smith"))  # rename, card and password kept

dev.delete_user(105)       # also deletes its fingerprint templates and authorizations

User fields: pin, name, card_no, password, group, start_time, end_time, privilege, super_authorize, and uid (read-only, assigned by the device).

Door access

dev.grant(105)                               # time zone 1 ("always"), door 1
dev.grant(105, timezone_id=2, door_mask=0b0101)   # doors 1 and 3 during time zone 2
dev.get_authorizations(105)                  # list[Authorization]
dev.revoke(105)                              # remove all of them

A user can open a door only if they have an authorization for it and a credential (fingerprint, card or password).

Fingerprint templates

Fingerprints are enrolled on the device (keypad menu or ZKAccess with a USB reader). The library can copy, back up and restore the resulting templates:

from pyzkaccess_native import Template

templates = dev.get_templates()          # all of them (large transfer handled for you)
mine = dev.get_templates(pin=105)

# Copy a template to another device (the user must exist there):
other.save_user(User(pin=105, name="Alice"))
other.save_template(Template(pin=105, finger_id=0, template=mine[0].template))

dev.delete_templates(105)                # or delete_templates(105, finger_id=3)

save_template() refuses to write when another user has the same internal UID (see safety notes).

Real-time events

from pyzkaccess_native import AccessEvent, EventType

for ev in dev.events(interval=0.5):      # reconnects automatically
    if ev.granted:
        print(f"{ev.pin} opened door {ev.door} ({ev.label})")
    elif ev.event == EventType.UNREGISTERED_FINGERPRINT:
        print("unknown finger")

Or poll yourself: dev.poll() returns the records received since the previous call: AccessEvent objects, plus a DoorStatus (door sensors, alarms) on every call.

AccessEvent has event (an EventType, or a plain int for unlisted codes), pin, card, door, verify_mode, in_out, time, plus the helpers granted, denied and label.

Doors and outputs

dev.open_door(1, seconds=5)    # pulse the lock relay of door 1
dev.hold_door_open(1)          # until close_door()
dev.close_door(1)
dev.set_aux_output(1, 3)       # aux output 1 for 3 s (0 = off, 255 = on)
dev.cancel_alarm()
dev.restart()

Generic table access

Everything above is built on four generic calls. They work on any table the device reports (dev.tables()), with the device's own field names:

dev.read_table("transaction", where={"Pin": 105})          # list[dict]
dev.read_table("user", fields=["Pin", "Name"])
dev.write_records("timezone", [{"TimezoneId": 2, "MonTime1": ...}])
dev.delete_records("holiday", where={"Holiday": 20261225})
dev.count("user")

Backup and restore

from pyzkaccess_native import backup

snap = backup.backup(dev)             # users, templates, authorizations, time zones...
backup.save(snap, "device.json")

backup.restore(dev, backup.load("device.json"))             # merge
backup.restore(dev, backup.load("device.json"), wipe=True)  # exact copy

Discovery

from pyzkaccess_native import discover
discover()     # UDP broadcast; only finds devices on the same subnet

Errors

All exceptions derive from ZKError: ZKConnectionError (network), DeviceError (the device refused, .code = -14 for a wrong password...), ProtocolError (unexpected answer), SafetyError (refused by a safety check).

Command line tool

zkaccess [--host HOST] [--port 4370] [--password PWD] [-v|-vv] <command>

--host and --password can also come from ZKACCESS_HOST / ZKACCESS_PASSWORD.

Command Description
discover find devices on the local network
info serial number, firmware, doors, readers...
tables tables and fields supported by the device
params NAME... / NAME=VALUE... read / write parameters
time [--set [ISO date]] read, or set the clock (default: now)
users [--json] list users
user-set PIN [--name] [--card] [--user-password] create or update a user
user-delete PIN [--yes] delete a user, its templates and authorizations
grant PIN [--timezone 1] [--doors 1] / revoke PIN door access
read TABLE [--where F=V] [--fields a,b] [--json] dump any table
count TABLE number of records
events [--status] [--json] live events, Ctrl+C to stop
door open|close|hold [--door 1] [--seconds 5] drive a lock relay
aux OUTPUT SECONDS drive an auxiliary output
backup FILE [--logs] / restore FILE [--wipe] [--yes] full backup / restore
cancel-alarm, restart

-vv prints every frame in hex, handy for protocol work. python -m pyzkaccess_native works too.

Example:

$ export ZKACCESS_HOST=192.168.1.201
$ zkaccess users
Pin  Name   CardNo    Password  Group  StartTime  EndTime  Privilege  SuperAuthorize  UID
101  Alice  12345678            0      0          0        0          0               1
$ zkaccess events
2026-11-21 08:02:11  door 1  pin 101    card 0          14 Fingerprint open
2026-11-21 08:05:40  door 1  pin 0      card 0          34 Unregistered fingerprint

Home Assistant integration

The repository is also a HACS custom integration built on the library.

Install

  1. HACS → ⋮ → Custom repositories → add https://github.com/Avataar120/pyzkaccess, type Integration.
  2. Install ZKAccess Native and restart Home Assistant.
  3. Settings → Devices & services → Add integration → ZKAccess Native, enter the IP address (and the communication password, if any).

What you get

Entity Description
event.<device>_access fires granted, denied or other with pin, card, door, event, event_name, verify_mode, time
binary_sensor.<device>_door_N door contact (unknown when no sensor is wired)
binary_sensor.<device>_door_N_alarm alarm / door open too long
sensor.<device>_last_user PIN of the last granted user
sensor.<device>_users, _fingerprint_templates counters
button.<device>_open_door_N pulse the lock relay
button.<device>_sync_clock set the device clock

Every access event is also fired on the bus as zkaccess_native_access with the same data plus device_id.

Services: zkaccess_native.set_user, delete_user, grant, revoke, open_door, sync_clock, list_users (returns the users) and backup (writes a JSON file in /config/zkaccess_native/).

Options: polling interval (default 1 s), door open duration, clock sync on connection.

Example automations

Turn on the hall light when a known user opens the door at night:

automation:
  - alias: "Front door - welcome light"
    triggers:
      - trigger: state
        entity_id: event.front_door_access
        to: ~
    conditions:
      - condition: template
        value_template: "{{ trigger.to_state.attributes.event_type == 'granted' }}"
      - condition: sun
        after: sunset
    actions:
      - action: light.turn_on
        target:
          entity_id: light.hall

Different action per user, with the bus event:

automation:
  - alias: "Front door - per user"
    triggers:
      - trigger: event
        event_type: zkaccess_native_access
        event_data:
          granted: true
    actions:
      - choose:
          - conditions: "{{ trigger.event.data.pin == 101 }}"
            sequence:
              - action: notify.mobile_app_phone
                data:
                  message: "Alice is home"

Notify on refused attempts:

automation:
  - alias: "Front door - refused"
    triggers:
      - trigger: event
        event_type: zkaccess_native_access
        event_data:
          denied: true
    actions:
      - action: notify.mobile_app_phone
        data:
          message: "Refused at the front door: {{ trigger.event.data.event_name }}"

More in examples/.

Safety notes (read this)

Lessons learned the hard way while reverse-engineering. The library protects you against each of them, but you should know them:

  1. Writing a user replaces the whole record. Sending only a new name erases the password and the card number. → save_user() reads the record and merges first.
  2. Deleting without a condition erases the whole table. → delete_records() refuses unless you pass allow_wipe=True.
  3. Some firmware give a new user a UID that another user already has. Templates are bound to the UID, so a template written then could identify the wrong person. → save_template() checks for duplicates and refuses.
  4. Deleting a user does not delete its templates or its door rights. → delete_user() cascades by default.
  5. ZKAccess "Add device" with "Clear data in device" checked erases the device, even when it then fails with "Unknown Device Model". Back up first (zkaccess backup device.json).
  6. ZKAccess does not read door authorizations from the device: syncing its database back to the device can leave users without access.
  7. Events are delivered to every open session: if two programs act on events, both will act. Do not manage a device from ZKAccess and this library at the same time.

Testing without hardware

An emulator speaking the same protocol is included:

python -m pyzkaccess_native.emulator --port 4370 &
zkaccess --host 127.0.0.1 user-set 1 --name Test
zkaccess --host 127.0.0.1 users

In tests:

from pyzkaccess_native import ZKAccess
from pyzkaccess_native.emulator import Emulator

def test_something():
    with Emulator() as emu, ZKAccess("127.0.0.1", emu.port) as dev:
        emu.state.push_event(14, pin=1)        # simulate a fingerprint
        assert dev.poll()[0].pin == 1

The emulator reproduces the behaviour observed on real devices (whole-record writes, device-assigned UIDs, buffered transfers...), but the real device remains the reference.

Troubleshooting

Symptom Cause / fix
cannot connect / timeout wrong IP, device on another VLAN without routing, firewall, or a firmware that accepts a single session while another program is connected.
device error -14 wrong communication password (ComPwd).
device error -13 command not supported by this firmware.
no event received check the polling loop is running; time zone / authorization of the user (event 23 = access denied).
discover() finds nothing broadcasts do not cross routers; connect by IP.
clock drifts call set_time() daily (the integration does it on each connection).

Run with -vv (CLI) or logging.getLogger("pyzkaccess_native").setLevel("DEBUG") to see every frame.

Contributing

Issues and pull requests are welcome, especially:

  • reports from other devices (zkaccess info, zkaccess tables);
  • captures of PullSDK calls that are not documented yet (see the open questions at the end of docs/PROTOCOL.md).
git clone https://github.com/Avataar120/pyzkaccess && cd pyzkaccess
pip install -e ".[test]"
pytest

Please never attach real fingerprint templates, passwords or card numbers to an issue.

Releasing (maintainers)

  1. Bump the version in src/pyzkaccess_native/__init__.py, and both version and the pyzkaccess-native== requirement in custom_components/zkaccess_native/manifest.json.
  2. Update CHANGELOG.md, commit, then create a GitHub release with tag vX.Y.Z.
  3. The Publish to PyPI workflow builds and uploads the package (PyPI trusted publishing, environment pypi; no token in the repository). HACS picks up the release.

This is an independent project, not affiliated with or endorsed by ZKTeco. "ZKTeco" and "ZKAccess" are trademarks of their owners. The protocol was documented by observing the network traffic of software and devices legitimately owned by the author, for interoperability purposes. Released under the MIT license.

Metadata

Release files for pyzkaccess-native 0.1.1

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

Source distribution (sdist)

Source distribution for pyzkaccess-native 0.1.1
File Size Uploaded Provenance Actions
pyzkaccess_native-0.1.1.tar.gz 39.5 kB With provenance Details for pyzkaccess_native-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyzkaccess-native 0.1.1
File Interpreter ABI Platform Actions
pyzkaccess_native-0.1.1-py3-none-any.whl Python 3 none any Details for pyzkaccess_native-0.1.1-py3-none-any.whl

Total release size: 76.7 kB

Release files / pyzkaccess_native-0.1.1.tar.gz

Download URL pyzkaccess_native-0.1.1.tar.gz
Size 39.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fbf821a9beb56e83a65d62a66de8b081f06a8357befce953ef333d19c08e8ac1
BLAKE2b-256 checksum
How to use checksums
efaa2cfde295f1f1feae4356cef04b6d2325d44953b75961fbb287c6c9ebdb48
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 22, 2026.

Transparency log

Release files / pyzkaccess_native-0.1.1-py3-none-any.whl

Download URL pyzkaccess_native-0.1.1-py3-none-any.whl
Size 37.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a0389d7ddae44a876d0c5180ec9fa2138c57b58cf0409261ef0f982bd40d98ee
BLAKE2b-256 checksum
How to use checksums
875a718b52590ed6f4d90822977b27b34d1a85c6a98a0a2f207985efc183b4f7
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 22, 2026.

Transparency log

Security for pyzkaccess-native 0.1.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyzkaccess_native-0.1.1.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 22, 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.

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