Adding additional handlers to jupyterhub

70 views
Skip to first unread message

Dan Davis

unread,
Mar 14, 2018, 5:42:20 PM3/14/18
to Project Jupyter
I'd like to load additional handlers for the JupyterHub application.   Is there anyway to do this through jupyterhub_config.py or must I extend the JupyterHub application to do what I wish to do?

Thanks,

-Dan

Simon Biggs

unread,
Mar 14, 2018, 7:56:22 PM3/14/18
to Project Jupyter
Creating a Jupyter Server Extension is the key:


But also making it so that the handlers can handle having a different base name within the extension for example:

Defining the handlers

Providing the base_url to the handlers

Michael Milligan

unread,
Mar 14, 2018, 10:53:15 PM3/14/18
to jup...@googlegroups.com
This is totally my refrain today, but can you tell us a little more about what you are trying to do?

If you are trying to add new API endpoints directly to the Jupyterhub Hub, then yes, you will need to extend the application. The main extension points are the configurable Spawner and Authenticator classes, see here: http://jupyterhub.readthedocs.io/en/latest/reference/technical-overview.html

If you just need additional endpoints to be routed through to the per-user notebook servers, probably you don't need to do anything, as the proxy should take care of it.

You can also use Services if you need to add functionality that doesn't need to be directly part of the Hub itself: http://jupyterhub.readthedocs.io/en/latest/reference/services.html

Or if you actually want to extend the Jupyter notebook server, then Simon's answer should put you on the right track.

Regards,
Michael

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/37a662dc-d6bb-488f-9e2f-847d0871f753%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Dan Davis

unread,
Mar 15, 2018, 2:24:09 PM3/15/18
to Project Jupyter
I am implementing a MultiAuthenticator for a site that will use Jupyter to host training materials.   Since adoption is desired, social authentication will be 
desired, and so we will have more than one way to authenticate socially.

That said, I think I've figured out what I did not understand - traitlets.   I somehow took traitlets.config.Application to be the tornado.web.Application, and that confused thoroughly.
Now it is clear - the web application is initialized rather late, and since the init_handlers method calls h.extend(self.authenticator.get_handlers(self)), I simply return additional handlers that way.

From the structure of the code, it is pretty clear that each "handler" in that list should be a tuple of pattern and handler, and this is confirmed by the implementation of jupyterhub.auth.Authenticator.

I've even checked that this basic structure doesn't change with jupyterhub 0.9.0.dev, which maybe I should be using.

Robert Schroll

unread,
Mar 15, 2018, 8:13:45 PM3/15/18
to jup...@googlegroups.com, Project Jupyter
Hi Dan,

This sounds vaguely related to work I've just been doing on the HashAuthenticator, allowing a separate authentication system to be used for admin users. Maybe our code can give you some hints: https://github.com/thedataincubator/jupyterhub-hashauthenticator
On Mar 15 2018, at 11:24 am, Dan Davis <dans...@gmail.com> wrote:

Now it is clear - the web application is initialized rather late, and since the init_handlers method calls h.extend(self.authenticator.get_handlers(self)), I simply return additional handlers that way.

From the structure of the code, it is pretty clear that each "handler" in that list should be a tuple of pattern and handler, and this is confirmed by the implementation of jupyterhub.auth.Authenticator.

Yep, with this, it's easy to add additional endpoints. Because this runs within the JupyterHub process, you can (ab)use this to display all sorts of interesting information. (We generate a list of login credentials, for example.)

Also worth noting, since it took me a while to find this out: These tuples can have a third element, a dictionary of keyword arguments passed to the initialize method of your handler.

Hope that helps,
Robert

Reply all
Reply to author
Forward
0 new messages