4

Where can I find a Python wrapper for libprint? If such wrapper does not exist, is it possible to write one? How can I get started?

martincho
  • 4,517
  • 7
  • 32
  • 42
  • This might help - http://stackoverflow.com/questions/1942298/wrapping-a-c-library-in-python-c-cython-or-ctypes – arunkumar Sep 01 '11 at 03:03
  • Do you mean this [libfprint](http://www.freedesktop.org/wiki/Software/fprint) library? – plaes Sep 01 '11 at 05:16
  • @martincho : Have you done this. I am also want to do the same thing. I hope you can help me. – Sakeer Jun 06 '17 at 11:57
  • @Kukku: this was a long time ago unfortunately. I don't remember very well. Take a look at the second answer of this question. You can always write a small executable in C++ and call it from Python with popen. – martincho Jun 06 '17 at 20:17

3 Answers3

6

As libfprint (I hope it is the project you are looking for) is using GLib, you might want to look into GObject Introspection.

plaes
  • 31,788
  • 11
  • 91
  • 89
5

I also made a lot of search for this, and I did learn a lot of C/C++ while trying to use libfprint as it is, but someday, out of nowhere, I saw a question some guy posted here and voilà:

https://github.com/luksan/pyfprint

Community
  • 1
  • 1
fiatjaf
  • 11,479
  • 5
  • 56
  • 72
  • 1
    pyfprint has problems in its implementation of identification of fingers (scanned finger versus gallery of stored fingerprints), so I decided to tweak the C API anyway. Maybe someday, with a bit of luck, I'll released a full-fledged all-working Python module for libfprint. – fiatjaf Nov 11 '12 at 15:58
  • is this tested one?. I was searching for the same. – Sakeer Jun 06 '17 at 12:08
  • It has been update recently, @Kukku, after many years, and it is now compatible with Python3. I didn't test it after the update, but it seems solid. – fiatjaf Jun 06 '17 at 14:15
2

As said in the @plaes's answer it's possible to use libfprint (or libfprint-2) from Python with GObject Introspection (GI).

You should have the correct packages installed. In Ubuntu 20.04, I installed python3-gi:

sudo apt install python3-gi

And then you can use the library like this from the python3 shell:

import gi
gi.require_version('FPrint', '2.0')
from gi.repository import FPrint, GLib

dir(FPrint)

In the dir result you'll see the exported names available. Refer to libfprint API documentation for usage: https://fprint.freedesktop.org/libfprint-dev/

Here's a simple example to get started:

ctx = FPrint.Context()
devices = ctx.get_devices()
print([dev.get_name() for dev in devices])

Note that there is also a D-Bus API available to fprintd: https://fprint.freedesktop.org/fprintd-dev/ref-dbus.html

Tuomas
  • 515
  • 5
  • 11