How to suppress output from a kqlmagic query in Jupyter?

I am using kqlmagic: GitHub - microsoft/jupyter-Kqlmagic: Extension (Magic) to Jupyter notebook and Jupyter lab, that enable notebook experience working with Kusto, ApplicationInsights, and LogAnalytics data. sql to execute KQL queries in my Jupyter notebook. While executing, kqlmagic prints output to the notebook such as:

 * forrest@loganalytics
Done (00:00.302): 1 records
1201 rows, truncated to display_limit of 0

This output ends up taking up half my screen. I would like to hide it and only display my final output, which is a matplotlib graph of the returned data.

Is it possible to disable printing this output from kqlmagic?

Most likely, yes.

Trying some of the notebooks here it looks like you need to sign up to even test some of this stuff and so I wasn’t able to easily find a way to run something like what you describe and test if my ideas work. Feel free to come back with an example that would work easily if you have trouble.

Usually you can achieve suppressing like this using %%capture cell magic or bracketing your code inside something like this:

from IPython.utils import io

with io.capture_output() as captured:
    MyFunction()

You have the added issue though that you need to combine it with the kqlmagix and so I cannot say what is the best for that. Doubling up in combination with %%cpature and %%time works if you put the %%time on the first line. However, I don’t know what combination might work for you since I couldn’t test.

You also mention though getting a plot back. Usually you can use the output you need by collecting it behind the scenes; however, I did run into an issue with using particular seaborn plots after capturing, see the UPDATE section here.

1 Like