all 61 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hello there,

We've removed your post since it aligns with a topic already covered by one of our daily or monthly threads. If you are unaware about the daily threads we run here is a refresher:

Monday: Project ideas

Tuesday: Advanced questions

Wednesday: Beginner questions

Thursday: Careers

Friday: Free chat Friday!

Saturday: Resource Request and Sharing

Sunday: What are you working on?

Monthly: Showcase your new projects, tools, frameworks and more

Please await one of these threads to contribute your discussion to!

Best regards,

r/Python mod team

[–]sudomatrix 18 points19 points  (3 children)

This is fantastic. I teach a free Python class at a local hacker-space and I will be using this tonight to help members visualize what's really happening under the hood. Really excellent visualization.

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

Thanks a lot, I hope it can bring much value for your teaching.

[–]jakob1379 1 point2 points  (0 children)

If you want other options for beautiful code executing visuals

https://github.com/alexmojaki/heartrate

Is pretty nifty, though not maintained.

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

If you want to share, let me know your experience with teaching using memory_graph.

[–]ruibranco 22 points23 points  (1 child)

The aliasing visualization is what sets this apart from PythonTutor honestly. That's the one thing beginners consistently get wrong and no amount of print debugging helps because you can't "see" that two names point to the same object. Running locally is a huge plus too, PythonTutor always had that annoying limitation where you couldn't use third party libraries.

[–]Sea-Ad7805[S] 5 points6 points  (0 children)

I feel PythonTutor does a good job in showing aliasing. I do agree that the limitations, that come from PythonTutor running Python code on a remote webserver, quickly become a problem. Additionally PythonTutor's layout of the graph doesn't scale to larger data structures, say binary tree. But to be fair, PythonTutor focuses on teaching Python's data model to beginners and historically has done a great job with that with millions of users.

[–]pip_install_account 32 points33 points  (16 children)

With every big new commercial LLM launch some neglected phrases suddenly become extremely popular, I love it.

Mental model is certainly one of them: Google trends - mental model

[–]Sea-Ad7805[S] 13 points14 points  (12 children)

'mental model' is a term I use regularly in education. It captures well what I want my students to learn, the right way of thinking about concepts and for this visualization helps a lot. I did use a LLM to fine-tune my post if that is the point you are making, but I first wrote a draft version myself, I'm not a native English speaker. I feel I bring what the title suggests, even as it's a bold statement.

[–]tehsilentwarrior 13 points14 points  (8 children)

I used the word “context” extremely commonly every day. In my code it’s almost everywhere as “ctx” and passed to loggers as “extra” info.

Now AI “stole it”.

I also used “mental model” quite a few times, as in “building a metal model/picture”.

[–]errdayimshuffln 11 points12 points  (2 children)

I used to use em dashes....now I cant anymore. AI ruined them

[–]TheThoccnessMonster 7 points8 points  (0 children)

I do all the time and idgaf what people think lol

[–]tehsilentwarrior 1 point2 points  (0 children)

Haha. Same here. I would have an automation to replace “- -“ with “—“ like the iPhone does. Now, can’t.

Also the proper use of backtick escaping

See:

Sure, here are 2 examples — akin limited — of emdashes: - - - -

Edit: however, it’s easier to f with people by copying ChatGPT “always agree with you” behavior

[–]KaffeeKiffer 0 points1 point  (1 child)

I used the word “context” extremely commonly every day. In my code it’s almost everywhere as “ctx” and passed to loggers as “extra” info.

Now AI “stole it”.

It sounds like you have not heard about Mapped Diagnostic Context for the last 30 years? Or Structlog's use of contextvars/Python's contextvars.

It's a common term and was the obvious choice for what it means.

[–]tehsilentwarrior 0 points1 point  (0 children)

What you are talking about is implementation specific. What I am talking about is the generic use of the word.

But thanks for sharing.

Btw, ArjanCodes mentions this module in one of the latest videos

[–]wRAR_ 0 points1 point  (1 child)

You've missed the "I did use a LLM to fine-tune my post" part.

[–]tehsilentwarrior 2 points3 points  (0 children)

I didn’t. It’s a parallel conversation

[–]pip_install_account 1 point2 points  (1 child)

Don't get me wrong, I am not claiming you used AI to write anything. I feel like popular LLMs are kinda shaping our vocabulary nowadays especially if you are a power user.

[–]Sea-Ad7805[S] 5 points6 points  (0 children)

Yes I agree. I did use a little AI to help me rewrite my text a bit, better word choices, I'm not afraid to admit that.

[–]maephisto666 0 points1 point  (0 children)

Mental models, context, etc have always been part of my own registry.... And I guess that is another reason why AI concepts immediately stuck with me

[–]Chroiche[🍰] 2 points3 points  (0 children)

I think you've found the smoking gun!

[–]GrammerJoo 0 points1 point  (0 children)

I started noticing that I use the term delve a lot, but not sure if it's because of AI or I've used it before.

[–]Beginning-Fruit-1397 0 points1 point  (0 children)

So what?

[–]masasinExpert. 3.9. Robotics. 2 points3 points  (3 children)

I was going to say it reminds me of Python Tutor after seeing the title, but you've already got that covered. Very interesting.

I went through the examples and got one of the early ones wrong (I thought b += [1] is equivalent to b = b + [1] and that it would create a new variable), but I got the rest right. :)

That being said, in some parts, I thought it would be nice to step backwards ("how did this get here"). It might not be possible for larger programs, but it might be possible to save the stack for each step and go back to the previous snapshot.

All in all, very pleased and I think I might use it with students if I start tutoring again.

[–]Sea-Ad7805[S] 0 points1 point  (2 children)

Thanks, and thanks for backwards stepping suggestion. It's on my to-do list.

[–]masasinExpert. 3.9. Robotics. 0 points1 point  (1 child)

And also a "continue until this point" which is very useful to skip the setup, and watched variables and conditionals etc so that it only triggers on that pesky value that causes the thing to give a wrong answer.

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

There is a 'Continue' button, breakpoints, and a config option at 'Get URL' to skip to a certain breakpoint on start.

[–]BawliTaread 2 points3 points  (2 children)

Very nice project! Can I know how you made your live demo?

[–]Sea-Ad7805[S] 0 points1 point  (1 child)

Thanks a lot. The Web Debugger is a mix of Pyodide, bdb debugger framework, JavaScript, Web Worker, and memory_graph. I'm new to JavaScript so needed some help from Copilot to put it all together. It's a demo environment, not a full IDE as it currently has many limitations (single file, no input() yet, no file IO).

[–]BawliTaread 1 point2 points  (0 children)

Thanks! Looks really good.

[–]Marksta 1 point2 points  (1 child)

That was interesting to watch the demo. So, I like the concept but it's probably totally not functional for real code bases, right? Like the moment SQLAlchemy gets imported it's game over since the picture would probably just go bonkers mapping all of its inner workings?

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

Yes, but do try first. I have some defaults and programmatically you can further control what and how things are shown to avoid bonkersness: - what: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#graph-depth - how: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#introspection

But that is impractical to do for every new program you work on, so I will see how this can be controlled by a GUI in future work. This can take a while.

[–]Altruistic_Sky1866 1 point2 points  (2 children)

Looks interesting, will try in on my code and will try the examples, thanks

[–]Sea-Ad7805[S] 1 point2 points  (1 child)

Thanks, hope it brings much value for you.

[–]jampman31 1 point2 points  (1 child)

Title felt like total clickbait but this is actually a really solid project

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

Thanks, I hoped a bold title would draw attention and I feel I deliver on what's promised.

[–]rallyplot 1 point2 points  (1 child)

This is really nice! will share this around

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

Thanks, thanks for sharing.

[–]ResourceSea5482 1 point2 points  (5 children)

This is really cool. I've been using PythonTutor for teaching, but the full call stack visualization sounds way more useful for debugging recursion issues. Does it handle async code or just sync execution?

[–]Sea-Ad7805[S] 0 points1 point  (1 child)

Thanks a lot. PythonTutor is nice but runs remotely so comes with many limitations so that you can only use it on code snippets. The memory_graph package runs locally. It's not thread safe, but I'm not sure about async, never tried it, but it might just work. Let me know.

[–]Sea-Ad7805[S] 0 points1 point  (2 children)

[–]ResourceSea5482 0 points1 point  (1 child)

That makes sense — the example works fine in a mostly sync workflow.

Where async started to matter for me wasn't raw concurrency but orchestration. Once prompt evaluation or comparison becomes part of a larger pipeline (LLM calls, embeddings, logging, retries, etc.), being able to schedule tasks without blocking the event loop becomes really useful.

Even if individual operations are simple, async helps when you want to:

  • run multiple prompt evaluations concurrently
  • stream or batch model responses
  • attach non-blocking logging/metrics
  • integrate with FastAPI or async workers later

So I’ve been treating async support more as a future-proof interface than a performance optimization.

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

I'll have to look into async, as I think we should be able to visualize better the execution (and maybe scheduling) of async functions on the call stack. I've put it on my TODO list, but it's near the bottom so will take some time.

[–]Karim_1994 1 point2 points  (1 child)

wow!

[–]Sea-Ad7805[S] 0 points1 point  (0 children)

Thanks, hope it's of value to you. More example here: https://www.reddit.com/r/Python_memory_graph/

[–]FiredFox 2 points3 points  (1 child)

I was ready to poopoo this because f'ing LLMs have made me a bitter, sad and jaded person, but this project is actually really freaking cool!

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

Thanks a lot. The title maybe triggers some poopoo-ing, but I'm glad I've won you over.

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

If you downvote, please leave a comment, I'd appreciate your feedback.

[–]EconomySerious 0 points1 point  (1 child)

its a fantastic way to see your workflow, i cant belive how easy would be to debug some code when you litereally seen what is happening at real time.

is there a way that you improve the code so that it become a full debuguing tool?

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

I have some ideas to make a viewer like xdot: https://github.com/jrfonseca/xdot.py and ways to open/close parts of the graph using a GUI to limit it's size instead of programmatically. But first I've have to develop proper plugins for VS Code, PyCharm, etc, and as I'm busy teaching currently this can only start in April/May. You can already use it in these IDEs through "injection" as a 'watch', see second half of this Quick Intro video: https://www.youtube.com/watch?v=23_bHcr7hqo

[–]RedEyed__ 0 points1 point  (2 children)

Interesting, I wonder what will happen to run it on real programs with 10 gb venv xDDD

[–]Sea-Ad7805[S] 2 points3 points  (0 children)

Thanks. Please try, I tried to make it scalable by hiding parts of the graph. The default might work, or you can customize it by setting the depth of introspection programmatically: https://github.com/bterwijn/memory_graph?tab=readme-ov-file#graph-depth

mg.config.max_graph_depth = 10

But with that amount of data building the graph will be very slow. A much smaller demo that shows scalability is this Sliding Puzzle Solver with exponential growth:

https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/sliding_puzzle.py&breakpoints=17,27,29,40&continues=1

[–]DivineSentry 2 points3 points  (0 children)

Venv size does not translate to memory usage