Documentation for LabThings-FastAPI
Contents:
- Quick start
- LabThings-FastAPI tutorial
- LabThings structure
- Actions
- Properties
- Generated documentation
- Thing Slots
- Blob input/output
- Concurrency in LabThings-FastAPI
- Using Things
- Optional Features and updates
- See Also
- Examples
- Web of Things Core Concepts
- Removed Features
- Public API Documentation
- Internal API Reference
- Developer Notes
labthings-fastapi is a Python library to simplify the process of making laboratory instruments available via a HTTP. It aims to create an API that is usable from any modern programming language, with API documentation in both OpenAPI and Thing Description formats. It is the underlying framework for v3 of the OpenFlexure Microscope software. Key features and design aims are:
The functionality of a unit of hardware or software is described using
Thingsubclasses.Methods and properties of
Thingsubclasses may be added to the HTTP API and associated documentation using decorators.Datatypes of action input/outputs and properties are defined with Python type hints.
Actions are decorated methods of a
Thingclass. There is no need for separate schemas or endpoint definitions.Properties are defined either as typed attributes (similar to
pydanticordataclasses) or with aproperty-like decorator.Lifecycle and concurrency are appropriate for hardware:
Thingcode is always run in a thread, and eachThingis instantiated, started up, and shut down only once.Vocabulary and concepts are aligned with the W3C Web of Things standard (see Web of Things Core Concepts)
Previous version
This is a ground-up rewrite of python-labthings, replacing Flask 1 and Marshmallow with FastAPI and Pydantic. Compared to python-labthings, this framework updates dependencies, shrinks the codebase, and simplifies the API (see LabThings structure). * FastAPI more or less completely eliminates OpenAPI generation code from our codebase * Marshmallow schemas and endpoint classes are replaced with Python type hints, eliminating double- or triple-definition of actions and their inputs/outputs. * Thing Description generation is very much simplified by the new structure (multiple Things instead of one massive Thing with many extensions)
Installation
pip install labthings-fastapi