---
title: magics
description: Line and cell magics for in-process notebook execution.
---
## UsageError

```python
def UsageError(
    *args, **kwargs
):
```

*Common base class for all non-exit exceptions.*

## MagicsMixin

```python
def MagicsMixin():
```

### MagicsMixin.init\_magics

```python
def init_magics():
```

### MagicsMixin.register\_magic\_function

```python
def register_magic_function(
    func, magic_kind:str='line', magic_name=None
):
```

*Register f(line), f(line, cell), or f(line, cell\=None) as a magic.*

### MagicsMixin.var\_expand

```python
def var_expand(
    cmd, depth:int=0, formatter:execnb.minipy.text.DollarFormatter=<DollarFormatter>
):
```

### MagicsMixin.run\_line\_magic

```python
def run_line_magic(
    magic_name, line
):
```

### MagicsMixin.run\_cell\_magic

```python
def run_cell_magic(
    magic_name, line, cell
):
```

### MagicsMixin.lsmagic

```python
def lsmagic(
    line:str=''
):
```

*List registered line and cell magics. Use -j or --json to return a dictionary.*

### MagicsMixin.show\_usage

```python
def show_usage():
```

### MagicsMixin.who\_ls

```python
def who_ls(
    line:str=''
):
```

*Return sorted user variables, optionally restricted to the given type names.*

### MagicsMixin.who

```python
def who(
    line:str=''
):
```

*Print user variable names, optionally restricted by type.*

### MagicsMixin.whos

```python
def whos(
    line:str=''
):
```

*Show the types and values of user variables, summarizing arrays and long values.*

### MagicsMixin.system

```python
def system(
    cmd
):
```

### MagicsMixin.getoutput

```python
def getoutput(
    cmd
):
```

### MagicsMixin.pwd

```python
def pwd(
    line
):
```

### MagicsMixin.cd

```python
def cd(
    line
):
```

### MagicsMixin.env

```python
def env(
    line
):
```

*Get or set a variable, or list the environment with likely secrets hidden.*

### MagicsMixin.set\_env

```python
def set_env(
    line
):
```

### MagicsMixin.writefile

```python
def writefile(
    line, cell
):
```

### MagicsMixin.html

```python
def html(
    line, cell
):
```

### MagicsMixin.capture

```python
def capture(
    line, cell
):
```

### MagicsMixin.config

```python
def config(
    line
):
```

*Set InlineBackend.figure\_format for inline Matplotlib plots.*

### MagicsMixin.matplotlib

```python
def matplotlib(
    line
):
```

*Enable inline figure display.*

### MagicsMixin.pinfo

```python
def pinfo(
    line
):
```

### MagicsMixin.pinfo2

```python
def pinfo2(
    line
):
```

### MagicsMixin.timeit

```python
def timeit(
    line:str='', cell=None, local_ns=None
):
```

*Time a statement or cell. On %%timeit the header runs as untimed setup.*

-n loops, -r repeats, -t wall time, -c process CPU time, -p significant digits, -q quiet, -o return the result, -v NAME save it.

### MagicsMixin.time

```python
def time(
    line:str='', cell=None, local_ns=None
):
```

*Print CPU and wall time and return the last expression; --no-raise-error suppresses ordinary runtime exceptions.*
