Package: libusb1
ContentsDependenciesSupported OSesInstallationWindows installation notesChecking release file signatureUsageDocumentationHistory0.0.10.1.10.1.20.1.30.2.00.2.10.2.20.2.31.0.01.1.01.2.01.3.01.3.11.3.21.4.01.4.11.5.01.5.11.5.21.5.31.61.6.11.6.21.6.31.6.41.6.51.6.61.6.71.71.7.11.81.8.11.91.9.11.9.21.9.31.10.1 (yanked)2.0.02.0.13.0.0unreleasedSupports all transfer types, both in synchronous and asynchronous mode.Home:http://github.com/vpelletier/python-libusb1PyPI:http://pypi.python.org/pypi/libusb1DependenciesCPython3.6+,pypy2.0+. Older versions may work, but are not
recommended as there is no automated regression testing set up for them.libusb-1.0Supported OSespython-libusb1 can be expected to work on:GNU/LinuxWindows[1]native dll or viaCygwinOSX[2]viaMacPorts,FinkorHomebrewFreeBSD (including Debian GNU/kFreeBSD)OpenBSD[1]Beware of libusb-win32, which implements 0.1 API, not 1.0 .[2]Beware of possible lack of select.poll if you want to use asynchronous
API.InstallationReleases from PyPI, with namelibusb1. Installing from command line:$ pip install libusb1Latest version from source tree:$ git clone https://github.com/vpelletier/python-libusb1.git
$ cd python-libusb1
$ pip install .Windows installation notesOn Windows, installing wheels from pypi also installs the libusb dll within the
usb1 python module. It does not install any driver, so you still need to decide
which of libusbk or WinUSB to use for each device and install it appropriately
(possibly usingZadig, or by providing a driver for your users to install).Installing from source tree does not install the dll, so you need to install the
library where ctypes can find it - and of course the driver as well.Checking release file signaturepipy releases are signed. To verify the signature:download the release file, note its URLdownload its detached signature by adding.ascat the end of the release
file URLadd the release key(s) to a gnupg keyring (KEYSfile in the home
repository), and use gnupg to validate the signature both corresponds to the
distribution file and is trusted by your keyringinstall the already-fetched release fileUsageFinding a device and gaining exclusive access:importusb1withusb1.USBContext()ascontext:handle=context.openByVendorIDAndProductID(VENDOR_ID,PRODUCT_ID,skip_on_error=True,)ifhandleisNone:# Device not present, or user is not allowed to access device.withhandle.claimInterface(INTERFACE):# Do stuff with endpoints on claimed interface.Synchronous I/O:whileTrue:data=handle.bulkRead(ENDPOINT,BUFFER_SIZE)# Process data...Asynchronous I/O, with more error handling:defprocessReceivedData(transfer):iftransfer.getStatus()!=usb1.TRANSFER_COMPLETED:# Transfer did not complete successfully, there is no data to read.# This example does not resubmit transfers on errors. You may want# to resubmit in some cases (timeout, ...).returndata=transfer.getBuffer()[:transfer.getActualLength()]# Process data...# Resubmit transfer once data is processed.transfer.submit()# Build a list of transfer objects and submit them to prime the pump.transfer_list=[]for_inrange(TRANSFER_COUNT):transfer=handle.getTransfer()transfer.setBulk(usb1.ENDPOINT_IN|ENDPOINT,BUFFER_SIZE,callback=processReceivedData,)transfer.submit()transfer_list.append(transfer)# Loop as long as there is at least one submitted transfer.whileany(x.isSubmitted()forxintransfer_list):try:context.handleEvents()exceptusb1.USBErrorInterrupted:passFor more, see theexampledirectory.Documentationpython-libusb1 main documentation is accessible with python’s standardpydoccommand.python-libusb1 follows libusb-1.0 documentation as closely as possible, without
taking decisions for you. Thanks to this, python-libusb1 does not need to
duplicate the nice existinglibusb1.0 documentation.Some description is needed though on how to jump from libusb-1.0 documentation
to python-libusb1, and vice-versa:usb1module groups libusb-1.0 functions as class methods. The first
parameter (when it’s alibusb_...pointer) defined the class the function
belongs to. For example:intlibusb_init(libusb_context**context)becomes USBContext class
constructor,USBContext.__init__(self)ssize_tlibusb_get_device_list(libusb_context*ctx,libusb_device***list)becomes an USBContext method, returning a
list of USBDevice instances,USBDevice.getDeviceList(self)uint8_tlibusb_get_bus_number(libusb_device*dev)becomes an
USBDevice method,USBDevice.getBusNumber(self)Error statuses are converted intousb1.USBErrorexceptions, with
status asvalueinstance property.usb1module also defines a few more functions and classes, which are
otherwise not so convenient to call from Python: the event handling API needed
by async API.History0.0.1Initial release0.1.1Massive rework of usb1.py, making it more python-ish and fixing some
memory leaks.0.1.2Deprecate “transfer” constructor parameter to allow instance reuse.0.1.3Some work on isochronous “in” transfers. They don’t raise exceptions anymore,
but data validity and python-induced latency impact weren’t properly checked.0.2.0Fix asynchronous configuration transfers.Stand-alone polling thread for multi-threaded apps.More libusb methods exposed on objects, including ones not yet part of
released libusb versions (up to their commit 4630fc2).2to3 friendly.Drop deprecated USBDevice.reprConfigurations method.0.2.1Add FreeBSD support.0.2.2Add Cygwin support.OpenBSD support checked (no change).0.2.3Add fink and homebrew support on OSX.Drop PATH_MAX definition.Try harder when looking for libusb.1.0.0Fix FreeBSD ABI compatibility.Easier to list connected devices.Easier to terminate all async transfers for clean exit.Fix few segfault causes.pypy support.1.1.0Descriptor walk API documented.Version and capability APIs exposed.Some portability fixes (OSes, python versions).Isochronous transfer refuses to round transfer size.Better exception handling in enumeration.Add examples.Better documentation.1.2.0Wrap hotplug API.Wrap port number API.Wrap kernel auto-detach API.Drop wrapper for libusb_strerror, with compatibility place-holder.Add a few new upstream enum values.1.3.0Backward-incompatible change: Enum class now affects caller’s local scope,
not its global scope. This should not be of much importance, as:This class is probably very little used outside libusb1.pyThis class is probably mostly used at module level, where locals == globals.It is possible to get former behaviour by providing the newscope_dictparameter toEnumconstructor:SOME_ENUM = libusb1.Enum({...}, scope_dict=globals())Improve start-up time on CPython by not importing standardinspectmodule.Fix some more USBTransfer memory leaks.Add Transfer.iterISO for more efficient isochronous reception.1.3.1Fixed USBContext.waitForEvent.Fix typo in USBInterfaceSetting.getClassTuple method name. Backward
compatibility preserved.Remove globals accesses from USBDeviceHandle destructor.Assorted documentation improvements.1.3.2Made USBDevice instances hashable.Relaxed licensing by moving from GPL v2+ to LGPL v2.1+, for consistency with
libusb1.1.4.0Reduce (remove ?) the need to import libusb1 module by exposing USBError and
constants in usb1 module.Fix libusb1.LIBUSB_ENDPOINT_ENDPOINT_MASK and
libusb1.LIBUSB_ENDPOINT_DIR_MASK naming.Fix pydoc appearance of several USBContext methods.Define exception classes for each error values.1.4.1Fix wheel generation (python3 setup.py bdist_wheel).1.5.0controlWrite, bulkWrite and interruptWrite now reject (with TypeError) numeric
values fordataparameter.Fix libusb1.REQUEST_TYPE_* names (were TYPE_*). Preserve backward
compatibility.Add USBContext.getDeviceIterator method.Rename USBContext.exit as USBContext.close for consistency with other USB*
classes. Preserve backward compatibility.Make USBDeviceHandle.claimInterface a context manager, for easier interface
releasing.1.5.1Introduce USBPollerThread.stop .Fix USBDeviceHandle.getSupportedLanguageList bug when running under python 3.
While fixing this bug it was realised that this method returned ctypes objects.
This was not intended, and it now returns regular integers.1.5.2Make USBTransfer.cancel raise specific error instances.1.5.3Fix USBTransfer.cancel exception raising introduced in 1.5.2: it was
accidentally becomming a bound method, preventing the raise to actually
happen (in at least CPython 2.x) or raising type conversion errors (in at least
CPython 3.5.2).1.6Improve asynchronous transfer performance: (very) suboptimal code was used to
initialise asynchronous transfer buffer. As a consequence, usb1 now exposesbytearrayswhere it used to exposebytesorstrobjects.Deprecate libusb1 module import, which should not be needed since all (?)
needed constants were re-bound to usb1 module.Move testUSB1 module inside usb1, to eventually only expose usb1 as top-level
module.1.6.1Fix getSupportedLanguageList.Fix and extend get{,ASCII}StringDescriptor .Fix iterISO and getISOBufferList.1.6.2Fix getASCIIStringDescriptor: unlike getStringDescriptor, this returns only the
payload of the string descriptor, without its header.1.6.3Deprecate USBPollerThread . It is mileading users for which the simple version
(a thread callingUSBContext.handleEvents) would be enough. And for more
advanced uses (ie, actually needing to poll non-libusb file descriptors), this
class only works reliably with epoll: kqueue (which should tehcnically work)
has a different API on python level, and poll (which has the same API as epoll
on python level) lacks the critical ability to change the set of monitored file
descriptors while a poll is already running, causing long pauses - if not
deadlocks.1.6.4Fix asynchronous control transfers.1.6.5Document hotplug handler limitations.Run 2to3 when running setup.py with python3, and reduce differences with
python3.Properly cast libusb_set_pollfd_notifiers arguments.
Fix null pointer value: POINTER(None) is the type of a pointer which may be a
null pointer, which falls back to c_void_p. But c_void_p() is an actual null
pointer.1.6.6Expose bare string descriptors (aka string indexes) on USBDevice.1.6.7get{,ASCII}StringDescriptor now return None for descriptor 0 instead of raising
UnicodeDecodeError. Use getSupportedLanguageList to access it.Moved getManufacturer, getProduct and getSerialNumber to USBDeviceHandle. Kept
shortcuts for these on USBDevice.1.7get{,ASCII}StringDescriptor now return None for descriptor 0, use
getSupportedLanguageList to get its content.getManufacturer, getProduct and getSerialNumber are now on USBDeviceHandle,
with backward-compatibility aliases on their original location.Synchronous bulk and interrupt API exposes number of bytes sent and received
bytes even when a timeout occurs.1.7.1usb1.__version__ is now present, managed by versioneer.Fix an occasional segfault when closing a transfer from inside its callback
function.1.8Fix getExtra and libusb1.libusb_control_transfer_get_data .Fix getMaxPower unit on SuperSpeed devices.1.8.1Release process rework:embed libusb1 dll for easier deployment on Windowscryptographically signed releasesUse libusb_free_pollfds whenever available (libusb1>=1.0.20).Fix hotplug callback destruction at context teardown.Drop remnants of python 2.6 support code.1.9Drop USBPollerThread and deprecate libusb-lock-related USBContext API.1.9.1Fix installation from pypi source tarball, broken in 1.8.1 .1.9.2Windows wheels: Update bundled libusb to 1.0.24 .Fix soure-only build when wheel is not available.1.9.3Add support for pyinstaller.Improve the way the windows dlls are embedded in wheels.Fix support for python 3.10 .Add support for homebrew on Apple M1.1.10.1 (yanked)NOTE: Releaseyankedfrom pypi and re-released as 2.0.0.2.0.0Drop python <3.4 support.Do not load the C library on import. Allows applications to customise the
lookup logic (seeusb1.loadLibrary).Add LIBUSB_SPEED_SUPER_PLUS.Better control device iterator end of life.Fix objects escaping control from their parent.2.0.1Fix a TypeError exception in USBContext.handleEvents .Fix an AttributeError exception in USBContext.hotplugRegisterCallback .Fix segfault in pypy3 when finalizing USBDevice objects .Source only: convert examples to python3.Release process: also run some examples scripts.3.0.0Update versioneer to be compatible with 3.11 .Drop python <3.6 support (consequence of versioneer update), hence the major
version change.unreleasedFix bug preventing use of setPollFDNotifiers.Wrap libusb_interrupt_event_handler, available since libusb 1.0.21, to help
applications wake an event handling thread (ex: durring exit).Windows wheels: Update bundled libusb dll to 1.0.26 .