0

Does Jupyter Notebook possess macro functionality (similar to how Excel and Notepad++ have macro recording and playback)? I'd like to automate certain actions I perform a lot (like formatting http requests).

Example:

I paste some unformatted http request headers into a cell:

Host: somehost.com
Accept: text/html,*/*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) 
Gecko/20100101 Firefox/106.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Then a macro would take the data within the cell and format it like so:

somerequest = session.get(
    "",
    headers = {
        'Host': 'somehost.com',
        'Accept': 'text/html,*/*',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:106.0) Gecko/20100101 Firefox/106.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
        'Accept-Language': 'en-US,en;q=0.5',
        'Accept-Encoding': 'gzip, deflate, br',
        'Connection': 'keep-alive'
})

I know I can achieve this through the creation of a custom Jupyter widget but being able to execute a macro with some designated shortcut would be easier. Having such functionality available across notebooks would also be helpful. Are there any trusted Jupyter extensions I could use to achieve this?

Singularity20XX
  • 321
  • 5
  • 20
  • It is not clear what is the scope of actions you would like to automate. Is everything contained to typing into cells in a notebook, or does it involve UI interactions too? – krassowski Nov 15 '22 at 22:31
  • + Example above – Singularity20XX Nov 15 '22 at 23:02
  • I don't know of an extension that would do that. There are three snippets extensions (see https://stackoverflow.com/a/67149648/6646912) and there is jupyterlab-templates extension. One could create a macros extension following [the extension tutorial](https://jupyterlab.readthedocs.io/en/latest/extension/extension_tutorial.html) and [extension examples](https://github.com/jupyterlab/extension-examples). – krassowski Nov 16 '22 at 21:22
  • For the example given I think that mindset of most analysts/developers is "I will have a function which takes a string I paste" over "I will have a macro that will reformat what I pasted" because with function you avoid redundancy/needless verbosity and also can modify said function once if needed. – krassowski Nov 16 '22 at 21:24

0 Answers0