Getting Started With marimo Notebooks: Building a Starter Notebook & Examining a Sample Problem

Real Python · Beginner ·📄 Research Papers Explained ·1y ago

Key Takeaways

The video demonstrates how to get started with marimo Notebooks, a reactive environment that addresses the limitations of traditional linear notebooks, and how to use it to build a starter notebook and examine a sample problem using tools like MIMO, NumPy, and Python.

Full Transcript

Welcome to getting started with MIMO notebooks. My name is Christopher and I will be your guide. This course is about MIMO notebooks and in it you'll learn about interactive Python notebooks, the MIMO notebook and what makes it different, how operation order affects notebooks, how to use MIMO's UI widgets, and how to export and manage code and the results you've written within the notebook environment. The code in this course was tested with MIMO 0.14.8. If you're just playing around with the notebook, that's all you'll need. MIMO is a third party library, so it has to be installed with pip or a similar tool. And like always, best practice is to use a virtual environment. A common use of notebooks is data science. And to demonstrate that, I'll be using some other libraries as well, namely NumPy 2.3.1, Mattplot Lib 3.10.3, 10.3 and to take advantage of the environment reproducibility tools that come with MIMO UV0.7.13. I tested all this with Python 3.13.5, but any supported version should be fine. Later on in the course, I'll also be installing pandas, but the version there doesn't matter. You'll see why when you get there. Python notebooks have been around for a while. The most common one being Jupiter. MIMO is a newer notebook environment which is very quickly becoming popular. You install MIMO with pip or its equivalent and what you get is a locally hosted server. You point your browser at that server and then use the webbased interface to build and play with your notebook. A notebook is kind of like a ripple where you can type in some code and get a result. The code goes in a notebook cell. You can put multiple lines of code in a single cell or spread your code across multiple cells. The cells can also contain markdown giving you the ability to put instructions or information about what the code is doing in a readable format. As you write to the cells, the results appear in the notebook. MIMO also ships with UI components which you can associate with variables in your code. This allows you to make changes to a value with a guey widget and watch your notebook update on the fly. One of the big advantages of MIMO is the underlying file format is Python. If you're coming from other notebooks that use data formats instead, you'll see this is a big improvement. All your existing tools for merging and managing code work with MIMO files easily because they're just Python. Keeping with convention, first up, I'll write a little hello world notebook to introduce you to the world of MIMO. In the previous lesson, I gave an overview of the course. In this lesson, I'll build a hello world notebook to get you started with MIMO. A notebook is an interactive tool for running code alongside of the corresponding results. It's kind of like a ripple on steroids. A notebook has cells, kind of like a ripple prompt where you type in code, but it's also able to show visual results like a graph or a data frame as a table. Mimo is one of the newer entries in the notebook space. In case you're wondering about the name, the word is Japanese, which means I'm likely butchering the pronunciation, and it translates to ball seaweed. The little green puffs on the right here are an example. Like most notebooks, the interface is in your browser. You run the MIMO command, and it launches a local server and then attempts to launch your browser for you, pointing it at the right location. You then use the interface in the browser to write your code and interact with the tool. While you do that, MIMO keeps track of what you're doing by saving it in a Python file, which you can then treat much like any other code, sharing it, uploading it to a repo, merging it, etc. If you're coming from the Jupyter world, that's a really big deal. If you're new to notebooks, just know that other tools typically use a data format instead, which means sharing and merging can sometimes be problematic. Let me open up a terminal and create a new notebook. I've already installed MIMO in a virtual environment with pip install. All I have to do now is run the Mimo server that comes with the third party package. The MIMO command has a bunch of subcomands and those are used to create or edit a file. You use the edit command passing in the name of a file to get started. Edit works for both creating a new file and editing an existing one. Normally, MIMO launches your browser for you, but through the magic of video editing, I've prevented that. If something goes wrong when it attempts to launch your browser, you can simply grab this URL that it's showing here and paste it to get started. Now, let me switch to the browser. This is the MIMO interface. The heading here shows you the file that has been created. At the moment, there isn't anything inside the notebook itself. This is a cell. MIMO provides you with an empty cell for your code. It even suggests you might want to import the MIMO module. Instead, I'm going to click in the cell and type something different. Notice here that as I type, buttons show up on the right hand side. The play button is yellow to tell me that this cell has not been executed yet. I could run it, but let me type in some more code first. As I type, the notebook prompts for autocomplete. Now, let me run the cell. On a Mac, there's a shortcut to run the cell. Command enter. If you're not on a Mac, you can see the shortcut that works for you when you mouse over the play button. Now that I've clicked play, the cell is split into two parts. The code I typed in and the corresponding output. To get another cell, I click the plus sign on the left hand side, which only shows up when my mouse is over the cell. At this point, I might grumble a bit about discoverability in user interfaces, but this habit is all over the web, and I should just give up that battle. Now that I've got another cell, I can do what I came here for. I hit command enter that time, and you see the result immediately. Notice at the bottom here, there are buttons for content type. If I click the markdown button, it will automatically add a new cell using that type. Actually, it added two cells. The first time you use a markdown cell, the notebook automatically imports the MIMO module if it isn't already there. In the bottom right hand corner here of the cell, you can see its type and that it's a markdown cell. Let me type some markdown. I'm consistent at least. Hello world. This is better than a regular old comment in your code because it's like a little miniword processor. It allows you to write prettier things to the screen. In a later lesson, I'll create a dashboard using just these features. There's another way to produce markdown. You can also use the MD function in the MIMO module. Let me scroll down a bit and add a cell. The main reason to use the MD function instead of just using a straight markdown cell is you can embed values from your Python using things like an F string as I've done here. Since I'm done, I can click the save button over here on the right hand side. I don't actually need to this time. It's done it automatically, but it's something to keep an eye on in case something didn't run. Once you've got it saved, you use the big red button to close the service. It'll prompt you to make sure and then shut it down. Once you shut it down, you'll notice back in the terminal that MIMO shows you a little goodbye message. Let's take a quick look at the resulting Python file. And here it is. Like any good Python file, it imports its modules at the top. The generated width value tells Mimo what version of the module created the file in case it gets loaded into the system again. Then the key part to how this code works is the instantiation of the MIMO app. This instance then gets used as a decorator to a nameless function for each cell. Remember our first cell? This is it. Let me scroll down just a bit. You'll recall that the first chunk of markdown I wrote used the built-in markdown cell. Behind the scenes, the server put that inside of the MD call. And this second chunk of markdown is the MD call that I wrote manually. Okay, that's the quick tour. Next up, I'll use a notebook to solve a problem. In the previous lesson, I gave you a quick tour of a Mimo notebook. In this lesson, I'll show you a more realistic problem, something you might actually do with MIMO and Numbai together. Notebooks generally get used for experimentation and quick problem solving, especially when visualization is helpful, but I'll come back to that in a later lesson. They tend to have less code in them than a full-size program, but they don't have to be one-off scripts. If you structure them well, you can always bring them back up, change a few variables, and get a new answer. Consider the math problem of solving these two equations. Let's create a notebook that does this. At the top of the notebook, I'm going to put some markdown documenting what I'm doing. And then inside a Python cell or two, I'll use the solve method in NumPy's linal module to get a solution. With a little more markdown, I can print out a result. If you're coding along, start MIMO with a new file and head to your browser to write the notebook. I'm calling mine simq.py. Here I'm in the new notebook that I called simq.py. Seeing as I know I'm going to use the marrimo module. This time I'm going to click in the cell and tab complete the suggested import. I'm going to make sure to run the cell so that the import happens. This is particularly helpful because it means the things that have been imported are available to the autocomplete. Now I'll add some markdown. Remo supports one of the richer variations on Markdown. I'm not sure if it's 100% GitHub Markdown compatible, but it does support using latte math equations like GitHub Markdown. As an aside, all the way through grad school, I and every prof I worked with pronounced Latte as Latex, as that's the way it's spelled. It wasn't until recently I learned I was wrong all these years. If you're not familiar, Latte is a type setting tool created by Leslie Lamport, which is built on top of tech, a similar type setting tool created by Donald New. The tech part is an acronym for Greek letters meaning skill or technique because well this came out of academia and so of course it does. Anyhow, you can use latte inside of markdown to denote math equations and make your output look professional. To write these kinds of statements you surround them in dollar signs. See, pretty math. Not too important with simple linear equations like this, but if you have functions, square roots, integrals, or the like, this is the way to go. Now that I've got a bit of documentation, I'll write some Python to actually solve the equations. Let me add a cell. Normally here, I might just keep writing code, but as I mentioned, the autocomplete feature only sees what is in the environment. Since the import doesn't happen until I run the cell, it's good practice to run the cell so that I can do less typing later. Command enter. The equation solver in numpy that I'm going to use is called solve and it takes two numpy arrays. The first argument is an array of arrays containing the coefficients of the two equations. And the second argument is an array of values representing the right hand side of the equations. Scroll down a bit and add a cell. See how the type ahead is helpful. Now command enter and nothing. There's no result being displayed here because I haven't asked it to do so. I'm going to add another cell. And this time I can see the results. Normally in a notebook you don't use print. You just use a markdown instead. But I'm looking into the future knowing that this line is going to be useful in a later lesson. So I'm going to keep it here. Let's also do this the more normal way. And there you go, a prettier version of the same content. Now that I have a notebook, I can use it to solve different equations just by editing the values in the cells. Let me scroll back up here. and now I'll rerun the cells. Scrolling back down and you can see the new answers. Note how both the print and the fstring markdown got updated. MIMO tracks the relationships between the cells and knows to refresh those that are dependent on the changes I made. You've just seen how MIMO handles changes. It isn't quite the same as a regular Python script, and it's definitely different from Jupiter. In the next lesson, I'll do things out of order so that you can see just how MIMO calculates cell dependencies.

Original Description

This is a preview of the video course, "Getting Started With marimo Notebooks". marimo notebooks redefine the notebook experience by offering a reactive environment that addresses the limitations of traditional linear notebooks. With marimo, you can seamlessly reproduce and share content while benefiting from automatic cell updates and a correct execution order. Discover how marimo’s features make it an ideal tool for documenting research and learning activities. This is a portion of the complete course, which you can find here: https://realpython.com/courses/getting-started-with-marimo-notebooks/ The rest of the course covers: - Digging Into Operation Order - Adding Interactive UI Components - Sandboxing - Exporting Notebooks
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Real Python · Real Python · 0 of 60

← Previous Next →
1 A better Python REPL – bpython vs python interpreter
A better Python REPL – bpython vs python interpreter
Real Python
2 Introducing large-type.com – A Utility Website
Introducing large-type.com – A Utility Website
Real Python
3 Reading Hacker News Without Wasting Tons of Time
Reading Hacker News Without Wasting Tons of Time
Real Python
4 Forward References and Python 3 Type Hints
Forward References and Python 3 Type Hints
Real Python
5 Using Sublime Text as your Git Editor
Using Sublime Text as your Git Editor
Real Python
6 Python Code Linting and Auto-Complete for Sublime Text
Python Code Linting and Auto-Complete for Sublime Text
Real Python
7 Make your Python Code More Readable with Custom Exceptions
Make your Python Code More Readable with Custom Exceptions
Real Python
8 Write Better Tests with Sublime Text's Split Layout Feature
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
9 How to Use Sublime Text from the Command Line
How to Use Sublime Text from the Command Line
Real Python
10 Rename Variables with Multiple Selection in Sublime Text
Rename Variables with Multiple Selection in Sublime Text
Real Python
11 Sublime Text Settings for Writing PEP 8 Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
12 Write Cleaner Python with Sublime Text's Indent Guides
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
13 Sublime Text Whitespace Settings for Python Development
Sublime Text Whitespace Settings for Python Development
Real Python
14 Function Argument Unpacking in Python
Function Argument Unpacking in Python
Real Python
15 Python Code Review: Debugging and Refactoring "Conway's Game of Life" +  Automated Tests
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
16 Using "get()" to Return a Default Value from a Python Dict
Using "get()" to Return a Default Value from a Python Dict
Real Python
17 A Python Shorthand for Swapping Two Variables
A Python Shorthand for Swapping Two Variables
Real Python
18 Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
19 Click & Jump to Test Failures from the Command Line (iTerm2)
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
20 Setting up Sublime Text for Python Developers
Setting up Sublime Text for Python Developers
Real Python
21 Sublime Text + Python Guide Overview
Sublime Text + Python Guide Overview
Real Python
22 Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
23 Type-Checking Python Programs With Type Hints and mypy
Type-Checking Python Programs With Type Hints and mypy
Real Python
24 A Shorthand for Merging Dictionaries in Python 3.5+
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
25 Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
26 My Python Code Looks Ugly and Confusing – Help!
My Python Code Looks Ugly and Confusing – Help!
Real Python
27 Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
28 Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
29 Programmer Portfolio – Example and Walkthrough
Programmer Portfolio – Example and Walkthrough
Real Python
30 How to Get Your 1st Speaking Gig at a Tech Conference
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
31 How to Build Your Public Speaking Skills as a Developer
How to Build Your Public Speaking Skills as a Developer
Real Python
32 The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
33 Setting up Sublime Text for Python Developers – Lesson #1
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
34 Cool New Features in Python 3.6
Cool New Features in Python 3.6
Real Python
35 "is" vs "==" in Python – What's the Difference? (And When to Use Each)
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
36 Emulating switch/case Statements in Python with Dictionaries
Emulating switch/case Statements in Python with Dictionaries
Real Python
37 Python Function Argument Unpacking Tutorial (* and ** Operators)
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
38 What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
39 A Crazy Python Dictionary Expression ?!
A Crazy Python Dictionary Expression ?!
Real Python
40 String Conversion in Python: When to Use __repr__ vs __str__
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
41 Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
42 Optional Arguments in Python With *args and **kwargs
Optional Arguments in Python With *args and **kwargs
Real Python
43 Python Context Managers and the "with" Statement (__enter__ & __exit__)
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
44 Installing Python Packages with pip and virtualenv / venv
Installing Python Packages with pip and virtualenv / venv
Real Python
45 "For Each" Loops in Python with enumerate() and range()
"For Each" Loops in Python with enumerate() and range()
Real Python
46 Python Code Review: LibreOffice Automation and the Python Standard Library
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
47 Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
48 Python Tutorial: List Comprehensions Step-By-Step
Python Tutorial: List Comprehensions Step-By-Step
Real Python
49 Leveraging Python's Implicit "return None" Statements
Leveraging Python's Implicit "return None" Statements
Real Python
50 What's the meaning of underscores (_ & __) in Python variable names?
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
51 Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
52 Writing automated tests for Python command-line apps and scripts
Writing automated tests for Python command-line apps and scripts
Real Python
53 How to find great Python packages on PyPI, the Python Package Repository
How to find great Python packages on PyPI, the Python Package Repository
Real Python
54 Immutable vs Mutable Objects in Python
Immutable vs Mutable Objects in Python
Real Python
55 PyPI vs Warehouse, the Next-Generation Python Package Repository
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
56 pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
57 My Experience at PyCon 2017 in Portland
My Experience at PyCon 2017 in Portland
Real Python
58 Pylint Tutorial – How to Write Clean Python
Pylint Tutorial – How to Write Clean Python
Real Python
59 "Reverse a List in Python" Tutorial: Three Methods & How-to Demos
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
60 Python Refactoring: "while True" Infinite Loops & The "input" Function
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python

This video teaches how to get started with marimo Notebooks and use it to build a starter notebook and examine a sample problem. It covers the basics of MIMO, including creating and editing notebooks, using UI components, and solving equations with NumPy. By the end of this video, viewers will be able to create and share their own notebooks and reproduce research papers.

Key Takeaways
  1. Install MIMO using pip
  2. Create a new notebook using the MIMO command
  3. Edit a file using the MIMO command
  4. Run a cell in the notebook
  5. Add a new cell to the notebook
  6. Use the autocomplete feature to suggest imports and variables
  7. Add markdown to denote math equations
  8. Write Python code to solve the equations
  9. Run a cell to import necessary modules
  10. Use numpy's solve function to solve a system of linear equations
💡 MIMO notebooks can be used to write code and markdown, with features like autocomplete and output display, making it easier to reproduce and share research papers.

Related Reads

Up next
Welcome to the Next Temperamental Era
Charles Schwab
Watch →