I am now happily using BaseX from Jupyter Notebooks for Greek data - see these links:

http://jonathanrobie.biblicalhumanities.org/blog/2017/12/08/jupyter-tutorial/
http://jonathanrobie.biblicalhumanities.org/assets/greeksyntax-tutorial-proiel.html

But I need to know how to handle exceptions, e.g. if the notebook user writes a query with an error in it.  And I would also like to return some result if the query returns an empty sequence.  Here is the current code:

https://github.com/biblicalhumanities/greek-new-testament/blob/master/labnotes/greeksyntax/lowfat.py

How can I improve what I am doing?

Jonathan