-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add python webserver handlers and clients for starlette (fastapi) and aiohttp #1828
Conversation
starlette server Asyncify the perspective client, abstract away the websocket handler into its own class and utility classes Implement starlette test client websocket wrapper, for testing purposes only. Websocket wrapper is synchronous so won't play nicely with perspective outside of a testing context fix lint
47f02dd
to
d241f50
Compare
2d8345e
to
bc731f8
Compare
ce51302
to
67fb17e
Compare
example, add aiohttp handler tests, migrate tornado tests to full async/await
Going to do a pass through now that all the tests are working (and cover some corner cases like locking) to see if we can eliminate the need for web server-specific handlers and just export 1, potentially with some type checks or flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
This is a cool addition, thanks especially for updating the tests and the special attention paid to the chunking/locking/streaming use cases we discussed. A few comments I had -
- It's worth IMO adding explicit docs on installing the optional dependencies, even though this may be basic Python developer knowledge.
- As we add more framework integrations (?), I'm interested in any strategy we can come up with to minimize an explosion of "glue" code that just translates Perspective concepts to framework ones.
PerspectiveManager
was meant to be a core abstraction we could use to "invert" this problem - e.g., make a simple API for dealing with Perspective server and session state, and then integration with specific frameworks should be "obvious"; however, we still ended up with aTornadoHandler
which we justified "as an example", then it just seemed pedantic to not export this also ... and now we export 3 such glue modules, all nearly identical. - We want to avoid an explosion of examples also - the ones in this PR are fine but if we end up adding more I'd like to see a consolidation of the python examples to show novel/interesting/exemplary use of the API, rather than just all possible permutations of framework/perspective.
"superstore-arrow": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@finos/perspective-webpack-plugin": "^1.4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire devDependencies
is superfluous I think - same goes for the other example projects added in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just copying from current examples in master: https://github.com/finos/perspective/blob/master/examples/python-tornado/package.json#L19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm you already merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"I copied something that was wrong" does not merit indemnity from review comments
@timkpaine also please remember to drop merge commits before un-drafting (as per |
(Moving over from #1573)
This PR decouples perspective's python server code from tornado, and adds
PerspectiveManager
integration, examples, and client libraries forAIOHTTP
andStarlette
/FastAPI
.The existing perspective webserver integration was limited to tornado. Though it was possible to connect
PerspectiveManager
to other webservers (with relative ease), these integrations were not "out of the box" and required end users to be familiar with the perspective client/server architecture. Additionally, because support was limited to tornado, certain aspects of both the server integration, and the websocket client integration would require extensive copy-paste for a user to integrate with a different library.Websocket Server Changes
We abstract away the
PerspectiveManager
integration from thePerspectiveTornadoHandler
class into the newPerspectiveHandlerBase
class. This class is essentially the non tornado-specific aspects of the originalPerspectiveTornadoHandler
class. Minor modifications are made:We then add two additional handlers implementing the
PerspectiveHandlerBase
class:PerspectiveAIOHTTPHandler
, which implements compatibility withaiohttp
web serversPerspectiveStarletteHandler
, which implements compatibility withstarlette
/FastAPI
web serversTests mirroring the tornado web server tests are added for both these handlers
Websocket Client Changes
On the client side, we decouple the tornado integration by adding three base classes:
PerspectiveWebsocketClient
to handle the integration between an arbitrary read/write websocket interface and thePerspectiveClient
classPerspectiveWebsocketConnection
, an abstract class to be implemented by the low level websocket connection detailsPeriodic
, an abstract class to to be implemented according to the underlying event loop (asyncio
/tornado
) to handle keep alive (ping/pong) messagesThe
PerspectiveTornadoClient
class is then modified to implement these interfaces, alongside the newPerspectiveTornadoWebsocketConnection
andPerspectiveTornadoPeriodic
classes.We then introduce support for two new libraries:
PerspectiveAIOHTTPClient
for integration withaiohttp
websocket client library (and the correspondingPerspectiveAIOHTTPWebsocketConnection
andAIOHTTPPeriodic
_PerspectiveStarletteTestClient
for integration with the starlette testing websocket client (starlette does not provide a standalone non-test websocket client)The former
websocket
function export is renamed totornado_websocket
, andaiohttp_websocket
is added.Examples
Leveraging the same frontend code as the existing tornado example, we add examples for
FastAPI
andaiohttp
servers. The existing tornado libraries are renamed for consistency and to appear next to their sibling examples for discoverability.@nickpholden feel free to test the included examples for starlette/fastapi and aiohttp
@tiangolo about to get an insanely fast datagrid 🚀