Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1071839%22%20slang%3D%22en-US%22%3EHow%20to%20debug%20inline%20Python%20code%20in%20Azure%20Data%20Explorer%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1071839%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Explorer%20supports%20running%20Python%20code%20embedded%20in%20Kusto%20query%20language%20using%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-explorer%2Fdebug-inline-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Epython()%20plugin%3C%2FA%3E.%20The%20plugin%20runtime%20is%20hosted%20in%20a%20sandbox%2C%20an%20isolated%20and%20secure%20Python%20environment.%20The%20python()%20plugin%20capability%20extends%20KQL%20(Kusto%20Query%20Language)%20native%20functionalities%20with%20the%20huge%20archive%20of%20OSS%20Python%20packages.%20This%20extension%20enables%20you%20to%20run%20advanced%20algorithms%2C%20such%20as%20ML%2C%20AI%2C%20statistical%2C%20and%20Time%20Series%20Analysis%20as%20part%20of%20the%20query.%3C%2FP%3E%0A%3CP%3EKQL%20tools%20aren't%20convenient%20for%20developing%20and%20debugging%20Python%20algorithms.%20Therefore%2C%20the%20best%20practice%20is%20to%20develop%20the%20algorithm%20on%20your%20favorite%20Python%20IDE%20such%20as%20Jupyter%2C%20PyCharm%2C%20VS%2C%20or%20VS%20Code.%20When%20the%20algorithm%20is%20complete%2C%20copy%20and%20paste%20the%20python%20code%20into%20KQL.%20To%20improve%20and%20streamline%20this%20workflow%2C%20Azure%20Data%20Explorer%20supports%20integration%20between%20Kusto%20Explorer%20or%20Web%20UI%20clients%20and%20VS%20Code%20for%20authoring%20and%20debugging%20KQL%20inline%20Python%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQuery%20example%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ERun%20the%20KQL%20query%20in%20Kusto%20Explorer%2C%20prefix%20it%20with%20the%26nbsp%3Bset%20query_python_debug%3B%20statement%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eset%20query_python_debug%3B%0Arange%20x%20from%201%20to%204%20step%201%0A%7C%20evaluate%20python(typeof(*%2C%20x4%3Aint)%2C%20%0A'exp%20%3D%20kargs%5B%22exp%22%5D%5Cn'%0A'result%20%3D%20df%5Cn'%0A'result%5B%22x4%22%5D%20%3D%20df%5B%22x%22%5D.pow(exp)%5Cn'%0A%2C%20pack('exp'%2C%204))%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EVS%20Code%20is%20launched.%20You%20can%20debug%20your%20script%2C%20for%20example%2C%20to%20verify%20the%20table%20that%20is%20returned%20to%20ADX%20you%20can%20breakpoint%20at%20the%20end%20of%20the%20script%20and%20from%20the%20debug%20console%20print%20the%20%E2%80%98result%E2%80%99%20dataframe%3A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F162305iD4ABC66298A92F6A%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EFor%20further%20information%20see%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-explorer%2Fdebug-inline-python%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ethe%20full%20documentation%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1071839%22%20slang%3D%22en-US%22%3E%3CP%3EAzure%20Data%20Explorer%20supports%20running%20Python%20code%20embedded%20in%20Kusto%20query%20language%20using%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fdata-explorer%2Fdebug-inline-python%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3Epython()%20plugin%3C%2FA%3E.%20The%20python()%20plugin%20capability%20extends%20Kusto%20query%20language%20native%20functionalities%20with%20the%20huge%20archive%20of%20OSS%20Python%20packages%2C%20enabling%20running%20advanced%20algorithms%2C%20such%20as%20ML%2C%20AI%20and%20Time%20Series%20Analysis%20as%20part%20of%20the%20query.%20To%20improve%20and%20streamline%20this%20workflow%2C%20Azure%20Data%20Explorer%20supports%20integration%20between%20Kusto%20Explorer%20or%20Web%20UI%20clients%20and%20VS%20Code%20for%20authoring%20and%20debugging%20KQL%20inline%20Python%20code.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20743px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F162312iAB789E6FBB0111DA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22QueryPythonDebug.PNG%22%20title%3D%22QueryPythonDebug.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1071839%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Data%20Explorer%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Edebugging%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ekql%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EKusto%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epython%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Evscode%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Azure Data Explorer supports running Python code embedded in Kusto query language using the python() plugin. The plugin runtime is hosted in a sandbox, an isolated and secure Python environment. The python() plugin capability extends KQL (Kusto Query Language) native functionalities with the huge archive of OSS Python packages. This extension enables you to run advanced algorithms, such as ML, AI, statistical, and Time Series Analysis as part of the query.

KQL tools aren't convenient for developing and debugging Python algorithms. Therefore, the best practice is to develop the algorithm on your favorite Python IDE such as Jupyter, PyCharm, VS, or VS Code. When the algorithm is complete, copy and paste the python code into KQL. To improve and streamline this workflow, Azure Data Explorer supports integration between Kusto Explorer or Web UI clients and VS Code for authoring and debugging KQL inline Python code.

 

Query example

 

  • Run the KQL query in Kusto Explorer, prefix it with the set query_python_debug; statement:

 

set query_python_debug;
range x from 1 to 4 step 1
| evaluate python(typeof(*, x4:int), 
'exp = kargs["exp"]\n'
'result = df\n'
'result["x4"] = df["x"].pow(exp)\n'
, pack('exp', 4))

 

  • VS Code is launched. You can debug your script, for example, to verify the table that is returned to ADX you can breakpoint at the end of the script and from the debug console print the ‘result’ dataframe:

clipboard_image_0.png

For further information see the full documentation