class platypush.plugins.qrcode.QrcodePlugin(camera_plugin: Optional[str] = None, **kwargs)[source]

Bases: Plugin

Plugin to generate and scan QR and bar codes.


  • numpy (pip install numpy).

  • qrcode (pip install 'qrcode[pil]') for QR generation.

  • pyzbar (pip install pyzbar) for decoding code from images.

  • Pillow (pip install Pillow) for image management.

__init__(camera_plugin: Optional[str] = None, **kwargs)[source]

camera_plugin – Name of the plugin that will be used as a camera to capture images (e.g. camera.cv or camera.pi).

decode(image_file: str) QrcodeDecodedResponse[source]

Decode a QR code from an image file.


image_file – Path of the image file.

generate(content: str, output_file: Optional[str] = None, show: bool = False, format: str = 'png') QrcodeGeneratedResponse[source]

Generate a QR code. If you configured the platypush.backend.http.HttpBackend then you can also generate codes directly from the browser through http://<host>:<port>/qrcode?content=....

  • content – Text, URL or content of the QR code.

  • output_file – If set then the QR code will be exported in the specified image file. Otherwise, a base64-encoded representation of its binary content will be returned in the response as data.

  • show – If True, and if the device where the application runs has an active display, then the generated QR code will be shown on display.

  • format – Output image format (default: png).



start_scanning(camera_plugin: Optional[str] = None, duration: Optional[float] = None, n_codes: Optional[int] = None) Optional[List[ResultModel]][source]

Decode QR-codes and bar codes using a camera.


  • camera_plugin – Camera plugin (overrides default camera_plugin).

  • duration – How long the capturing phase should run (default: until stop_scanning or app termination).

  • n_codes – Stop after decoding this number of codes (default: None).


When duration or n_codes are specified or stop_scanning is called, it will return a list of platypush.message.response.qrcode.ResultModel instances with the scanned results,