Kotlin (1.3.70) REPL kernel for Jupyter (https://jupyter.org).
Alpha version. Tested with Jupyter 6.0.1 on OS X so far.
To start using Kotlin kernel for Jupyter take a look at introductory guide.
Example notebooks can be found in the samples folder
There are two ways to install kernel:
If you have conda installed, just run:
conda install kotlin-jupyter-kernel -c jetbrains
Run ./gradlew install
Use option -PinstallPath= to specify installation path. (Note that Jupyter looks for kernel specs files only in predefined places.)
Default installation path is ~/.ipython/kernels/kotlin/.
jupyter console --kernel=kotlinjupyter notebookjupyter lab
To start using kotlin kernel inside Jupyter Notebook or JupyterLab create a new notebook with kotlin kernel.
The following REPL commands are supported:
:help- displays REPL commands help:classpath- displays current classpath
It is possible to add dynamic dependencies to the notebook using the following annotations:
@file:DependsOn(<coordinates>)- adds artifacts to classpath. Supports absolute and relative paths to class directories or jars, ivy and maven artifacts represented by colon separated string@file:Repository(<absolute-path>)- adds a directory for relative path resolution or ivy/maven repository
The following maven repositories are included by default:
The following line magics are supported:
%use <lib1>, <lib2> ...- injects code for supported libraries: artifact resolution, default imports, initialization code, type renderers%trackClasspath- logs any changes of current classpath. Useful for debugging artifact resolution failures%trackExecution- logs pieces of code that are going to be executed. Useful for debugging of libraries support
When a library is included with %use keyword, the following functionality is added to the notebook:
- repositories to search for library artifacts
- artifact dependencies
- default imports
- library initialization code
- renderers for special types, e.g. charts and data frames
List of supported libraries:
- klaxon - JSON parser for Kotlin
- lets-plot - ggplot-like interactive visualization for Kotlin
- krangl - Kotlin DSL for data wrangling
- kotlin-statistics - Idiomatic statistical operators for Kotlin
- kravis - Kotlin grammar for data visualization
- spark - Unified analytics engine for large-scale data processing
- gral - Java library for displaying plots
- koma - Scientific computing library
- kmath - Kotlin mathematical library analogous to NumPy
The list of all supported libraries can be found in config file
A definition of supported library may have a list of optional arguments that can be overriden when library is included. The major use case for library arguments is to specify particular version of library. Most library definitions default to -SNAPSHOT version that may be overriden in %use magic.
Usage example:
%use krangl(0.10), lets-plot By default the return values from REPL statements are displayed in the text form. To use richer representations, e.g. to display graphics or html, it is possible to send MIME-encoded result to the client using the MIME helper function:
fun MIME(vararg mimeToData: Pair<String, Any>): MimeTypedResult E.g.:
MIME("text/html" to "<p>Some <em>HTML</em></p>", "text/plain" to "No HTML for text clients") HTML outputs can also be rendered with HTML helper function:
fun HTML(text: String): MimeTypedResultPress TAB to get the list of suggested items for completion.
Currently completion suggests only names for user-defined variables and functions.
- Run
./gradlew installDebug. Use option-PdebugPort=to specify port address for debugger. Default port is 1044. - Run
jupyter-notebook - Attach remote debugger to JVM with specified port
You are welcome to add support for new Kotlin libraries by contributing to config.json file.
Library descriptor has the following fields:
name: short name of the library with optional arguments. All library arguments must have default value specified. Syntax:<name>(<arg1>=<default1>, <arg2>=<default2>)link: a link to library homepage. This link will be displayed in:helpcommandrepositories: a list of maven or ivy repositories to search for dependenciesdependencies: a list of library dependenciesimports: a list of default imports for libraryinit: a list of code snippets to be executed when library is includedinitCell: a list of code snippets to be executed before execution of any cellrenderers: a list of type converters for special rendering of particular types
Fields for type renderer:
class: fully-qualified class name for the type to be renderedresult: expression to produce output value. Source object is referenced as$it
Library arguments can be referenced in any parts of library descriptor as $arg
