Package: pyozk
pyzkpyzkis an unofficial library of zksoftware (zkteco family) attendance machine.InstallationThere is some installation method you can use below:pippipinstall-Upyzkmanual installation (clone and execute)pythonsetup.pyinstallclone and append the path of this projectimportsysimportossys.path.insert(1,os.path.abspath("./pyzk"))fromzkimportZK,constDocumentationComplete documentation can be found atReadthedocs.API UsageCreate the ZK object and you will be ready to call api.Basic UsageThe following is an example code block how to use pyzk.fromzkimportZK,constconn=None# create ZK instancezk=ZK('192.168.1.201',port=4370,timeout=5,password=0,force_udp=False,ommit_ping=False)try:# connect to deviceconn=zk.connect()# disable device, this method ensures no activity on the device while the process is runconn.disable_device()# another commands will be here!# Example: Get All Usersusers=conn.get_users()foruserinusers:privilege='User'ifuser.privilege==const.USER_ADMIN:privilege='Admin'print('+ UID #{}'.format(user.uid))print('  Name       :{}'.format(user.name))print('  Privilege  :{}'.format(privilege))print('  Password   :{}'.format(user.password))print('  Group ID   :{}'.format(user.group_id))print('  User  ID   :{}'.format(user.user_id))# Test Voice: Say Thank Youconn.test_voice()# re-enable device after all commands already executedconn.enable_device()exceptExceptionase:print("Process terminate :{}".format(e))finally:ifconn:conn.disconnect()Command ListConnect/Disconnectconn=zk.connect()conn.disconnect()Disable/Enable Connected Device# disable (lock) device, to ensure no user activity in device while some process runconn.disable_device()# re-enable the connected device and allow user activity in device againconn.enable_device()Get and Set Timefromdatetimeimportdatetime# get current machine's timezktime=conn.get_time()printzktime# update new time to machinenewtime=datetime.today()conn.set_time(newtime)Get Firmware Version and Extra Informationconn.get_firmware_version()conn.get_serialnumber()conn.get_platform()conn.get_device_name()conn.get_face_version()conn.get_fp_version()conn.get_extend_fmt()conn.get_user_extend_fmt()conn.get_face_fun_on()conn.get_compat_old_firmware()conn.get_network_params()conn.get_mac()conn.get_pin_width()Get Device Usage Spaceconn.read_sizes()print(conn)#also:conn.usersconn.fingersconn.recordsconn.users_capconn.fingers_cap# TODO: add records_cap counter# conn.records_capUser Operation# Create userconn.set_user(uid=1,name='Fanani M. Ihsan',privilege=const.USER_ADMIN,password='12345678',group_id='',user_id='123',card=0)# Get all users (will return list of User object)users=conn.get_users()# Delete Userconn.delete_user(uid=1)conn.delete_user(user_id=123)Fingerprints# Get  a single Fingerprint (will return a Finger object)template=conn.get_user_template(uid=1,temp_id=0)#temp_id is the finger to read 0~9# Get all fingers from DB (will return a list of Finger objects)fingers=conn.get_templates()# to restore a finger, we need to assemble with the corresponding user# pass a User object and a list of finger (max 10) to saveconn.save_user_template(user,[fing1,fing2])Remote Fingerprint Enrollmentzk.enroll_user('1')# but it doesn't work with some tcp ZK8 devicesAttendance Record# Get attendances (will return list of Attendance object)attendances=conn.get_attendance()sorted_attendances=conn.get_sorted_attendance(by_date=False)# means sorting by uidlimited_attendances=conn.get_limited_attendance(users=[1,2],# only UIDs 1, 2start=datetime(2022,1,10,12,42),# from 2022,1,10 12:42:00end=datetime(2022,1,11)# to 2022,1,11)# Clear attendances recordsconn.clear_attendance()User history# Get the history of users recordshist=conn.get_user_history(users=[1,2],start_date=datetime(2022,1,10,12,42))Test voice"""play test voice:0 Thank You1 Incorrect Password2 Access Denied3 Invalid ID4 Please try again5 Dupicate ID6 The clock is flow7 The clock is full8 Duplicate finger9 Duplicated punch10 Beep kuko11 Beep siren12 -13 Beep bell14 -15 -16 -17 -18 Windows(R) opening sound19 -20 Fingerprint not emolt21 Password not emolt22 Badges not emolt23 Face not emolt24 Beep standard25 -26 -27 -28 -29 -30 Invalid user31 Invalid time period32 Invalid combination33 Illegal Access34 Disk space full35 Duplicate fingerprint36 Fingerprint not registered37 -38 -39 -40 -41 -42 -43 -43 -45 -46 -47 -48 -49 -50 -51 Focus eyes on the green box52 -53 -54 -55 -"""conn.test_voice(index=0)# will say 'Thank You'Device Maintenance# DANGER!!! This command will be erase all data in the device (incuded: user, attendance report, and finger database)conn.clear_data()# shutdown connected deviceconn.poweroff()# restart connected deviceconn.restart()# clear bufferconn.free_data()Live Capture!# live capture! (timeout at 10s)forattendanceinconn.live_capture():ifattendanceisNone:# implement here timeout logicpasselse:print(attendance)# Attendance object#if you need to break gracefully just set#   conn.end_live_capture = True## On interactive mode,# use Ctrl+C to break gracefully# this way it restores timeout# and disables live captureTest Machineusage:./test_machine.py[-h][-aADDRESS][-pPORT][-TTIMEOUT][-PPASSWORD][-f][-t][-r][-u][-l][-DDELETEUSER][-AADDUSER][-EENROLLUSER][-FFINGER]ZKBasicReadingTests

optionalarguments:-h,--helpshowthishelpmessageandexit-aADDRESS,--addressADDRESSZKdeviceAddress[192.168.1.201]-pPORT,--portPORTZKdeviceport[4370]-TTIMEOUT,--timeoutTIMEOUTDefault[10]seconds(0:disabletimeout)-PPASSWORD,--passwordPASSWORDDevicecode/password-b,--basicgetBasicInformationonly.(nobulkread,ie:users)-f,--force-udpForceUDPcommunication-v,--verbosePrintdebuginformation-t,--templatesGettemplates/fingers(comparebulkandsingleread)-tr,--templates-rawGetrawtemplates(dumptemplates)-r,--recordsGetattendancerecords-u,--updatetimeUpdateDate/Time-l,--live-captureLiveEventCapture-o,--open-doorOpendoor-DDELETEUSER,--deleteuserDELETEUSERDeleteaUser(uid)-AADDUSER,--adduserADDUSERAddaUser(uid)(andenroll)-EENROLLUSER,--enrolluserENROLLUSEREnrollaUser(uid)-FFINGER,--fingerFINGERFingerforenroll(fid=0)Backup/Restore (Users and fingers only!!!)(WARNING! destructive test! do it at your own risk!)usage:./test_backup_restore.py[-h][-aADDRESS][-pPORT][-TTIMEOUT][-PPASSWORD][-f][-v][-r][filename]ZKBasicBackup/RestoreTool

positionalarguments:filenamebackupfilename(default[serialnumber].bak)optionalarguments:-h,--helpshowthishelpmessageandexit-aADDRESS,--addressADDRESSZKdeviceAddress[192.168.1.201]-pPORT,--portPORTZKdeviceport[4370]-TTIMEOUT,--timeoutTIMEOUTDefault[10]seconds(0:disabletimeout)-PPASSWORD,--passwordPASSWORDDevicecode/password-f,--force-udpForceUDPcommunication-v,--verbosePrintdebuginformation-E,--erasecleanthedeviceafterwrittingbackup!-r,--restoreRestorefrombackup-c,--clear-attendanceOnRestore,alsoclearstheattendance[defaultkeepattendance]To restore on a different device, make sure to specify thefilename. on restoring, it asks for the serial number of the destination device (to make sure it was correct, as it deletes all data) WARNING. there is no way to restore attendance data, you can keep it or clear it, but once cleared, there is no way to restore it.Compatible devicesFirmware Version : Ver 6.21 Nov 19 2008
Platform : ZEM500
DeviceName : U580

Firmware Version : Ver 6.60 Apr 9 2010
Platform : ZEM510_TFT
DeviceName : T4-C

Firmware Version : Ver 6.60 Dec 1 2010
Platform : ZEM510_TFT
DeviceName : T4-C

Firmware Version : Ver 6.60 Mar 18 2011
Platform : ZEM600_TFT
DeviceName : iClock260

Platform         : ZEM560_TFT
Firmware Version : Ver 6.60 Feb  4 2012
DeviceName       :

Firmware Version : Ver 6.60 Oct 29 2012
Platform : ZEM800_TFT
DeviceName : iFace402/ID

Firmware Version : Ver 6.60 Mar 18 2013
Platform : ZEM560
DeviceName : MA300

Firmware Version : Ver 6.60 Dec 27 2014
Platform : ZEM600_TFT
DeviceName : iFace800/ID

Firmware Version : Ver 6.60 Nov 6 2017 (remote tested with correct results)
Platform : ZMM220_TFT
DeviceName : (unknown device) (broken info but at least the important data was read)

Firmware Version : Ver 6.60 Jun 9 2017
Platform : JZ4725_TFT
DeviceName : K20 (latest checked correctly!)

Firmware Version : Ver 6.60 Aug 23 2014 
Platform : ZEM600_TFT
DeviceName : VF680 (face device only, but we read the user and attendance list!)

Firmware Version : Ver 6.70 Feb 16 2017
Platform : ZLM30_TFT
DeviceName : RSP10k1 (latest checked correctly!)

Firmware Version : Ver 6.60 Jun 16 2015
Platform : JZ4725_TFT
DeviceName : K14 (tested & verified working as expected.)

Firmware Version : Ver 6.60 Jan 13 2016
Platform         : ZMM220_TFT
DeviceName       : iFace702 (without voice function, test with encoding='gbk')Latest tested (not really confirmed)Firmware Version : Ver 6.60 Jun 16 2015
Platform : JZ4725_TFT
DeviceName : iClock260

Firmware Version : Ver 6.60 Jun 5 2015
Platform : ZMM200_TFT
DeviceName : iClock3000/ID (Active testing! latest fix)

Firmware Version : Ver 6.70 Jul 12 2013
Platform : ZEM600_TFT
DeviceName : iClock880-H/ID (Active testing! latest fix)Not Working (needs more tests, more information)Firmware Version : Ver 6.4.1 (build 99) (display version 2012-08-31)
Platform : 
DeviceName : iClock260 (no capture data - probably similar problem as the latest TESTED)If you have another version tested and it worked, please inform me to update this list!TodoCreate better documentationFinger template downloader & uploaderHTTP Rest apiCreate real time api (if possible)and much more ...Publishhttps://packaging.python.org/en/latest/tutorials/packaging-projects/