qrcode
Platypush documentation
qrcode
- class platypush.plugins.qrcode.QrcodePlugin(camera_plugin: Optional[str] = None, **kwargs)[source]
Bases:
Plugin
Plugin to generate and scan QR and bar codes.
Requires:
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]
- Parameters:
camera_plugin – Name of the plugin that will be used as a camera to capture images (e.g.
camera.cv
orcamera.pi
).
- decode(image_file: str) QrcodeDecodedResponse [source]
Decode a QR code from an image file.
- Parameters:
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 throughhttp://<host>:<port>/qrcode?content=...
.- Parameters:
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
).
- Returns:
- 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.
Triggers:
platypush.message.event.qrcode.QrcodeScannedEvent
when a code is successfully scanned.
- Parameters:
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).
- Returns:
When
duration
orn_codes
are specified orstop_scanning
is called, it will return a list ofplatypush.message.response.qrcode.ResultModel
instances with the scanned results,