Skip to main content

Picamera2 support for LabThings-FastAPI

Project description

labthings-picamera2

A LabThings-FastAPI Thing for working with picamera2

This package defines a Thing using labthings-fastapi that exposes an HTTP interface to the Raspberry Pi camera, using picamera2. This includes autogenerated OpenAPI documentation viewed with a built-in Swagger/Redocly page at /docs/, and a Web of Things compliant Thing Description at the camera's root (usually /camera/).

Installation

For this to work you should be on a 32-bit version of Bullseye or Bookworm os with python v3.9 or 3.11.

It's usually best to install in a virtual environment, but note that you should use

python -m venv .venv --system-site-packages

as the picamera2 package and its dependencies are not all installable using pip.

The package is on PyPI and can be installed using

pip install labthings-picamera2

You will also need to separately install the server with:

pip install labthings-fastapi[server]

If you want to edit labthings-picamera2 then you can clone this repository. Move to the directory and run

pip install -e .

Usage

You can start the server using:

labthings-server --json '{"things":{"/camera/":"labthings_picamera2.thing:StreamingPiCamera2"}}'

This assumes you have labthings[server]>=0.0.6 installed.

You may then point a web browser at http://localhost:5000/camera or http://localhost:5000/docs/.

It's also possible to control it from Python, if you have labthings-fastapi installed (note that if you're using a separate machine or separate environment for the client, if you don't add [server] it won't install the rather heavy server dependencies like starlette.)

To connect, run:

from labthings_fastapi.client import ThingClient
from PIL import Image

cam = ThingClient.from_url("http://localhost:5000/camera/")
blob = cam.capture_jpeg()
image = Image.open(blob.open())

All of the properties and actions described in the Thing Description should be present as Python properties and methods - currently the types and docstrings don't propagate to the client object, this is planned for the future but isn't reality yet.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labthings_picamera2-0.0.2.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

labthings_picamera2-0.0.2-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file labthings_picamera2-0.0.2.tar.gz.

File metadata

  • Download URL: labthings_picamera2-0.0.2.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for labthings_picamera2-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f288527bd6d8cb079e4e5c40cc2341041f0033e36fa4ba617a6b1a3ba4c6546d
MD5 b56d4c0f84418fc4e5beeb43f0af7554
BLAKE2b-256 1cf6cf64f7643f80d92bd674a6fcd3e5ca9182e59da9f9fe1057d7d7725e4b62

See more details on using hashes here.

Provenance

The following attestation bundles were made for labthings_picamera2-0.0.2.tar.gz:

Publisher: publish.yml on labthings/labthings-picamera2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file labthings_picamera2-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for labthings_picamera2-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cdd19ef93b755333001c3dbea1651f720c7274d9e730b9bb4bd7c7adcabf524
MD5 86e792ed8907c42a850ce951a4a944fa
BLAKE2b-256 ae0e48a4bfe79415ade3ee386888bb8bf8baff8979c157f5cf8b66998deda0fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for labthings_picamera2-0.0.2-py3-none-any.whl:

Publisher: publish.yml on labthings/labthings-picamera2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page