The API project contains the http server. It also includes code required to run protocols, talk to smoothie board, read various robot configs, take pictures, and more.
All the code is packaged and distributed as a library as well as launched as an application.
As we move to FastAPI as a new framework and work to redesign some of our API this is a good time to do some refactoring.
1: Opentrons library providing interfaces to Robot.
2: API application which uses Opentrons library to talk to robot
3: Simulator application
Make it easier to interact with the robot.
nmcli, camera, etc.
I believe this is akin to what @iansolano was thinking as Services
This seems to have been started in hardware_control/modules. Let's keep going and apply this to everything.
nmcli, camera, etc.
API bootstrap or jupyter notebook code should call factory methods to create the appropriate object instances based on running environment.
For example:
Every http handler in server/endpoints/control.py checks a feature flag to determine what kind of object is held in request's com.opentrons.hardware value. This can be abstracted using a fleshed out HardwareAPILike interface.
Eliminate command line arguments from API and Hardware Control setup.
Looks good in general, but a few interesting things:
Regarding your first point, I think that any code that would be imported and used by multiple applications, scripts or via a jupyter notebook should not be in update-server or api. I could see that updates and networking would not fall into this category, but lights, sound, camera, etc could be useful from some jupyter notebook.
๐ on point 2.
Thinking about it more, I agree with you about the multimedia support stuff. We should also probably consider integrating it into both the json and python protocol APIs.
Sorry I'm a little late to the party. I'm in agreement with the general premise here, curious to see how we prioritize implementation (i.e. what parts to peel off first, mocks for HW might be nice since we _could_ start by improving testing).
Abstracting HardwareAPILike interfaces, simulations and/or mocks, and separating things like nmcli wrapper make a lot of sense to me.
With regards to wrappers of all hardware resources and services, this is somewhat similar in concept, the idea being isolate the business logic and provide a clean interface for engineers to interact with. Services objects in my particular wording applied to the the associated business logic around a particular resource (api endpoint) and abstracting the work around what and how to display json in api calls as well as how those api calls interact with our system (if that makes sense). Hopefully, in the nearish future I'll make PR example of this with the new fastapi implementation.
Excited about where this is heading ๐. Thanks for getting the ball rolling @amitlissack
It can me named py-opentrons or something else more imaginative.
This would contain everything in api project minus opentrons.server and opentrons.app packages. Almost everything in current api is applicable to building a package vs an application.
api sub-projectThis is the api server application. For the time being both the aiohttp (opentrons.server) and fastapi (opentrons.app) packages will be in this project.
| README.md
| Makefile
| ...
โ- tests
| | __init__.py
| โ- app
โ- app
| __init__.py
| main.py
โ- aiohttp ( to be deprecated )
โ- fastapi ( move contents one level up when aiohttp is deprecated )
api will not be packaged for pypi./usr/local/opentrons/api)API configuration for the moment is just a handful of items and they should be moved from command line args and into their own yaml file.
The request handlers in opentrons.server.endpoints contain a good amount of code that should be moved to the opentrons library.
Examples
move function in control.py should be moved out to the shared library. Interacting with the motion lock is too much intimate knowledge of the hardware for a request handler.take_picture should call a method in the library rather than invoking ffmpeg.This ticket #4963
We all agree that this should happen. Created an epic for the project #5009