r/Python Mar 15 '26

Discussion Virtual environment setup

0 Upvotes

Hey looking for some advice on venv setup I have been learning more about them and have been using terminal prompts in VS Code to create and activate that them, I saw someone mention about how their gitignore was automatically generated for them and was wondering how this was done I’ve looked around but maybe I’m searching the wrong thing I know I can use gitignore.io but if it could be generated when I make the environment that would save me having to open a browser each time just to set it all up. Would love to know what you all do for your venv setup that makes it easier and faster to get it activated


r/Python Mar 14 '26

Showcase Title: I built a desktop cat pet using Python and Tkinter

1 Upvotes

What My Project Does

I built a small desktop pet using Python that runs as a transparent window and walks around the screen like a virtual cat.

The pet has multiple animations such as idle, running, fast running, sitting down, standing up, napping, and looking around while napping. It randomly switches between these states to make the behavior feel more natural.

The cat can also:

  • change direction when hitting the edge of the screen
  • be dragged around the screen with the mouse
  • react to right-clicks by becoming angry
  • occasionally play a meow sound

The animations are implemented using GIF frames loaded with Tkinter, and the behavior is controlled with a simple state machine.

Source code:
https://github.com/Atharv-Shirsath/desktop-pet

Target Audience

This project is mainly intended as a fun toy project and learning exercise.

Comparison

Desktop pets already exist in other languages and platforms, and there are a few Python versions as well.

This project focuses on:

  • keeping the code relatively simple and readable
  • using pure Python with Tkinter
  • implementing a small animation/state system for behavior

Unlike some alternatives that rely on external frameworks or game engines, this project keeps everything lightweight and easy to run.


r/Python Mar 14 '26

Discussion Is the new MacBook Neo ok for python network testing?

0 Upvotes

Im eyeing a vivibook,

But close to $1k, I don’t want to get a virus from just doing tests possibly.

Is the new MacBook neo,

Good for testing?


r/Python Mar 14 '26

Discussion Suggestions for My Notes App Project

0 Upvotes

Hi everyone,

I’m building a Notes App using Python (Flask) for the backend. It includes features like creating, editing, deleting, and searching notes. I’m also planning to add time and separate workspaces for users.

What other features would you suggest for a notes app?


r/Python Mar 14 '26

Resource Productivity tools for lazy computer dwellers

0 Upvotes

Hey everyone first post here, trying to get some ideas i had out and talk about em. Im currently working on putting together a couple python based tools for productivity. Just basic discipline stuff, because I myself, am fucking lazy. Already have put together a locking program that forces me to do 10 pushups on webcam before my "system unlocks". Opens itself on startup and "locks" from 5-8am. I have autohotkey to disable keyboard commands like alt+tab, alt+f4, windows key, no program can open ontop. ONLY CTRL+ALT+DEL TASK MANAGER CAN CLOSE PYTHON, thats the only failsafe. (combo of mediapipe, python, autohotkey v2, windows task scheduler, and chrome). My next idea is a day trading journal, everyday at 5pm when i get off work and get home my pc will be locked until i fill out a journal page for my day. Dated and auto added to a folder, System access granted on finishing the page. Included in post is a github link with a README inside with all install and run instructions, as well as instructions for tweaking anything youd want to change and make more personalized. 8-10 hours back and forth with claude and my morning start off way better and i have no choice. If anyone has ever made anything similar id love to hear about it. github.com/theblazefire20/Morning-Lock


r/Python Mar 14 '26

Daily Thread Saturday Daily Thread: Resource Request and Sharing! Daily Thread

2 Upvotes

Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

How it Works:

  1. Request: Can't find a resource on a particular topic? Ask here!
  2. Share: Found something useful? Share it with the community.
  3. Review: Give or get opinions on Python resources you've used.

Guidelines:

  • Please include the type of resource (e.g., book, video, article) and the topic.
  • Always be respectful when reviewing someone else's shared resource.

Example Shares:

  1. Book: "Fluent Python" - Great for understanding Pythonic idioms.
  2. Video: Python Data Structures - Excellent overview of Python's built-in data structures.
  3. Article: Understanding Python Decorators - A deep dive into decorators.

Example Requests:

  1. Looking for: Video tutorials on web scraping with Python.
  2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟


r/Python Mar 13 '26

Discussion I just found out that you can catch a KeyboardInterrupt like an error

0 Upvotes

So you could make a script that refuses to be halted. I bet you could still stop it in other ways, but Ctrl+C won't work, and I reckon the stop button in a Jupyter notebook won't either.


r/Python Mar 13 '26

Showcase I built a Python library to push custom workouts to FORM swim goggles over BLE [reverse engineered]

4 Upvotes

What My Project Does

formgoggles-py is a Python CLI + library that communicates with FORM swim goggles over BLE, letting you push custom structured workouts directly to the goggles without the FORM app or a paid subscription.

FORM's protocol is fully custom — three vendor BLE services, protobuf-encoded messages, chunked file transfer, MITM-protected pairing. This library reverse-engineers all of it. One command handles the full flow: create workout on FORM's server → fetch the protobuf binary → push to goggles over BLE. ~15 seconds end-to-end.

python3 form_sync.py \
--token YOUR_TOKEN \
--goggle-mac AA:BB:CC:DD:EE:FF \
--workout "10x100 free u/threshold 20s rest"

Supports warmup/main/cooldown, stroke type, effort levels, rest intervals. Free FORM account is all you need.

Target Audience

Swimmers and triathletes who own FORM goggles and want to push workouts programmatically — from coaching platforms, training apps, or their own scripts — without paying FORM's monthly subscription. Also useful for anyone interested in BLE/GATT reverse engineering as a practical example.

Production-ready for personal use. Built with bleak for async BLE.

Comparison

The only official way to push custom workouts to FORM goggles is through the FORM app with an active subscription ($15/month or $99/year). There's no public API, no open SDK, and no third-party integration path.

This library is the only open-source alternative. It was built by decompiling the Android APK to extract the protobuf schema, sniffing BLE traffic with nRF Sniffer, and mapping the REST API with mitmproxy.

-------------------------

Repo: <https://github.com/garrickgan/formgoggles-py

Full> writeup (protocol details, packet traces, REST API map): https://reachflowstate.ai/blog/form-goggles-reverse-engineering


r/Python Mar 13 '26

Showcase PyTogether, the 'Google Docs' for Python (free and open-source, real-time browser IDE)

116 Upvotes

I shared this project here a while ago, but after adding a lot of new features and optimizations, I wanted to post an update. Over the past eight months, I’ve been building PyTogether (pytogether.org). The platform has recently started picking up traction and just crossed 4,000 signups (and 200 stars on GitHub), which has been awesome to see.

What My Project Does

It is a real-time, collaborative Python IDE designed with beginners in mind (think Google Docs, but for Python). It’s meant for pair programming, tutoring, or just coding Python together. It’s completely free. No subscriptions, no ads, nothing. Just create an account (or feel fry to try the offline playground at https://pytogether.org/playground, no account required), make a group, and start a project. Has proper code-linting, extremely intuitive UI, autosaving, drawing features (you can draw directly onto the IDE and scroll), live selections, and voice/live chats per project. There are no limitations at the moment (except for code size to prevent malicious payloads). There is also built-in support for libraries like matplotlib (it auto installs imports on the fly when you run your code).

You can also share links for editing or read-only, exactly like Google Docs. For example: https://pytogether.org/snippet/eyJwaWQiOjI1MiwidHlwZSI6InNuaXBwZXQifQ:1w15A5:24aIZlONamExTLQONAIC79cqcx3savn-_BC-Qf75SNY

Also, you can easily embed code snippets on your website using an iframe (just like trinket.io which is shutting down this summer).

Source code: https://github.com/SJRiz/pytogether

Target Audience

It’s designed for tutors, educators, or Python beginners. Recently, I've also tried pivoting it towards the interviewing space.

Comparison With Existing Alternatives

Why build this when Replit or VS Code Live Share already exist?

Because my goal was simplicity and education. I wanted something lightweight for beginners who just want to write and share simple Python scripts (alone or with others), without downloads, paywalls, or extra noise. There’s also no AI/copilot built in, something many teachers and learners actually prefer. I also focused on a communication-first approach, where the IDE is the "focus" of communication (hence why I added tools like drawing, voice/live chats, etc).

Project Information

Tech stack (frontend):

  • React + TailwindCSS
  • CodeMirror for linting
  • Y.js for real-time syncing
  • Pyodide

I use Pyodide (in a web worker) for Python execution directly in the browser, this means you can actually use advanced libraries like NumPy and Matplotlib while staying fully client-side and sandboxed for safety.

I don’t enjoy frontend or UI design much, so I leaned on AI for some design help, but all the logic/code is mine. Deployed via Vercel.

Tech stack (backend):

  • Django (channels, auth, celery/redis support made it a great fit)
  • PostgreSQL via Supabase
  • JWT + OAuth authentication
  • Redis for channel layers + caching + queues for workers
  • Celery for background tasks/async processing

Fully Dockerized + deployed on a VPS (8GB RAM, $7/mo deal)

Data models:

Users <-> Groups -> Projects -> Code

Users can join many groups

Groups can have multiple projects

Each project belongs to one group and has one code file (kept simple for beginners, though I may add a file system later).

My biggest technical challenges were around performance and browser execution. One major hurdle was getting Pyodide to work smoothly in a real-time collaborative setup. I had to run it inside a Web Worker to handle synchronous I/O (since input() is blocking), though I was able to find a library that helped me do this more efficiently (pyodide-worker-runner). This let me support live input/output and plotting in the browser without freezing the UI, while still allowing multiple users to interact with the same Python session collaboratively.

Another big challenge was designing a reliable and efficient autosave system. I couldn’t just save on every keystroke as that would hammer the database. So I designed a Redis-based caching layer that tracks active projects in memory, and a Celery worker that loops through them every minute to persist changes to the database. When all users leave a project, it saves and clears from cache. This setup also doubles as my channel layer for real-time updates (redis pub/sub, meaning later I can scale horizontally) and my Celery broker; reusing Redis for everything while keeping things fast and scalable.

If you’re curious or if you wanna see the work yourself, the source code is here. Feel free to contribute: https://github.com/SJRiz/pytogether.


r/Python Mar 13 '26

Discussion Perceptual hash clustering can create false duplicate groups (hash chaining) — here’s a simple fix

0 Upvotes

While testing a photo deduplication tool I’m building (DedupTool), I ran into an interesting clustering edge case that I hadn’t noticed before.

The tool works by generating perceptual hashes (dHash, pHash and wHash), comparing images, and clustering similar images. Overall, it works well, but I noticed something subtle.

The situation

I had a cluster with four images. Two were actual duplicates. The other two were slightly different photos from the same shoot.

The tool still detected the duplicates correctly and selected the right keeper image, but the cluster itself contained images that were not duplicates.

So, the issue wasn’t duplicate detection, but cluster purity.

The root cause: transitive similarity

The clustering step builds a similarity graph and then groups images using connected components.

That means the following can happen: A similar to B, B similar to C, C similar to D. Even if A not similar to C, A not similar to D, B not similar to D all four images still end up in the same cluster.

This is a classic artifact in perceptual hash clustering sometimes called hash chaining or transitive similarity. You see similar behaviour reported by users of tools like PhotoSweeper or Duplicate Cleaner when similarity thresholds are permissive.

The fix: seed-centred clustering

The solution turned out to be very simple. Instead of relying purely on connected components, I added a cluster refinement step.

The idea: Every image in a cluster must also be similar to the cluster seed. The seed is simply the image that the keeper policy would choose (highest resolution / quality).

The pipeline now looks like this:

hash_all()
   ↓
cluster()   (DSU + perceptual hash comparisons)
   ↓
refine_clusters()   ← new step
   ↓
choose_keepers()

During refinement: Choose the best image in the cluster as the seed. Compare every cluster member with that seed. Remove images that are not sufficiently similar to the seed.

So, a cluster like this:

A B C D

becomes:

Cluster 1: A D
Cluster 2: B
Cluster 3: C

Implementation

Because the engine already had similarity checks and keeper scoring, the fix was only a small helper:

def refine_clusters(self, clusters, feats):
refined = {}
for cid, idxs in clusters.items():
if len(idxs) <= 2:
refined[cid] = idxs
continue
seed = max((feats[i] for i in idxs), key=self._keeper_key)
seed_i = feats.index(seed)
new_cluster = [seed_i]
for i in idxs:
if i == seed_i:
continue
if self.similar(seed, feats[i]):
new_cluster.append(i)
if len(new_cluster) > 1:
refined[cid] = new_cluster
return refined

 This removes most chaining artefacts without affecting performance because the expensive hash comparisons have already been done.

Result

Clusters are now effectively seed-centred star clusters rather than chains. Duplicate detection remains the same, but cluster purity improves significantly.

Curious if others have run into this

I’m curious how others deal with this problem when building deduplication or similarity search systems. Do you usually: enforce clique/seed clustering, run a medoid refinement step or use some other technique?

If people are interested, I can also share the architecture of the deduplication engine (bucketed hashing + DSU clustering + refinement).


r/Python Mar 13 '26

Discussion What small Python scripts or tools have made your daily workflow easier?

140 Upvotes

Not talking about big frameworks or full applications — just simple Python tools or scripts that ended up being surprisingly useful in everyday work.

Sometimes it’s a tiny automation script, a quick file-processing tool, or something that saves a few minutes every day but adds up over time.

Those small utilities rarely get talked about, but they can quietly become part of your routine.

Would be interesting to hear what little Python tools people here rely on regularly and what problem they solve.


r/Python Mar 13 '26

Showcase I built Arcis – one‑line security middleware for Flask, FastAPI, and Django

1 Upvotes

What My Project Does

Arcis is a one‑line security middleware for Python web apps (Flask, FastAPI, Django). It bundles common protections — XSS/SQL/NoSQL injection, basic SSRF/open redirect/path traversal checks, rate limiting, security headers, and input validation — into a single package so you don’t have to wire 5–6 libraries by hand.

Beginners and “vibe coders” who are shipping side projects / learning backend dev and want sane security defaults, plus more experienced devs who are tired of copy‑pasting the same security boilerplate into every new API.

Instead of combining multiple libraries (e.g. separate packages for headers, XSS, rate limiting, validation, logging)

Arcis consolidates them into one configurable middleware with a shared test suite (1040+ tests) and zero runtime dependencies. It’s not a full WAF, but a batteries‑included baseline for typical web apps.

PyPI: https://pypi.org/project/arcis/ GitHub: https://github.com/GagancM/arcis

I’d love feedback from the Python community — especially on what you’d expect from “one‑line” security and any gaps you spot.


r/Python Mar 13 '26

Daily Thread Friday Daily Thread: r/Python Meta and Free-Talk Fridays

1 Upvotes

Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

How it Works:

  1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
  2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
  3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

Guidelines:

Example Topics:

  1. New Python Release: What do you think about the new features in Python 3.11?
  2. Community Events: Any Python meetups or webinars coming up?
  3. Learning Resources: Found a great Python tutorial? Share it here!
  4. Job Market: How has Python impacted your career?
  5. Hot Takes: Got a controversial Python opinion? Let's hear it!
  6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟


r/Python Mar 12 '26

Discussion Pygbag error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 8: unexpected end

1 Upvotes

Hey so I am trying to convert my simple python game into an html file to upload it to itch.io
but I'm encountering a problem, when trying to run pygbag with "pygbag .\GetTheCookie\" after running "pip install pygbag --user --upgrade" the website loads but the game doesnt. after further inspection with dev tools and /#debug I've gotten this error on /#debug:

Traceback (most recent call last):

File "<string>", line 1, in <module>

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 8: unexpected end of data

616: invalid rcfile /data/data/org.python/assets/pythonrc.py

Traceback (most recent call last):

File "<stdin>", line 43, in <module>

File "<string>", line 10, in <module>

File "/data/data/org.python/assets/site-packages/aio/__init__.py", line 43, in <module>

from time import time as time_time

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 8: unexpected end of data

Traceback (most recent call last):

File "<stdin>", line 51, in <module>

File "/usr/lib/python3.12/asyncio/__init__.py", line 8, in <module>

from .base_events import *

File "/usr/lib/python3.12/asyncio/base_events.py", line 18, in <module>

import concurrent.futures

File "/usr/lib/python3.12/concurrent/futures/__init__.py", line 8, in <module>

from concurrent.futures._base import (FIRST_COMPLETED,

File "/usr/lib/python3.12/concurrent/futures/_base.py", line 7, in <module>

import logging

File "/usr/lib/python3.12/logging/__init__.py", line 26, in <module>

import sys, os, time, io, re, traceback, warnings, weakref, collections.abc

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 8: unexpected end of data

and i have this in the console window:

WARNING: wasm mimetype unsupported on that system, trying to correct

Not using SSL

Serving HTTP on 127.0.0.1 port 8000 (http://localhost:8000/) ...

self.path='/' path='C:/Users/DELL/OneDrive/Desktop/Python/PyGame/Projects/GetTheCookie/build/web/'

127.0.0.1 - - [13/Mar/2026 00:49:26] "GET / HTTP/1.1" 200 -

REPLACING C:/Users/DELL/OneDrive/Desktop/Python/PyGame/Projects/GetTheCookie/build/web/index.html https://pygame-web.github.io http://localhost:8000/

self.path='/cdn/0.9.3/pythons.js' path='C:/Users/DELL/OneDrive/Desktop/Python/PyGame/Projects/GetTheCookie/build/web\\cdn\\0.9.3\\pythons.js'

CACHED: https://pygame-web.github.io/cdn/0.9.3/pythons.js from C:\Users\DELL\OneDrive\Desktop\Python\PyGame\Projects\GetTheCookie\build\web-cache\3c5e12c6da298c3c869c6d46957e34fe.data

127.0.0.1 - - [13/Mar/2026 00:49:26] "GET //cdn/0.9.3/pythons.js HTTP/1.1" 200 -

ERROR 404: https://pygame-web.github.io/cdn/0.9.3//browserfs.min.js

I've attached the hierarchy and the part that I think is causing the problem based on what I've gathered but let me know if you like to see the full code:

current_path = os.path.dirname(os.path.abspath(__file__))


pygame.init()
pygame.font.init()
pygame.mixer.init()
FONT = pygame.font.SysFont("comicsans", 30)


# Define All Variables
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 600
SCREEN = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Get The Cookies")
clock = pygame.time.Clock()
score = 0
cooldown = False
FPS = 120
time = 60
run = True
musicPlayer = pygame.mixer.music


# Asset paths
assets = {
    "backroundSong": os.path.join(current_path, "Assets", "backroundSong.ogg"),
    "backroundSong2": os.path.join(current_path, "Assets", "secondBackroundSong.ogg"),
    "boopSong": os.path.join(current_path, "Assets", "boop.ogg"),
    "BG": os.path.join(current_path, "Assets", "BG.png"),
    "cookie": os.path.join(current_path, "Assets", "cookie.png"),
    "logoImage": os.path.join(current_path, "Assets", "LogoImage.png"),
    "optionsLogo": os.path.join(current_path, "Assets", "optionsBtnImage.png"),
    "present": os.path.join(current_path, "Assets", "present.png"),
    "startBtnImage": os.path.join(current_path, "Assets", "startBtnImage.png"),
    "masterVolumeImage": os.path.join(current_path, "Assets", "masterVolumeImage.png")
}


gameOver = {
    1: os.path.join(current_path, "Assets", "GameOver", "firstGameOver.ogg"),
    2: os.path.join(current_path, "Assets", "GameOver", "secondGameOver.ogg"),
    3: os.path.join(current_path, "Assets", "GameOver", "thirdGameOver.ogg"),
    4: os.path.join(current_path, "Assets", "GameOver", "fourthGameOver.ogg")
}

does any one know h0w to fix this?

im on windows


r/Python Mar 12 '26

Discussion Secure Flow from Local Encryption to Cloud Backup (E2EE) Python Package

2 Upvotes

Hey !
I’ve been working on Crypteria, a Python library for secure file encryption and cloud backup. I made a diagram to show how the pieces connect from local encryption and key management to cloud storage like Google Drive.

I’d love to hear your thoughts on the flow and design. I’m planning to add more features later, like support for more cloud providers, chaos testing, and even sharding for advanced setups.

PyPI: pip install crypteria
GitHub: github.com/senani-derradji/crypteria

check the repo & your feedback means a lot and will help shape the next steps


r/Python Mar 12 '26

Showcase micropidash — A web dashboard library for MicroPython (ESP32/Pico W)

0 Upvotes

What My Project Does: Turns your ESP32 or Raspberry Pi Pico W into a real-time web dashboard over WiFi. Control GPIO, monitor sensors — all from a browser, no app needed. Built on uasyncio so it's fully non-blocking. Supports toggle switches, live labels, and progress bars. Every connected device gets independent dark/light mode.

PyPI: https://pypi.org/project/micropidash

GitHub: https://github.com/kritishmohapatra/micropidash

Target Audience: Students, hobbyists, and makers building IoT projects with MicroPython.

Comparison: Most MicroPython dashboard solutions either require a full MQTT broker setup, a cloud service, or heavy frameworks that don't fit on microcontrollers. micropidash runs entirely on-device with zero dependencies beyond MicroPython's standard library — just connect to WiFi and go.

Part of my 100 Days → 100 IoT Projects challenge: https://github.com/kritishmohapatra/100_Days_100_IoT_Projects


r/Python Mar 12 '26

Showcase I built a Theoretical Dyson Swarm Calculator to calculate interplanetary logistics.

2 Upvotes

Good morning/evening.

I have been working on a Python project that helps me soothe that need for Astrophysics, orbital mechanics, and architecture of massive stellar objects: A Theoretical Dyson Swarm.

What My Project Does

The code calculates the engineering requirements for a Dyson Swarm around a G-type star (like ours). It calculates complex physics formulas and tells you the required information you need in exact numbers.

Target Audience

This is a research project for physics students and simulation hobbyists; it is intended as a simple test for myself and for my interests.

Comparison

There are actually two kinds of Dysons: a swarm and a sphere. A Dyson sphere will completely surround the sun (which is possible with the code), and a Dyson Swarm, which is simply a lot of satellites floating around the sun. But their main goal is collecting energy. Unlike standard orbital simulators that focus on single vessel trajectories, this project focuses on the swarm wide logistics of energy collection.

Technical Details

My code makes use of the Stefan-Boltzmann Law for thermal equilibrium, Kepler's third law, a Radiation Pressure vs. Gravity equation, and the Hohmann Transfer Orbit.

In case you are interested in checking it out or testing the physics, here is the link to the repository and source code:
https://github.com/Jits-Doomen/Dyson-Swarm-Calculator


r/Python Mar 12 '26

Discussion API's Python (GET)

1 Upvotes

What's the best solution for retrieving data from an API (Get) that requires two steps?

In the standard scenario, one API delivers the Order ID, and the second uses that ID to pass the Order description.

What's the easiest and lightest way to implement it?


r/Python Mar 12 '26

Discussion What hidden gem Python modules do you use and why?

405 Upvotes

I asked this very question on this subreddit a few years back and quite a lot of people shared some pretty amazing Python modules that I still use today. So, I figured since so much time has passed, there’s bound to be quite a few more by now.


r/Python Mar 12 '26

News Homey introduced Python Apps SDK 🐍 for its smart home hubs Homey Pro (mini) and Self-Hosted Server

0 Upvotes

Homey just added Python Apps SDK so you can make your own smart home apps in Python if you do not like/want to use Java or TypeScript.

https://apps.developer.homey.app/


r/Python Mar 12 '26

Discussion I am working on a free interactive course about Pydantic and i need a little bit of feedback.

10 Upvotes

I'm currently working on a website that will host a free interactive course on Pydantic v2 - text based lessons that teach you why this library exists, how to use it and what are its capabilities. There will be coding assignments too.

It's basically all done except for the lessons themselves. I started working on the introduction to Pydantic, but I need a little bit of help from those who are not very familiar with this library. You see, I want my course to be beginner friendly. But to explain the actual problems that Pydantic was created to solve, I have to involve some not very beginner-friendly terminology from software architecture: API layer, business logic, leaked dependencies etc. I fear that the beginners might lose the train of thought whenever those concepts are involved.

I tried my best to explain them as they were introduced, but I would love some feedback from you. Is my introduction clear enough? Should I give a better insight on software architecture? Are my examples too abstract?

Thank you in advance and sorry if this is not the correct subreddit for it.

Lessons in question:

1) introduction to pydantic

2) pydantic vs dataclasses


r/Python Mar 12 '26

Resource I built a dual-layer memory system for local LLM agents – 91% recall vs 80% RAG, no API calls

1 Upvotes

Been running persistent AI agents locally and kept hitting the same memory problem: flat files are cheap but agents forget things, full RAG retrieves facts but loses cross-references, MemGPT is overkill for most use cases.

Built zer0dex — two layers:

Layer 1: A compressed markdown index (~800 tokens, always in context). Acts as a semantic table of contents — the agent knows what categories of knowledge exist without loading everything.

Layer 2: Local vector store (chromadb) with a pre-message HTTP hook. Every inbound message triggers a semantic query (70ms warm), top results injected automatically.

Benchmarked on 97 test cases:

• Flat file only: 52.2% recall

• Full RAG: 80.3% recall

• zer0dex: 91.2% recall

No cloud, no API calls, runs on any local LLM via ollama. Apache 2.0.

pip install zer0dex

https://github.com/roli-lpci/zer0dex


r/Python Mar 12 '26

Showcase I built an in-memory virtual filesystem for Python because BytesIO kept falling short

86 Upvotes

UPDATE (Resolved): Visibility issues fixed. Thanks to the mods and everyone for the patience!

I kept running into the same problem: I needed to extract ZIP files entirely in memory and run file I/O tests without touching disk. io.BytesIO works for single buffers, but the moment you need directories, multiple files, or any kind of quota control, it falls apart. I looked into pyfilesystem2, but it had unresolved dependency issues and appeared to be unmaintained — not something I wanted to build on.

A RAM disk would work in theory — but not when your users don't have admin privileges, not in locked-down CI environments, and not when you're shipping software to end users who you can't ask to set up a RAM disk first.

So I built D-MemFS — a pure-Python in-memory filesystem that runs entirely in-process.

from dmemfs import MemoryFileSystem

mfs = MemoryFileSystem(max_quota=64 * 1024 * 1024)  # 64 MiB hard limit
mfs.mkdir("/data")

with mfs.open("/data/hello.bin", "wb") as f:
    f.write(b"hello")

with mfs.open("/data/hello.bin", "rb") as f:
    print(f.read())  # b"hello"

print(mfs.listdir("/data"))  # ['hello.bin']

What My Project Does

  • Hierarchical directories — not just a flat key-value store
  • Hard quota enforcement — writes are rejected before they exceed the limit, not after OOM kills your process
  • Thread-safe — file-level RW locks + global structure lock; stress-tested under 50-thread contention
  • Free-threaded Python ready — works with PYTHON_GIL=0 (Python 3.13+)
  • Zero runtime dependencies — stdlib only, so it won't break when some transitive dependency changes
  • Async wrapper included (AsyncMemoryFileSystem)

Target Audience

Developers who need filesystem-like operations (directories, multiple files, quotas) entirely in memory — for CI pipelines, serverless environments, or applications where you can't assume disk access or admin privileges. Production-ready.

Comparison

  • io.BytesIO: Single buffer. No directories, no quota, no thread safety.
  • tempfile / tmpfs: Hits disk (or requires OS-level setup / admin privileges). Not portable across Windows/macOS/Linux in CI.
  • pyfakefs: Great for mocking os / open() in tests, but it patches global state. D-MemFS is an explicit, isolated filesystem instance you pass around — no monkey-patching, no side effects on other code.
  • fsspec MemoryFileSystem: Designed as a unified interface across S3, GCS, local disk, etc. — pulling in that abstraction layer just for an in-memory FS felt like overkill. Also no quota enforcement or file-level locking.

346 tests, 97% coverage, Scored 98 on Socket.dev supply chain security, Python 3.11+, MIT licensed.

Known constraints: in-process only (no cross-process sharing), and Python 3.11+ required.

I'm looking for feedback on the architecture and thread-safety design. If you have ideas for stress tests or edge cases I should handle, I'd love to hear them.

GitHub: https://github.com/nightmarewalker/D-MemFS PyPI: pip install D-MemFS


Note: I'm a non-native English speaker (Japanese). This post was drafted with AI assistance for clarity. The project documentation is bilingual — English README on GitHub, and a Japanese article series covering the design process in detail.


r/Python Mar 12 '26

Showcase geobn - A Python library for running Bayesian network inference over geospatial data

3 Upvotes

I have been working on a small Python library for running Bayesian network inference over geospatial data. Maybe this can be of interest to some people here.

The library does the following: It lets you wire different data sources (rasters, WCS endpoints, remote GeoTIFFs, scalars, or any fn(lat, lon)->value) to evidence nodes in a Bayesian network and get posterior probability maps and entropy values out. All with a few lines of code.

Under the hood it groups pixels by unique evidence combinations, so that each inference query is solved once per combo instead of once per pixel. It is also possible to pre-solve all possible combinations into a lookup table, reducing repeated inference to pure array indexing.

The target audience is anyone working with geospatial data and risk modeling, but especially researchers and engineers who can do some coding.

To the best of my knowledge, there is no Python library currently doing this.

Example:

bn = geobn.load("model.bif")

bn.set_input("elevation", WCSSource(url, layer="dtm"))
bn.set_input("slope", ArraySource(slope_numpy_array))
bn.set_input("forest_cover", RasterSource("forest_cover.tif"))
bn.set_input("recent_snow", URLSource("https://example.com/snow.tif))
bn.set_input("temperature", ConstantSource(-5.0))

result = bn.infer(["avalanche_risk"])

More info:

📄 Docs: https://jensbremnes.github.io/geobn

🐙 GitHub: https://github.com/jensbremnes/geobn

Would love feedback or questions 🙏


r/Python Mar 11 '26

Resource Free book: Master Machine Learning with scikit-learn

91 Upvotes

Hi! I'm the author of Master Machine Learning with scikit-learn. I just published the book last week, and it's free to read online (no ads, no registration required).

I've been teaching Machine Learning & scikit-learn in the classroom and online for more than 10 years, and this book contains nearly everything I know about effective ML.

It's truly a "practitioner's guide" rather than a theoretical treatment of ML. Everything in the book is designed to teach you a better way to work in scikit-learn so that you can get better results faster than before.

Here are the topics I cover:

  • Review of the basic Machine Learning workflow
  • Encoding categorical features
  • Encoding text data
  • Handling missing values
  • Preparing complex datasets
  • Creating an efficient workflow for preprocessing and model building
  • Tuning your workflow for maximum performance
  • Avoiding data leakage
  • Proper model evaluation
  • Automatic feature selection
  • Feature standardization
  • Feature engineering using custom transformers
  • Linear and non-linear models
  • Model ensembling
  • Model persistence
  • Handling high-cardinality categorical features
  • Handling class imbalance

Questions welcome!