How to using Zklib

I am developing a finger authentication attendance app in ERPNext using zklib.
Can someone help me how to using zklib library.

1 Like

I am new in erpnext.
where can but this script ,in windows or inside erpnext?

@zaidali install this software on a local server that has direct access to the biometric system

see Installing as a Windows service section:

1 Like

@Mohammed_Redha
thank you brother ,
I install biometric-attendance-sync-tool on windows,but erpnext in another server ,how to access to erpnext

If you followed the guide then it should connect to your ERPNext instance no matter the location as the process is outlined in the implementation guide.

@zaidali As mentioned by @flexy2ky you have to check the Setting up config section

@flexy2ky After setting up config ,I executed using py erpnext_sync.py
display this error.

2021-07-12 16:03:36,961 ERROR 192.168.40.55 exception when fetching from device…
Traceback (most recent call last):
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 248, in __send_command
self.__sock.send(top)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “erpnext_sync.py”, line 138, in get_all_attendance_from_device
conn = zk.connect()
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 373, in connect
cmd_response = self.__send_command(const.CMD_CONNECT)
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 260, in __send_command
raise ZKNetworkError(str(e))
zk.exception.ZKNetworkError: timed out
2021-07-12 16:03:36,965 ERROR exception when calling pull_process_and_push_data function for device{“device_id”: “test_1”, “ip”: “192.168.40.55”, “punch_direction”: null, “clear_from_device_on_fetch”: false}
Traceback (most recent call last):
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 248, in __send_command
self.__sock.send(top)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “erpnext_sync.py”, line 138, in get_all_attendance_from_device
conn = zk.connect()
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 373, in connect
cmd_response = self.__send_command(const.CMD_CONNECT)
File “C:\Users\Zaid.Melahi\Desktop\biometric-attendance-sync-tool-master\venv\lib\site-packages\pyzk-0.9-py3.7.egg\zk\base.py”, line 260, in __send_command
raise ZKNetworkError(str(e))
zk.exception.ZKNetworkError: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “erpnext_sync.py”, line 51, in main
pull_process_and_push_data(device, device_attendance_logs)
File “erpnext_sync.py”, line 78, in pull_process_and_push_data
device_attendance_logs = get_all_attendance_from_device(device[‘ip’], device_id=device[‘device_id’], clear_from_device_on_fetch=device[‘clear_from_device_on_fetch’])
File “erpnext_sync.py”, line 159, in get_all_attendance_from_device
raise Exception(‘Device fetch failed.’)
Exception: Device fetch failed.

What’s your device model?

Can you paste your config here? you can leave out the url, secret and key

@flexy2ky
fingerTec TA200 plus

ERPNext related configs

ERPNEXT_API_KEY = ‘’
ERPNEXT_API_SECRET = ‘’
ERPNEXT_URL = ‘’

operational configs

PULL_FREQUENCY = 60 # in minutes
LOGS_DIRECTORY = ‘logs’ # logs of this script is stored in this directory
IMPORT_START_DATE = 20210710 # format: ‘20190501’

Biometric device configs (all keys mandatory)

#- device_id - must be unique, strictly alphanumerical chars only. no space allowed.
#- ip - device IP Address
#- punch_direction - 'IN'/'OUT'/'AUTO'/None
#- clear_from_device_on_fetch: if set to true then attendance is deleted after fetch is successful.
                                #(Caution: this feature can lead to data loss if used carelessly.)

devices = [
{‘device_id’:‘test_1’,‘ip’:‘192.168.40.55’, ‘punch_direction’: ‘AUTO’, ‘clear_from_device_on_fetch’: False},
#{‘device_id’:‘test_2’,‘ip’:‘192.168.40.55’, ‘punch_direction’: None, ‘clear_from_device_on_fetch’: False}
]

Configs updating sync timestamp in the Shift Type DocType

shift_type_device_mapping = [
{‘shift_type_name’: [‘Shift1’], ‘related_device_id’: [‘test_1’]}
]

Your device is not compatible. Only ZKTeco devices can be used with zklib.

l’m using pyzk packages that is required inside requirements file in [frappe/biometric-attendance-sync-tool] .

what is the different between zklib and pyzk?

yesterday i did pull the data from biomtric device but now can not connect with it !
what is the problem?and how solve it?

Both of them are the same essentially. pyzk I the unofficial library (tweaked) while zklib is the official nodejs library developed for biometric data collection.

Now this is surprising because the library is only compatible with zkteco devices. Maybe there’s some sort of similarities with the sdk used to develop the device you’re using but the fact that it failed later suggests there’s inconsistencies somewhere. Even with ZKTeco devices, not all of them are supported (I learnt this the hard way) so basically if you want this biometric attendance system to work for you then you have to check device compatibility. If you check the pyzk package repo in the url below you will see the list of tested and compatible devices. Although the list is not exhaustive but the firmware and platform version indicates what devices will ultimately be compatible. That should guide you going forward.

Hope this helps

Thank you so much for help me.:pray:
What do you recommend me?
How can connect my device with erpnext?

It’s rare to see a post about zklib. Can you ask me some questions? I want to receive data directly when scanning on the device and transmit it to the server, how do I do that?