<jupyter_start><jupyter_text>IPython/Jupyter Magic Reprex-rendering is also available in IPython, Jupyter, and VS Code through an IPython cell magic. This functionality requires IPython to be installed at a minimum. (You can install both reprexlite and IPython together with `reprexlite[ipython]`.) To use, first load the extension:<jupyter_code>%load_ext reprexlite<jupyter_output><empty_output><jupyter_text>and then simply use the `%%reprex` magic with a cell containing the code you want a reprex of.<jupyter_code>%%reprex

from itertools import product

grid = list(product([1, 2, 3], [8, 16]))
grid
list(zip(*grid))<jupyter_output>```python
from itertools import product

grid = list(product([1, 2, 3], [8, 16]))
grid
#> [(1, 8), (1, 16), (2, 8), (2, 16), (3, 8), (3, 16)]
list(zip(*grid))
#> [(1, 1, 2, 2, 3, 3), (8, 16, 8, 16, 8, 16)]
```

<sup>Created at 2021-02-27 16:08:34 PST by [reprexlite](https://github.com/jayqi/reprexlite) v0.3.1</sup><jupyter_text>That's it! The cell magic shares the same interface and command-line options as the CLI.<jupyter_code>%%reprex -v slack
x = 2
x + 2<jupyter_output>```
x = 2
x + 2
#> 4
```<jupyter_text>Print Help DocumentationYou can use the `%reprex` line magic (single-`%`) to print out documentation.<jupyter_code>%reprex<jupyter_output>reprexlite v0.3.1 IPython Magic

Cell Magic Usage: %%reprex [OPTIONS]

  Render reproducible examples of Python code for sharing. Your code will be
  executed and the results will be embedded as comments below their associated
  lines.

  Additional markup will be added that is appropriate to the choice of venue
  option. For example, for the default `gh` venue for GitHub Flavored
  Markdown, the final reprex will look like:

  ----------------------------------------
  ```python
  arr = [1, 2, 3, 4, 5]
  [x + 1 for x in arr]
  #> [2, 3, 4, 5, 6]
  max(arr) - min(arr)
  #> 4
  ```
 
  <sup>Created at 2021-02-27 00:13:55 PST by [reprexlite](https://github.com/jayqi/reprexlite) v0.3.1</sup>
  ----------------------------------------

  The supported venue formats are:
 
  - gh : GitHub Flavored Markdown
  - so : StackOverflow, alias for gh
  - ds : Discourse, alias for gh
  - html : HTML
  - py : Python script
  - rtf : Rich Text Format
  - slack : Slack

Options:
  -i, --infile PATH    [...]<jupyter_text>VS Code Interactive Python Windows If you're in VS Code and `ipykernel` is installed, you similarly use the `%%reprex` cell magic with [Python Interactive windows](https://code.visualstudio.com/docs/python/jupyter-support-py). For a file set to Python language mode, use ` %%` to mark an IPython cell that can then be run. Or you can open the Interactive window on its own via "Jupyter: Create Interactive Window" through the [Command Palette](https://code.visualstudio.com/docs/getstarted/userinterface_command-palette). See [VS Code docs](https://code.visualstudio.com/docs/python/jupyter-support-py) for more info.     Isolated Namespace Note that—just like other ways of rendering a reprex—your code is evaluated in an isolated namespace that is separate from the namespace of your IPython session or your notebook. That means, for example, variables defined in your notebook won't exist in your reprex.<jupyter_code>notebook_var = 2
%%reprex --no-advertise

notebook_var<jupyter_output>```python
notebook_var
#> Traceback (most recent call last):
#>   File "/Users/jqi/repos/reprexlite/reprexlite/code.py", line 69, in evaluate
#>     result = eval(str(self).strip(), scope, scope)
#>   File "<string>", line 1, in <module>
#> NameError: name 'notebook_var' is not defined
```
{'fraction_non_alphanumeric': 0.13788300835654596, 'fraction_numerical': 0.027855153203342618, 'mean_word_length': 3.9531034482758622, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 33, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '631518', 'license': 'MIT', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1181, 'n_words': 430, 'path': 'docs/docs/ipython-jupyter-magic.ipynb', 'repo_name': 'jayqi/reprexlite', 'size': '3590'}