from serial import Serial from fastapi import FastAPI ser = Serial('COM5', 9600) s = ser.read(1) # read up to one hundred bytes print(s) app = FastAPI() @app.get("/") async def root(): return ("message", s)