-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample.py
More file actions
31 lines (22 loc) · 791 Bytes
/
example.py
File metadata and controls
31 lines (22 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""An example of how Things can use other Things via dependencies."""
from typing import Annotated
from fastapi import Depends
import labthings_fastapi as lt
from labthings_fastapi.example_things import MyThing
MyThingClient = lt.deps.direct_thing_client_class(MyThing, "mything")
MyThingDep = Annotated[MyThingClient, Depends()]
class TestThing(lt.Thing):
"""A test thing with a counter property and a couple of actions."""
@lt.action
def increment_counter(self, my_thing: MyThingDep) -> None:
"""Increment the counter on another thing."""
my_thing.increment_counter()
server = lt.ThingServer(
{
"mything": MyThing,
"testthing": TestThing,
}
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(server.app, port=5000)