Comments (5)
Another option that is more language agnostic but also more "magical" (in a bad way) ...
If the cell emits JSON, parse it. If it contains a "headers" key and a "body" key, use those to set the HTTP header and body appropriately. (Same for the "status" for issue #47).
Strawman here is to use a form of duck typing to do the detection, but maybe there's a more explicit way.
from kernel_gateway.
Brainstorming:
- Use the different message types to separate print (body, output) vs execute result (implicit display) (pro: agnostic, con: multiple outputs can get confusing)
- Set a global RESPONSE variable before the cell ends with a JSON value contain headers, status, etc. (pro: consistent with REQUEST, con: more kernel comm)
- We can clear RESPONSE after reading it every time, but it still means we have to check it every time even if it's not being used to set special headers
from kernel_gateway.
Putting the original implementation ideas here to record in case we change implementations in the future:
Implementation 1: Display Data
The python kernels already use the display data module to set outputs for specific types. For my particular use case, I believe this could be achieved today by writing the following code:
# GET /foo/bar
from IPython import display
response_dict = { 'foo' : 'bar' }
response_type = get_response_type() # Assumes we will be able to get the accept header
response_value = serialize_response(response_type, response_dict)
display.publish_display_data({
response_type : response_value
})
The only implementation needed in the kernel gateway would be to do the following:
- Check if there is an accept header
- Look at the display data returned from the cell execution and see if the accept header mime-type is in the message
- Return appropriate value based on the step above
Advantages
- There is an implementation, which can be referenced by other kernels, in the python kernel.
- The API is fairly simple and would look fairly similar across multiple languages
- This can help the ambiguity in returning values by making this the standard way to return values for consumption by the kernel gateway
Disadvantages
- Requires an implementation of Display Data for the current kernel
Implementation 2: Comm API
We can provide a comm channel API which will allow for objects to be created which will relay the response information to the kernel gateway. An example implementation could look like this:
from KernelGateway import Response
# GET /foo/bar
response_dict = { 'foo' : 'bar' }
response_type = get_response_type() # Assumes we will be able to get the accept header
response_value = serialize_response(response_type, response_dict)
Response(response_value, type=reponse_type, status=200)
Advantages
- Will provide us flexibility in defining what the API is going to be (this can help in other areas such as setting the HTTP response status code or any other response values)
Disadvantages
- Will need to setup implementations across all supported kernel, which could be taxing on resources for development.
- Requires all kernels to provide an API to interact with comm channels from within the kernel (which I believe would also be required from implementation 1)
- Will require a
kernel_gateway
plugin to run code to setup the comm channels (either as an extension or by interacting with the kernel directly)
from kernel_gateway.
pr #70 will close this.
from kernel_gateway.
Merged. For anyone else following along, README has the final design.
from kernel_gateway.
Related Issues (20)
- CORS preflight OPTIONS request fails for kernel interruptions HOT 1
- Can't access environment variables with remote kernel HOT 3
- kernel_gateway incompatible with Jupyter API? HOT 9
- Parallel API calls
- JWT Auth Mixin
- block kwarg removed in jupyter-client 7 HOT 2
- jupyter websocket messages not updating UI HOT 5
- How do I run some bootstrap code in the kernels before the startup files? HOT 2
- Support for integrating external contents managers HOT 2
- Moving repo to jupyter-server org HOT 2
- jupyter-kernel-gateway hanging/slow HOT 18
- Update JKG to more recent packages
- Decoding message response in NodeJS WS demo HOT 1
- Decoding message data in nodeJS demo. HOT 1
- Using bash kernel in notebook-http mode HOT 5
- Returning the message associated with the error code HOT 1
- Gateway seems to be stuck when deploying on cloud HOT 3
- 3.x Release HOT 5
- CLI fails to start on windows with signal import issue HOT 1
- Reload cell code without restarting server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kernel_gateway.