r/pythoncoding • • Jul 22 '25

Visualizing Python's Data Model: References, Mutability, and Copying Made Clear

3 Upvotes

Many Python beginners (and even experienced devs) struggle with concepts like:

  • references vs. values

  • mutable vs. immutable data types

  • shallow vs. deep copies

  • variables pointing to the same object across function calls

  • recursion and the call stack

To write bug-free code, it's essential to develop the right mental model of how Python actually handles its data. Visualization can help a lot with that. I've created a tool called memory_graph, a teaching tool and debugger aid that generates visual graphs of Python data structures including: shared references, nested structures, and the full call stack.

It helps answer questions like:

  • “Does this variable share any values with that one?”

  • “What part of this object is actually copied?”

  • “What does the call stack look like in this recursive call?”

You can generate a memory graph with a single line of code:

import memory_graph as mg
a = [4, 3, 2]
b = a
b.append(1)
mg.show(mg.stack())  # show graph of the call stack

It also integrates in IDEs like VS Code, Cursor AI, and PyCharm for real-time visualization while stepping through code in the debugger.

Would love feedback from Python educators, learners, and tooling enthusiasts.


r/pythoncoding • • Jun 28 '25

A Small Rust-Backed Utility Library for Python (FastPy-RS, Alpha)

3 Upvotes

Hello everyone! I come from the Rust ecosystem and have recently started working in Python. I love Rust for its safety and speed, but I fell in love with Python for its simplicity and rapid development. That inspired me to build something useful for the Python community: FastPy-RS, a library of commonly used functions that you can call from Python with Rust-powered implementations under the hood. The goal is to deliver high performance and strong safety guarantees. While many Python libraries use C for speed, that approach can introduce security risks.

Here’s how you can use it:

import fastpy_rs as fr

# Using SHA cryptography
hash_result = fr.crypto.sha256_str("hello")

# Encoding in BASE64
encoded = fr.datatools.base64_encode(b"hello")


# Count word frequencies in a text
text = "Hello hello world! This is a test. Test passed!"
frequencies = fr.ai.token_frequency(text)
print(frequencies)
# Output: {'hello': 2, 'world': 1, 'this': 1, 'is': 1, 'a': 1, 'test': 2, 'passed': 1}

# JSON parsing
json_data = '{"name": "John", "age": 30, "city": "New York"}'
parsed_json = fr.json.parse_json(json_data)
print(parsed_json)
# Output: {'name': 'John', 'age': 30, 'city': 'New York'}

# JSON serialization
data_to_serialize = {'name': 'John', 'age': 30, 'city': 'New York'}
serialized_json = fr.json.serialize_json(data_to_serialize)
print(serialized_json)
# Output: '{"name": "John", "age": 30, "city": "New York"}'

# HTTP requests
url = "https://api.example.com/data"
response = fr.http.get(url)
print(response)
# Output: b'{"data": "example"}'

I’d love to see your pull requests and feedback! FastPy-RS is open source under the MIT license—let’s make Python faster and safer together. https://github.com/evgenyigumnov/fastpy-rs

By the way, surprisingly, token frequency calculation in FastPy-RS works almost 935 times faster than in regular Python code, so for any text parsing and analysis tasks you will get instant results; at the same time, operations with Base64 and regular expressions also “fly” 6-6.6 times faster thanks to internal optimizations in Rust; the SHA-256 implementation does not lag behind - it uses the same native accelerations as in Python; and the low standard deviation of execution time means that your code will work not only quickly, but also stably, without unexpected “failures”.

P.S. I’m still new to Python, so please don’t judge the library’s minimalism too harshly—it’s in its infancy. If anyone wants to chip in and get some hands-on practice with Rust and Python, I’d be delighted!


r/pythoncoding • • Jun 19 '25

I built a simple Claude Code Usage Tracker

Thumbnail github.com
3 Upvotes

Hi!

I was getting annoyed not knowing how close I was to hitting my Claude Code usage limits during longer sessions — especially when working with larger prompts or complex tasks.

So I built a lightweight, local usage tracker that runs in real-time and shows if I’m on track to run out of quota before the session ends. It’s been super handy, so I decided to clean it up and share it in case it’s useful to others too.

🔧 What it does:

  • Tracks your Claude Code usage in real-time

  • Predicts whether you’re on pace to hit your limit before your session ends

  • Runs locally, no setup headaches

  • Includes presets for Pro, Max x5, and Max x20 plans (easy to tweak)


r/pythoncoding • • May 09 '25

May be of interest to anyone looking to learn Python

Thumbnail reddit.com
3 Upvotes

r/pythoncoding • • Apr 25 '25

Custom Save Image node for ComfyUI (StableDifussion)

3 Upvotes

Hey there

I'm trying to write a custom node for Comfy that:

1.- Receives an image

2.- Receives an optional string text marked as "Author"

3.- Receives an optional string text marked as "Title"

4.- Receives an optional string text marked as "Subject"

5.- Receives an optional string text marked as "Tags"

6.- Have an option for an output subfolder

7.- Saves the image in JPG format (100 quality), filling the right EXIF metadata fields with the text provided in points 2, 3, 4 and 5

8.- The filename should be the day it was created, in the format YYYY/MM/DD, with a four digit numeral, to ensure that every new file has a diferent filename

The problem is, even when the node appears in ComfyUI, it does not save any image nor create any subfolder. I'm not a programmer at all, so maybe I'm doing something completely stupid here. Any clues?

Note: If it's important, I'm working with the portable version of Comfy, on an embedded Python. I also have Pillow installed here, so that shouldn't be a problem

This is the code I have so far:

import os

import datetime

from PIL import Image, TiffImagePlugin

import numpy as np

import folder_paths

import traceback

class SaveImageWithExif:

u/classmethod

def INPUT_TYPES(cls):

return {

"required": {

"image": ("IMAGE",),

},

"optional": {

"author": ("STRING", {"default": "Author"}),

"title": ("STRING", {"default": "Title"}),

"subject": ("STRING", {"default": "Description"}),

"tags": ("STRING", {"default": "Keywords"}),

"subfolder": ("STRING", {"default": "Subfolder"}),

}

}

RETURN_TYPES = ("STRING",) # Must match return type

FUNCTION = "save_image"

CATEGORY = "image/save"

def encode_utf16le(self, text):

return text.encode('utf-16le') + b'\x00\x00'

def save_image(self, image, author="", title="", subject="", tags="", subfolder=""):

print("[SaveImageWithExif] save_image() called")

print(f"Author: {author}, Title: {title}, Subject: {subject}, Tags: {tags}, Subfolder: {subfolder}")

try:

print(f"Image type: {type(image)}, len: {len(image)}")

image = image

img = Image.fromarray(np.clip(255.0 * image, 0, 255).astype(np.uint8))

output_base = folder_paths.get_output_directory()

print(f"Output directory base: {output_base}")

today = datetime.datetime.now()

base_path = os.path.join(output_base, subfolder)

dated_folder = os.path.join(base_path, today.strftime("%Y/%m/%d"))

os.makedirs(dated_folder, exist_ok=True)

counter = 1

while True:

filename = f"{counter:04d}.jpg"

filepath = os.path.join(dated_folder, filename)

if not os.path.exists(filepath):

break

counter += 1

exif_dict = TiffImagePlugin.ImageFileDirectory_v2()

if author:

exif_dict[315] = author

if title:

exif_dict[270] = title

if subject:

exif_dict[40091] = self.encode_utf16le(subject)

if tags:

exif_dict[40094] = self.encode_utf16le(tags)

img.save(filepath, "JPEG", quality=100, exif=exif_dict.tobytes())

print(f"[SaveImageWithExif] Image saved to: {filepath}")

return (f"Saved to {filepath}",)

except Exception as e:

print("[SaveImageWithExif] Error:")

traceback.print_exc()

return ("Error saving image",)

NODE_CLASS_MAPPINGS = {

"SaveImageWithExif": SaveImageWithExif

}

NODE_DISPLAY_NAME_MAPPINGS = {

"SaveImageWithExif": "Save Image with EXIF Metadata"

}


r/pythoncoding • • Feb 26 '25

Good translator api or library

3 Upvotes

Hi everyone, I made a Python project which translate PDF documents. I did it because I couldn't find something similar already made because my purpose was: to not have a size of file limitation, and the translated new-made file to look exactly the same like original. I can say after 2 days hard work, I succeeded 😅 But the problem is that I was using a Google Cloud account to activate Google Translate Api and now I'm out of free credits. I'm looking for another free way to use a good translator without limitation because I'm translating pdf-s with many pages. The project is for own use and no commercial purposes. I saw Argos Translate and Libre Translate but the translation from English to Bulgarian(which I need) is very bad. I will be glad if someone could help 🙏


r/pythoncoding • • Jan 24 '25

Open-source DIY Home Security System

3 Upvotes

Hello r/PythonCoding,

I have recently finished building a DIY home security system that supports multiple devices. It works well on old laptops and can use a RaspberryPi Zero W for on-demand pictures and videos (I have found the Zero W too weak for full motion detection with OpenCV).

You can get the source code here: MingSec

Here is some more information about the project:

Features:

  • Motion Detection: Utilizes OpenCV to detect motion and trigger responses.

  • Image Capture: Captures and uploads an image every ten minutes to Dropbox.

  • Alarm Response: Captures an image and records a video if the alarm is triggered. Both are uploaded to Dropbox.

  • Offline Operation: Logs all videos and images when the internet connection is down, and uploads them once the connection is restored.

  • REST API: Provides endpoints for users to check the status of each camera and request images or videos.

  • Kotlin Notification App: A companion mobile app developed in Kotlin that receives notifications each time an alarm is triggered.

Project Structure:

  • docs/ - Contains a Single Page Application (SPA) for the project demo.

  • core/ - Includes the REST API and user interface for remote control and system management.

  • local/ - Contains the MingSec application, including configuration files and local scripts.

  • app/ - Contains the Kotlin notification app that receives alerts for triggered alarms.


r/pythoncoding • • Jan 21 '25

Creating my math interpreter stage-2

3 Upvotes

I am in the second stage in the development of my interpeter for math, now I am in the parser stage, the interpeter will be ready soon, it already has a parser and lexer and counts simple math calculations, in the future this interpeter will become a full-fledged programming language, I will be glad for feedback and stars on Github

Github link 🔗 https://github.com/Nikchan5/Math-Interpreter


r/pythoncoding • • Dec 24 '24

GossipSampling - A Standalone Peer Selection Service for Decentralized Networking

3 Upvotes

This library (tries) to make decentralized networking easy. I'm open to suggestions and contributors and would love to find others that are interested in this topic!

Github Repo

Blog Explaining High Level Theory


r/pythoncoding • • Dec 12 '24

How to convert model.h5 to TensorFlow; tensorflowjs_converter: command not found

3 Upvotes

I have a model.h5 and I want to use it on my site, so I want to convert it to TensorFlow JS. For this, I need to use the tensorflowjs_converter. I tried installing tensorflowjs with the following command:

sudo pip install tensorflowjs --break-system-packages

But when I try to run the command to convert, this is what I get:

ice@ice-Mint-PC:~$ tensorflowjs_converter --input_format keras "/home/ice/Downloads/handwritten (1).h5" \

/home/ice/Desktop

tensorflowjs_converter: command not found


r/pythoncoding • • Sep 21 '24

Learn how to build the GUI for A Crytpo Tracking Application in Python - Tkinter

Thumbnail
youtu.be
3 Upvotes

r/pythoncoding • • Sep 03 '24

Why not just get your plots in numpy?!

Thumbnail
reddit.com
3 Upvotes

r/pythoncoding • • Aug 19 '24

I Created the Definitive AUTOMATIC Shiny Hunter for Pokémon BDSP

3 Upvotes

Hey everyone! I am Dinones! I coded a Python program using object detection that lets my computer hunt for shiny Pokémon on my physical Nintendo Switch while I sleep. So far, I’ve automatically caught shiny Pokémon like Giratina, Dialga or Azelf, Rotom, Drifloon, all three starters, and more in Pokémon BDSP. Curious to see how it works? Check it out! The program is available for everyone! Obviously, for free; I'm just a student who likes to program this stuff in his free time :)

The games run on a Nintendo Switch (not emulated, a real one). The program gets the output images using a capture card, then, it process them to detect whether the pokemon is shiny or not (OpenCV). Finally, it emulates the joycons using bluetooth (NXBT) and control the Nintendo. Also works on a Raspberry Pi!

I don't make money with this, I just feel my project can be interesting for lot of people.

📽️ Youtube: https://www.youtube.com/watch?v=84czUOAvNyk
🤖 Github: https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter


r/pythoncoding • • Jun 28 '24

Tutorial: Create a 3D Viewer for Numpy Arrays with Three.js in 5 Minutes

Thumbnail
youtube.com
3 Upvotes

r/pythoncoding • • Apr 21 '24

Achieve true parallelism in Python 3.12

Thumbnail self.python
3 Upvotes

r/pythoncoding • • Mar 17 '24

Searching for a good rest-api to retrieve data from

3 Upvotes

Hello all,

I'm creating a project for university about machine learning and finding correlations between different mobile phones and their architectures, features and abilities.

I am currently focusing on samsung as a start, later on I'll add all Android and Ios available to reach out to and gather information about.

I took the data out of GSMArena by RapidAPI paid custom-api.

I am searching for a real-time updating site / bot / api I could scrape or retrieve data from about phones and their specifications and properties etc.. preferably free.

I took a look on twitter, telegram, google and chatGPT but could not find anything reliable, free and up-to-date (but to GSM which currently doesn't hold a free API)

I am sure people from gaming, cyber and networks companies would be able to give me good resources to relay on which are up-to-date and constantly updating in order to make this project a blast.

Thanks for the recommendations and help :)


r/pythoncoding • • Mar 04 '24

PNLS: Tool for capturing SSIDs from device's Preferred Network List

Thumbnail
github.com
3 Upvotes

r/pythoncoding • • Feb 07 '24

Asynchronous programming with Python

Thumbnail pynerds.com
3 Upvotes

r/pythoncoding • • Feb 04 '24

/r/PythonCoding monthly "What are you working on?" thread

3 Upvotes

Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!

If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.


r/pythoncoding • • Jan 23 '24

Selenium: Inserting HTML as formatted text with an active link

Thumbnail
self.seleniumpython
3 Upvotes

r/pythoncoding • • Jan 17 '24

A programming language for making APIs

Thumbnail
github.com
3 Upvotes

r/pythoncoding • • Jan 11 '24

Understanding Load Balancer: Types & Building with Flask & NGINX

Thumbnail
youtu.be
3 Upvotes

r/pythoncoding • • Nov 26 '23

Designing a python API from scratch on top of a C++ 3D rendering library (Looking for contributors)

3 Upvotes

Over at F3D, we are trying to craft a python API on top of the libf3d, a C++ API for rendering 3D meshes.

We are not experienced python developpers so we are not sure of the right choices to make and we a python developer would expect. We already have a working python API using pybind11 but we feel like we could do much more!

If this sounds like something that interest you, please come and take a look. Contributions in any shape or form, issues, documentation, examples, actual code, is very much welcome.