labthings / python-labthings

Python implementation of LabThings, based on the Flask microframework
GNU General Public License v3.0
18 stars 2 forks source link

Updating dependencies... #323

Open rwb27 opened 1 year ago

rwb27 commented 1 year ago

I'm really struggling to update the openflexure server - we are stuck in dependency hell again. I think I can relax a lot of the version constraints there to update things, but need to think carefully about the dependencies that come in via labthings: do we bite the bullet and update Flask? Is it time to try out an alternative framework like FastAPI? I think if I'm going to put a chunk of effort in, I'd be best putting it towards whatever's most useful long term, and if updating Flask already breaks things, maybe FastAPI is something to think about for the next major version?

@jtc42 what's your thinking here, and how much are you likely to want to get involved?

rwb27 commented 1 year ago

FWIW we will need to abandon Buster for the OpenFlexure software quite soon, because it ties us to Python 3.7 and is really out of date. I'm not looking forward to all the things that will break when we upgrade, but I think we'll need to do it before the next big release.

jtc42 commented 1 year ago

Yeah ok I think this all sounds sensible. I've been using fastapi a lot at work lately and it is really... properly nice to use. As you said though, it would be a substantial rewrite, likely even moreso than updating Flask.

FastAPI does have good support for threading requests. I believe it actually does this by default if the view function isn't async, but it'd still require a bit of work to get it functioning nicely with tasks etc. The underlying ASGI framework (Starlette) has background task functionality built in which you could relatively easily hook labthings tasks into (I do a similar thing for handling tasks at work, see https://github.com/renalreg/ukrdc-fastapi/blob/main/ukrdc_fastapi/utils/tasks.py#L58 and https://github.com/renalreg/ukrdc-fastapi/blob/main/ukrdc_fastapi/routers/api/patientrecords/pid/export.py#L46)

The other thing you may want to consider, if you're going the rewrite route anyway, is to re-integrate what is currently labthings back into the OF server application. It depends how much value it being separated still has.

Upsettingly I'm not really in a position right now to contribute much, if any, time to this beyond odd discussions here and there. I'm more familiar with fastapi than Flask these days, but I see the appeal of both options.

rwb27 commented 1 year ago

Thanks - that's exactly the sort of response I hoped for. I quite like the separation of splitting it out from the OFM server for now - we're reaching the stage where enough people want to customise it that the monolithic structure is getting troublesome so I'd ideally like to split it into a collection of properly separable modules, though many of them might come in the same package.

Thanks for the link to the task stuff - that will be really helpful. I've started https://github.com/rwb27/labthings-fastapi which is currently just some messing about with fastapi. When I have something worth sharing, I'll ping you again!