Skip to main content

A test implementation of LabThings using FastAPI

Project description

codecov Documentation Status

labthings-fastapi

A FastAPI based library to implement a Web of Things interface for laboratory hardware using Python. This is a ground-up rewrite of python-labthings, replacing Flask 1 and Marshmallow with FastAPI and Pydantic. It is the underlying framework for v3 of the OpenFlexure Microscope software.

Features include:

  • Better alignment with the Web of Things standard:
    • Extensions are gone, everything is now a Thing
    • Things are classes, with properties and actions defined exactly once
    • Various improvements to TD generation and validation with pydantic
  • Cleaner API
    • Datatypes of action input/outputs and properties are defined with Python type hints
    • Actions are defined exactly once, as a method of a Thing class
    • Properties and actions are declared using decorators (or descriptors if that's preferred)
    • Dependency injection is used to manage relationships between Things and dependency on the server
  • Async HTTP handling
    • Starlette (used by FastAPI) can handle requests asynchronously - potential for websockets/events (not used much yet)
    • Thing code is still, for now, threaded. I intend to make it possible to write async things in the future, but don't intend it to become mandatory
  • Smaller codebase
    • FastAPI more or less completely eliminates OpenAPI generation code from our codebase
    • Thing Description generation is very much simplified by the new structure (multiple Things instead of one massive Thing with many extensions)
  • Extensive testing
    • FastAPI/Starlette have nice test provision, so the vast majority of the codebase is already covered

Installation

You can install this repository with pip, either clone it and run pip install -e .[dev] to work on it, or just pip install https://gitlab.com/rwb27/labthings-fastapi.git. It will be published on PyPI in the near future, initially as labthings-fastapi. It may at some point be renamed to labthings v2.

Developer notes

The code is linted with ruff ., type checked with mypy src, and tested with pytest. These all run in CI with GitHub Actions. The codebase is not even v0.1 yet so it's still subject to summary rearrangement.

Demo

See the examples folder for a runnable demo.

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_fastapi-0.0.4.tar.gz (61.2 kB view details)

Uploaded Source

Built Distribution

labthings_fastapi-0.0.4-py3-none-any.whl (62.9 kB view details)

Uploaded Python 3

File details

Details for the file labthings_fastapi-0.0.4.tar.gz.

File metadata

  • Download URL: labthings_fastapi-0.0.4.tar.gz
  • Upload date:
  • Size: 61.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for labthings_fastapi-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7a13618bd8eb7976d76f345ffe677154db584c28b518144604f8e70cf612b083
MD5 153aec94a58fcb773f9e7d2ad5869585
BLAKE2b-256 415cb4f4681afe96e151390521b02064096be462f9b220e177cffaa38c0ce7eb

See more details on using hashes here.

File details

Details for the file labthings_fastapi-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for labthings_fastapi-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 41e3a7401269b249e58b884d2f798bdcf005cd353d61b7ca0321af0d2f4c48af
MD5 bfbcc614835ad0187dbb44d2eb3915c9
BLAKE2b-256 60034187eb9649bf55c415270e86deec4db760f53670d6bc25c8324a6027a054

See more details on using hashes here.

Supported by

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