Support Support Home » APIs » Python

Python API

We have integrated xiAPI into PYTHON.
This API creates an interface with which you can fully utilize the features and capabilities of XIMEA cameras.
This Python interface supports various Python packages like OpenCV or Pillow.

Supported platforms

  • Windows
  • Linux
  • MacOS

Installation instructions

Sample code:

The Ximea Python package may be used in a script in the following way:

from ximea import xiapi

#create instance for first connected camera
cam = xiapi.Camera()

#start communication
#to open specific device, use:
#(open by serial number)
print('Opening first camera...')

print('Exposure was set to %i us' %cam.get_exposure())

#create instance of Image to store image data and metadata
img = xiapi.Image()

#start data acquisition
print('Starting data acquisition...')

for i in range(10):
    #get data and pass them from camera to img

    #get raw data from camera
    #for Python2.x function returns string
    #for Python3.x function returns bytes
    data_raw = img.get_image_data_raw()

    #transform data to list
    data = list(data_raw)

    #print image data and metadata
    print('Image number: ' + str(i))
    print('Image width (pixels):  ' + str(img.width))
    print('Image height (pixels): ' + str(img.height))
    print('First 10 pixels: ' + str(data[:10]))

#stop data acquisition
print('Stopping acquisition...')

#stop communication


Example applications

There are several applications, that may be found in the xiApiPython examples/ folder.
Here you may find various examples for xiApiPython, OpenCV, or Pillow packages.


The Python v3. supports examples only from pillow and various folder.