Magic commands

Magics are special commands for the kernel that are not part of the C++ programming language.

There are defined with the symbol % for a line magic and %% for a cell magic.

A few magics are available in xeus-cling. In the future, user-defined magics will also be enabled.


This magic command copies the content of the cell in a file named filename.

%%file [-a] filename
  • Example

  • Optional argument:


append the content to the file.


Measure the execution time execution for a line statement (%timeit) or for a block of statements (%%timeit)

  • Usage in line mode

%timeit [-n<N> -r<R> -p<P>] statement
  • Usage in cell mode

%%timeit [-n<N> -r<R> -p<P>]
  • Example

  • Optional arguments:


execute the given statement <N> times in a loop. If this value is not given, a fitting value is chosen.


repeat the loop iteration <R> times and take the best result. Default: 7


use a precision of <P> digits to display the timing result. Default: 3