Podcast Lookup

58 - Python Memory Graph with Bas Terwijn

The Python Show

  • December 2, 2026
  • 24 min
Episode page
About this episodeOn this week's Python Show, we have special guest Bas Terwijn, author of memory_graph, a Python package similar to Python Tutor that you…

On this week's Python Show, we have special guest Bas Terwijn, author of memory_graph, a Python package similar to Python Tutor that you can run locally on your machine and use for much larger Python applications than Python Tutor can support.

Learn more about memory_graph here:

* memory_graph README

* memory_graph teaching examples

* memory_graph on PyPI

* memory_graph online web tool



Get full access to The Python Show at www.pythonshow.com/subscribe

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

58 - Python Memory Graph with Bas Terwijn

00:00—
  1. Speaker 4

    Welcome to a brand new episode.

  2. Speaker 1

    Mike Driscoll, The Python Show. [music]

  3. Speaker 4

    Hello, and welcome to The Python Show. I'm your host, Mike Driscoll. And today I have the honor of having my new friend, Boss, on the show to tell us about one of his cool projects, Memory Graph. Welcome to the show, Boss.

  4. Speaker 2

    Thanks, Mike, for the invitation.

  5. Speaker 4

    Yeah, it's great to have you. So I'd like to start out the show by just having my guest tell us a little bit about yourself and what you're doing with Python.

  6. Speaker 2

    Yeah, so I'm an educator at the University of Amsterdam in the Netherlands. There I teach many courses in the program Artificial Intelligence. It's a bachelor program. So these are students that just got started at university. And I'm helping them get the grips on Python and also some math and some machine learning applications.

  7. Speaker 4

    Nice. Do you feel like Python's like the primary language or do you have to dive into other languages too?

  8. Speaker 2

    Python is the main language for us. We also do a little bit of Prolog because artificial intelligence, Prolog used to be a popular language. So we still want to do some symbolic AI also. But the main language is really Python.

  9. Speaker 4

    Interesting. I wasn't sure if people had switched to like Rust or some other language recently or not.

  10. Speaker 2

    In the informatics department, they do many other languages, but for Bachelor of Artificial Intelligence, we stick to Python mostly. There's a little bit of C++ later for GPU programming, but Python is the main language.

  11. Speaker 4

    That's good to know. I'm always curious what they're teaching, especially around AI, because it's such a popular topic right now. Maybe you could give us some background into how you got into programming.

  12. Speaker 2

    Yeah, that's a long time ago. I started early. A friend of mine had a computer, really interesting toy. So it was at first playing many games. But later we figured out you could cheat in these games by sort of writing a little program. And slowly, step by step, we got sort of an idea of what programming is. And then, yeah, we liked it. We made our own games at some point, text adventures, that sort of really simple things. And yeah, I really liked it. So I chose it later on for higher education.

  13. Speaker 4

    Nice. Nice. So did you go into like the engineering side or is it more computer science? So many degrees now.

  14. Speaker 2

    Yeah, I did really informatics. So computer science, really about programming C and in Java or then programming languages, software design, databases, that sort of topics.

  15. Speaker 4

    Okay. Okay. I was just curious because I don't get to talk to people that are overseas. I was wondering how different your education would be from like what we get taught here in the US. It sounds very similar. Yeah, I think so.

  16. Speaker 2

    Yeah. This was all like pre-internet. There was internet, but the average person didn't have an internet connection. Yeah. And of course, way before AI and other big steps.

  17. Speaker 4

    But That kind of brings up a side question then. How did you get into AI if that wasn't what you were trained in?

  18. Speaker 2

    After I finished my education at Hogeschool Utrecht, I did a... Graduation project at the University of Amsterdam. Writing something with neural networks was kind of new for me. Later on, I got a position there to help students program robots. So this was a robot football competition. Internationally, universities would compete. And yeah, later I got more and more into AI applications, but I'm not an AI expert, although I teach it at like the first or second year bachelor level.

  19. Speaker 4

    Yep. Well, I mean, if you're teaching it, I feel like you're more of an expert than a lot of people.

  20. Speaker 2

    Hopefully, but many of my colleagues are the real experts. So I also ask them questions if I get stuck.

  21. Speaker 4

    Yep. So do you have any favorite Python libraries or packages that you use?

  22. Speaker 2

    Yeah, there are many. Of course, my own package. But I can choose that, of course. I guess NumPy is the one I use the most, especially now I'm teaching again in this machine learning course. And then NumPy is the one we use the most.

  23. Speaker 4

    So you don't use stuff like SciPy or... What is it? Scikit-Learn or stuff like that.

  24. Speaker 2

    No, not at this level of the course. So later on, students will be taught more advanced tools or PyTorch, I think. But in this course, we stick with the basics still. So we want students to program with matrices low level. You really have an idea what's going on instead of just calling some API and having all the things done for them. That makes sense.

  25. Speaker 4

    So you alluded to your own package, I believe it's called Memory Graph. Maybe you could tell us about its origins and what it's all about.

  26. Speaker 2

    Yes, yes. Yeah, I wrote it as a sort of, it was inspired by Python Tutor, which is a really common tool in Python education. And this is about visualizing how Python works internally. So Python uses reference semantics. So every variable is a reference to a value. And if you assign one value, If you change one variable to another, basically you have two references pointing to the same value. So if you change one of the variables, you also change the other. And this can be confusing, especially for people coming from a A value semantics language like C, C++. Most of the time, if you write A is B, then automatically a copy is made. But in Python and many other languages, you get aliasing or two references pointing to the same value. This can be confusing for students. And Python Tutor is a tool that's, I think, 15 years old or something. It's really good at visualizing these references so students really get to understand what's going on internally. Yeah, my memory graph tool is inspired on that because Python Tutor has some limitations that I wanted to get rid of and we did. So now, yeah, you don't only, so Python Tutor can only run in a browser with really small programs. It's a really short runtime, whereas the Memory Graph tool runs locally, so you have full control over what happens, so you can run any program you want.

  27. Speaker 4

    Is that the primary difference, or are there other differences too?

  28. Speaker 2

    Your artificialization is different. You can also ask for user inputs. There are more limitations we got rid of.

  29. Speaker 4

    Okay. Nice. What kind of output does it put out for those who can't see it?

  30. Speaker 2

    Yeah, you can choose. So PDF is the default, but you can generate PNG or SVG or many other image formats that just give you a graphical representation of all the And that includes the call stack. So if you call different functions, each function call has its own stack frame of local variables. They all get shown with the references. So students get a good understanding of what's going on.

  31. Speaker 3

    Nice.

  32. Speaker 4

    That sounds really difficult to visualize conceptually, but I know I've taken a look at your product and I think it looks really cool. So I'm going to tell my listeners, go check it out because it sounds weird when we're just talking about it, but if you see it in action, it makes a lot of sense.

  33. Speaker 2

    And it used to be that the teachers would draw these on the blackboard. This is also what Python Tutor also references a lot. So instead of drawing it now by hand as a teacher, show your students how the internals work. The tool does it for you and you can just debug your software using the visualization. And yeah, you don't have to rely on your teacher to make the drawing fun.

  34. Speaker 4

    Yeah, so will that teach the students where a bottleneck is, kind of like a profiler kind of thing?

  35. Speaker 2

    No, a profiler really focuses on the performance indeed, but it is more on how the memory is organized. Okay. So, yeah.

  36. Speaker 4

    Well, there are memory profilers, so I was kind of wondering maybe it's kind of like that, but in a visual way for the student to look at.

  37. Speaker 2

    Yeah, but if you say profiler, then I'm thinking about counting how much time a function takes, that sort of thing. And that's not what memory graph is doing. So memory graph gives at one point in time the graph of how all

  38. Speaker 1

    the data is laid out, you can say, in a graph.

  39. Speaker 2

    Okay. So it's not about timing, but it's about

  40. Speaker 1

    data structures.

  41. Speaker 2

    Yeah.

  42. Speaker 4

    Okay, cool. That clears that up. So when you're working on this kind of a product, what kind of lessons were you learning? What new things did you learn? Whenever I do something brand new, I'm like, this is going to be easy, or this is going to be really hard, and I learn all kinds of fun new things while I'm working on it.

  43. Speaker 2

    You know, I did learn a lot. And this was for me the first project that got really attention from users, because I had a lot of software before, but it was usually a research project. So only for internal use, maybe one or two other people would play with my software to do their research. But now with this software, the user group is growing. We're getting close to 100,000 users, although it's a bit hard to measure. But yeah, we get traction. Many users are enthusiastic. So that was really new for me. And also writing public software, because you publish an API. And later on, if you decide maybe something should be changed, You really have to consider if you want to do that because people already might be working on this API. Yeah. Yeah. So, yeah, that was really new for me.

  44. Speaker 4

    You don't have to share this if you don't want to, but I'm just curious. Do you find that most of your users are from the Amsterdam area or are they all over the world or?

  45. Speaker 2

    The most are from America, but it might also be that there are many bots from America, like indexing the internet or something. But anyway, there's a large group from the USA. Also from India a lot, because it's a large country. And also the south of India is really into programming, mainly the south, I've learned. And also Europe, my own country, because many people see my LinkedIn page. But Germany, France, United Kingdom, these are the main countries.

  46. Speaker 1

    Brazil is getting there.

  47. Speaker 4

    Australia also. Yeah, it sounds very similar to my demographics when I look who reads my blog. Those are like the top ones typically.

  48. Speaker 3

    So cool. That's interesting. Let's see.

  49. Speaker 4

    Are there any other differences between memory graph and Python tutor that we haven't covered yet?

  50. Speaker 2

    To make a little list, we can walk through them in one second. Yeah, a quick overview is this Python Tutor only allows you to make one file and with memory growth you can have multiple files. The amount of memory you can take is limited because if you send a Python program to Python Tutor, it runs your program on a remote server and then sends you the results back. So for them, it would be a problem if people would send in used programs because then they would have servers running a lot of programs, whereas memory graph runs locally on your own computer. So it's not limited in any way by a limit on memory use or CPU use. Memorycraft also only use built-in types because in this remote server, not all the packages are installed there. Reading and writing to files is difficult with Python Tutor or maybe not even possible. Reading command line arguments. And also memory graph can be used quite nicely in IDEs, for example, Visual Studio Code and PyCharm. You can also use it in Jupyter Notebook or IPython or other environments. And in Python, Tutor is really only available on a web interface.

  51. Speaker 4

    Okay.

  52. Speaker 2

    But don't get me wrong, it's really a nice tool. Python Tutor is used for more than 15 years now. Many educators know it and use it a lot. It made a really big difference in learning people how to program, especially when it comes to references, aliasing, difference between shallow and deep copy, all kinds of things that are really kind of difficult to explain in words. But if you make an image, it's much easier for students to understand what's going on and to debug their own programs when they see things are not correct.

  53. Speaker 4

    Yeah, I've used it a little bit, but I haven't used it for teaching purposes just to kind of play around with. So I'm looking forward to playing with your product more or your package more because like you said, it has all this nice stuff I can run locally and I can trade out some of my My bigger programs, see what happens.

  54. Speaker 2

    Yeah, do let me know if you have any feedback. There's all a problem if you run it on really big programs because then the graph gets really big. And a really big graph, yeah, it's no longer very readable. So also for Python Tutor, this only works really nicely on small programs. Although in memory graph, I have built in some tricks where you can sort of reduce the graph. If you know where you want to search, then you can sort of take out parts of the memory you're not interested in visualizing. But I haven't come up with a good user interface to do this yet. So that can only be done programmatically. And that's not the best interface. So it's something to do still.

  55. Speaker 4

    Yeah. I'm just curious, have you, have you tried using memory graph with like any kind of the, any of the GUI frameworks in Python, like just a simple like tkinter or DBX Python app, does it work with those at all?

  56. Speaker 2

    Yeah, but often the graph really explodes because there is too much memory to visualize. But if you kick out the stuff that you're not interested in, you could come up with a useful way of debugging code.

  57. Speaker 4

    Okay. I'm just curious how that would work if it's... Yeah, I'll just try it. Okay.

  58. Speaker 2

    Yeah, and there's two ways to use MemoryGraph. One is locally on your machine, and I also have built a web interface because it's just easier for students to get it installed. You don't have to install anything. Just click a link and you can run MemoryGraph. And there, because it's in a web interface, there you cannot use tools like TKinter or PyCharm or other things. Oh, yeah. So there we are still limited, like Python Tutor is also in that sense.

  59. Speaker 1

    But you can, if you run it locally, you can graph any Python program you want

  60. Speaker 2

    and also define how you want things visualized if you really want to get into the details.

  61. Speaker 4

    Yeah. Nice.

  62. Speaker 3

    That's cool.

  63. Speaker 4

    Let's see. Are you working on any other projects related to this tool or do you have any other tools you'd like to highlight that you've been working on?

  64. Speaker 2

    I would like to expand the visualization to other languages. So now it's only Python. And Python Tutor is also strong in the sense that they don't only cover Python. We can also use it for C, I think Java, JavaScript, and I probably forget one language. At least it does a couple of these languages. So I would also like to try to expand my way of doing it to languages like C and C++. These are the first on my list, but maybe other languages in the future too.

  65. Speaker 4

    OK.

  66. Speaker 2

    But they're keeping me busy also at university for courses that I'm preparing. So the time is limited.

  67. Speaker 4

    Yeah. Are you planning to add this to your current memory graph package? Or are they going to be like their own separate packages for each language?

  68. Speaker 2

    Yeah, I didn't decide yet, but I already noticed that you want to visualize things a little differently because there's just different ways of thinking about memory there.

  69. Speaker 4

    So probably it will be a little different

  70. Speaker 2

    in how we visualize things in Python. I haven't really got into the details there yet.

  71. Speaker 4

    Well, still, that sounds really exciting. I'm curious to see how that turns out. While I don't write in C and C++, I still am exposed to that code base. The code base is with the use it a lot. So it'd be kind of fun to be able to visualize it more and understand what's going on under the covers.

  72. Speaker 2

    Yeah, no, definitely. And then with Python Tutor, you can do this now already, although small programs that you run on the web server, but you can have a feel of what's possible there at least.

  73. Speaker 4

    Nice, cool. That's great. Well, I usually like to ask if you have any non-technical hobbies that you'd like to expound on. Tell us what you do in your spare time, if you have any.

  74. Speaker 2

    Oh, yeah, yeah. I have some spare time, definitely. I like to do some road cycling, only now it's winter, so I haven't really kept that up in the last months. But that's one of my hobbies. I also play a little bit of chess, not at any level, seriously, but just for fun with friends sometimes. Oh, yeah. I'm watching a lot of YouTube. Is that a hobby? Probably.

  75. Speaker 4

    A little bit. When you do road cycling, do you go long distances, or are you talking about neighborhood biking?

  76. Speaker 2

    Yeah, I did some long distances. 200 kilometers is now my longest, but

  77. Speaker 1

    that's a bit extreme.

  78. Speaker 2

    But a couple of hours would be reasonable.

  79. Speaker 4

    Yeah. Well, you know, when people talk about, I go for a run, sometimes that means they just run around the block or, you know, they ride to the post office or back. And other people mean, you know, they ride all day and that's what they do for their weekends. You know, I'm just curious what that meant.

  80. Speaker 2

    Yeah. No, I used to ride to work often, but that's an hour to and back again. But for weekend rides, usually two or maybe three hours occasionally. That's sort of what I do.

  81. Speaker 4

    Wow, that's amazing. That's something I aspire to do someday.

  82. Speaker 2

    But cycling is a great sport because you just sit. It's a seated sport like chess. You can pedal as hard as you want. So you mentioned running. I also did some running before. And that's much harder in the sense that you cannot take it easy for. It's harder to take it easy to recover a little bit, let's say.

  83. Speaker 4

    Yeah. Yeah, I understand. Well, I think we ran out of questions, so I just want to thank you so much for being on our show today, and I hope a lot of my viewers and our listeners will come and check out your product, and hopefully it'll continue to grow.

  84. Speaker 2

    Yeah, thanks a lot. Thanks for having me.

  85. Speaker 4

    Yeah, it was great to have you.

  86. Speaker 1

    Follow on Apple Podcasts. Mike Driscoll, The Python Show. [music]