Metadata-Version: 2.1
Name: labthings-fastapi
Version: 0.0.1
Summary: A test implementation of LabThings using FastAPI
Author-email: Richard Bowman <richard.bowman@cantab.net>
Project-URL: Homepage, https://github.com/rwb27/labthings-fastapi
Project-URL: Bug Tracker, https://github.com/rwb27/labthings-fastapi/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic>=2.0.0
Requires-Dist: jsonschema
Requires-Dist: typing_extensions
Requires-Dist: anyio~=4.0
Provides-Extra: dev
Requires-Dist: pytest<8,>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: mypy<2,>=1.6.1; extra == "dev"
Requires-Dist: ruff>=0.1.3; extra == "dev"
Requires-Dist: types-jsonschema; extra == "dev"
Requires-Dist: numpy~=1.20; extra == "dev"
Provides-Extra: server
Requires-Dist: fastapi[all]>=0.104.0; extra == "server"

[![codecov](https://codecov.io/gh/rwb27/labthings-fastapi/branch/main/graph/badge.svg?token=IR4QNA8X6M)](https://codecov.io/gh/rwb27/labthings-fastapi)
[![Documentation Status](https://readthedocs.org/projects/labthings-fastapi/badge/?version=latest)](https://labthings-fastapi.readthedocs.io/en/latest/?badge=latest)

# 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`
    - `Thing`s 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.0.1` yet so it's still subject to summary rearrangement.

## Demo

See the [examples folder](./examples/) for a runnable demo.

[Web of Things]: https://www.w3.org/WoT/
[python-labthings]: https://github.com/labthings/python-labthings/
[OpenFlexure Microscope software]: https://gitlab.com/openflexure/openflexure-microscope-server/
