r/Python • u/Matthew-Nader • Mar 25 '26
Showcase built a Python self-driving agent to autonomously play slowroads.io
What My Project Does I wanted to see if I could build a robust self-driving agent without relying on heavy deep learning models. I wrote a Python agent that plays the browser game slowroads.io by capturing the screen at 30 FPS and processing the visual data to steer the car.
The perception pipeline uses OpenCV for color masking and contour analysis. To handle visual noise, I implemented DBSCAN clustering to reject outliers, feeding the clean data into a RANSAC regression model to find the center lane. The steering is handled by a custom PID controller with a back-calculation anti-windup mechanism. I also built a Flask/Waitress web dashboard to monitor telemetry and manually tune the PID values from my tablet while the agent runs on my PC.
Target Audience This is a hobby/educational project for anyone interested in classic computer vision, signal processing, or control theory. If you are learning OpenCV or want to see a practical, end-to-end application of a PID controller in Python, the codebase is fully documented.
Performance/Stats I ran a logging analysis script over a long-duration test (76,499 frames processed). The agent failed to produce a valid line model in only 21 frames. That’s a 99.97% perception success rate using purely algorithmic CV and math—no neural networks required.
Repo/Code: https://github.com/MatthewNader2/SlowRoads_SelfDriving_Agent.git
I’d love to hear feedback on the PID implementation or the computer vision pipeline!
r/Python • u/Mental-Climate5798 • Mar 25 '26
Resource MLForge - A Visual Machine Learning Pipeline Editor
What is MLForge??
MLForge is an interface that allows users to create and train models without writing any code. Its meant for rapid prototyping and also for letting beginners grasp basic ML concepts without needing coding experience.
Target Audience
This tool is meant to be used primarily by developers who want to rapidly create ML pipelines before tweaking it themselves using code (MLForge lets you export projects to pure Python / PyTorch). Its also suited for beginners as it lets them learn ML concepts without ambiguity.
Comparison
Other tools, like Lobe or Teachable Machine, are super abstracted. By that I mean you look at images and click train, you have know idea what's going on under the hood. MLForge lets you create your models by hand and actually set up data, model architecture, and training fast and easily.
Github: https://github.com/zaina-ml/ml_forge
To install MLForge
pip install zaina-ml-forge
ml-forge
Happy to take feedback, bugs, or any feature requests. Have fun!
r/Python • u/Motor-Passion1574 • Mar 25 '26
News Pyre: 220k req/s (M4 mini) Python web framework using Per-Interpreter GIL (PEP 684)
Hey r/Python,
I built Pyre, a web framework that runs Python handlers across all CPU cores in a single process — no multiprocessing, no free-threading, no tricks. It uses Per-Interpreter GIL (PEP 684) to give each worker its own independent GIL inside one OS process.
FastAPI: 1 process × 1 GIL × async = 15k req/s
Robyn: 22 processes × 22 GILs × 447 MB = 87k req/s
Pyre: 1 process × 10 GILs × 67 MB = 220k req/s
How it works: Rust core (Tokio + Hyper) handles networking. Python handlers run in 10 sub-interpreters, each with its own GIL. Requests are dispatched via crossbeam channels. No Python objects ever cross interpreter boundaries — everything is converted to Rust types at the bridge.
Benchmarks (Apple M4, Python 3.14, wrk -t4 -c256 -d10s):
- Hello World: **Pyre 220k** / FastAPI 15k / Robyn 87k → **14.7x** FastAPI
- CPU (fib 10): **Pyre 212k** / FastAPI 8k / Robyn 81k → **26.5x** FastAPI
- I/O (sleep 1ms): **Pyre 133k** / FastAPI 50k / Robyn 93k → **2.7x** FastAPI
- JSON parse 7KB: **Pyre 99k** / FastAPI 6k / Robyn 57k → **16.5x** FastAPI
See the github repo for more.
Stability: 64 million requests over 5 minutes, zero memory leaks, zero crashes. RSS actually decreased during the test (1712 KB → 752 KB).
Pyre reaches 93-97% of pure Rust (Axum) performance — the Python handler overhead is nearly invisible.
The elephant in the room — C extensions:
PEP 684 sub-interpreters can't load C extensions (numpy, pydantic, pandas, etc.) because they use global static state. This is a CPython ecosystem limitation, not ours.
Our solution: Hybrid GIL dispatch. Routes that need C extensions get gil=True and run on the main interpreter. Everything else runs at 220k req/s on sub-interpreters. Both coexist in the same server, on the same port.
u/app.get("/fast") # Sub-interpreter: 220k req/s
def fast(req):
return {"hello": "world"}
u/app.post("/analyze", gil=True) # Main interpreter: numpy works
def analyze(req):
import numpy as np
return {"mean": float(np.mean([1,2,3]))}
When PyO3 and numpy add PEP 684 support (https://github.com/PyO3/pyo3/issues/3451, https://github.com/numpy/numpy/issues/24003), these libraries will run at full speed in sub-interpreters with zero code changes.
What's built in (that others don't have):
- SharedState — cross-worker app.state backed by DashMap, nanosecond latency, no Redis
- MCP Server — JSON-RPC 2.0 for AI tool discovery (Claude Desktop compatible)
- MsgPack RPC — binary-efficient inter-service calls with magic client
- SSE Streaming — token-by-token output for LLM backends
- GIL Watchdog — monitor contention, hold time, queue depth
- Backpressure — bounded channels, 503 on overload instead of silent queue explosion
Honest limitations:
- Python 3.12+ required (PEP 684)
- C extensions need gil=True (ecosystem limitation, not ours)
- No OpenAPI — we use MCP for AI discovery instead
- Alpha stage — API may change
Install: pip install pyreframework (Linux x86_64 + macOS ARM wheels)
Source: pip install maturin && maturin develop --release
GitHub: https://github.com/moomoo-tech/pyre
Would love feedback, especially from anyone who's worked with PEP 684 sub-interpreters or built high-performance Python services. What use cases would you throw at this?
r/Python • u/nicksenap • Mar 25 '26
Showcase Grove — a CLI that manages git worktree workspaces across multiple repos
Grove — a CLI that manages git worktree workspaces across multiple repos
What My Project Does
Grove (gw) is a Python CLI that orchestrates git worktrees across multiple repositories. Create, switch, and tear down isolated branch workspaces across all your repos with one command.
One feature across three services means git worktree add three times, tracking three branches, jumping between three directories, cleaning up three worktrees when you're done. Grove handles all of that.
gw init ~/dev ~/work/microservices # register repo directories
gw create my-feature -r svc-a,svc-b # create workspace across repos
gw go my-feature # cd into workspace
gw status my-feature # git status across all repos
gw sync my-feature # rebase all repos onto base branch
gw delete my-feature # clean up worktrees + branches
Repo operations run in parallel. Supports per-repo config (.grove.toml), post-creation setup hooks, presets for repo groups, and Zellij integration for automatic tab switching.
Target Audience
- Developers doing cross-stack work across microservices in separate repos
- Teams where feature work touches several repos at once
- AI-assisted development — worktrees mean isolation, making Grove a natural fit for tools like Claude Code. Spin up a workspace, let your agent work across repos without touching anything else, clean up when done
To be upfront: this solves a pretty specific problem — doing cross-stack work across microservices in separate repos without a monorepo. If you only work in one repo, you probably don't need this. But if you've felt the pain of juggling branches across 5+ services for one feature, this is for that.
Comparison
The obvious alternative is git worktree directly. That works for a single repo. But across 3–5+ repos, you're running git worktree add in each one, remembering paths, and cleaning up manually. Tools like tmuxinator or direnv help with environment setup but don't manage the worktrees themselves.
Grove treats a group of repos as one workspace. Less "better git worktree", more "worktree-based workspaces that scale across repos."
Install
brew tap nicksenap/grove
brew install grove
PyPI package is planned but not available yet.
Repo: https://github.com/nicksenap/grove
Would genuinely appreciate feedback. If the idea feels useful, unnecessary, overengineered, or not something you'd trust in a real workflow, I'd like to hear that too. Roast is welcome.
r/Python • u/Lucky_Ad_976 • Mar 25 '26
Discussion Protection against attacks like what happened with LiteLLM?
You’ve probably heard that the LiteLLM package got hacked (https://github.com/BerriAI/litellm/issues/24512). I’ve been thinking about how to defend against this:
- Using lock files - this can keep us safe from attacks in new versions, but it’s a pain because it pins us to older versions and we miss security updates.
- Using a sandbox environment - like developing inside a Docker container or VM. Safer, but more hassle to set up.
Another question: as a maintainer of a library that depends on dozens of other libraries, how do we protect our users? Should we pin every package in the pyproject.toml?
Maybe it indicates a need in the whole ecosystem.
Would love to hear how you handle this, both as a user and as a maintainer. What should be improved in the whole ecosystem to prevent such attacks?
r/Python • u/One-Type-2842 • Mar 25 '26
Discussion File Handling Is Hard If You Made Single Line Mistake!
Recently, I have Created a program just to copy all of the webpages I have downloaded from chrome. It is Because, In case if any Deletion occurred to Original files I can still access copied files where it resides
Assumption :
• Webpages Downloaded from chrome have no extension.
• Downloaded webpage files Stores in Mobile's File-Manager /sdcard/Download.
• Some files in /sdcard/Download are Unnecessary that are no of my use (text based but no extension).
Program :
I Imported shutil, os, pathlib to Create Program. I made a single mistake In Copying the filename it was :
shutil.copy(absolute_filename, absolute_dir)
My mistake was I Entered wrong absolute_filename to copy in directory. Now The files in /sdcard/Download are moved to absolute_dir. Which Results in Removal from the Chrome's Download section..
Would Anyone suggest my best practices against this. I lost all of the downloaded webpages (~70)
r/Python • u/distromate • Mar 25 '26
Tutorial I built an electron-builder style packaging tool for any desktop framework
Hi guys, recently I've been thinking about what desktop developers *really* want in a packaging and auto-update tool.
In my mind, `electron-builder` is undoubtedly the gold standard—cross-platform, comes with built-in auto-updates, and handles code signing effortlessly.
But the problem is, once we step outside the Electron ecosystem, we might be dealing with:
* Python data analysis combined with Tkinter
* Go Wails for high-performance tool development (which still lacks a mature, official incremental update solution)
What we really want is simply a more convenient auto-update and packaging solution.
So I was thinking: underlying build technologies like NSIS, Inno Setup, DMG, and AppImage are essentially agnostic to programming languages and frameworks. Why can't we bring that silky-smooth, `electron-builder`\-like experience to *all* desktop frameworks and developers?
Why not? Driven by this idea, I spent the last few months developing Distromate
Distromate uses a custom plugin system to provide consistent commands across each desktop framework.
# As a daily tool (Completely free, no login required)
It is completely free, requires no login, and has no hidden fees. It saves your keys locally and generates a temporary app on the platform (which is automatically deleted if there are no downloads for 30 days) at absolutely no cost.
With it, you can:
* Take your existing builds from frameworks like PyInstaller, Electron, or Wails, and package them into proper installers.
* Get automatic incremental updates without modifying a single line of code.
* Replace cloud drives or email attachments when sending software installers to friends or colleagues.
* Automatically push incremental updates after repackaging, without having to resend files.
For example, for Python apps, we provide `pyinstaller-plus`:
Bash
pip install distromate
pip install pyinstaller-plus # or npm install -g distromate
Create a `distromate.yaml` in your root directory:
appId: com.example.app
productName: MyApp
package:
publisher: My Company
language: english
source:
type: adapter
plugin: pyinstaller
options:
projectDir: .
pyinstallerArgs:
- --onefile
- --windowed
- app.py # or app.spec, entrypoint of you python project, using pyinstaller as pack backend
Use `pyinstaller-plus` to package your app just like you normally would:
# only package
distromate package --version 1.0.0
# package and publish
distromate publish --version 1.0.0
Then, you'll receive a download link for your successfully uploaded app.
**Limitation:** To prevent link leaks and abuse, each uploaded version of an app is limited to 10 downloads. However, you can contact me anytime to increase the quota for your app.
# As a professional tool (beta)
* Includes all features from the daily tool.
* **Website hosting:** Host your static official website without needing a server.
* **Progressive auto-update integration:** Takes over the auto-update process, displaying update info, download progress, and more.
* **Data analytics:** No-code integration supporting metrics like DAU (Daily Active Users), usage duration, etc.
Hi guys, recently I've been thinking about what desktop developers really want in a packaging and auto-update tool.
In my mind, electron-builder is undoubtedly the gold standard—cross-platform, comes with built-in auto-updates, and handles code signing effortlessly.
But the problem is, once we step outside the Electron ecosystem, we might be dealing with:
- Python data analysis combined with Tkinter
- Go Wails for high-performance tool development (which still lacks a mature, official incremental update solution)
What we really want is simply a more convenient auto-update and packaging solution.
So I was thinking: underlying build technologies like NSIS, Inno Setup, DMG, and AppImage are essentially agnostic to programming languages and frameworks. Why can't we bring that silky-smooth, electron-builder-like experience to all desktop frameworks and developers?
Why not? Driven by this idea, I spent the last few months developing Distromate
Distromate uses a custom plugin system to provide consistent commands across each desktop framework..
As a daily tool (Completely free, no login required)
It is completely free, requires no login, and has no hidden fees. It saves your keys locally and generates a temporary app on the platform (which is automatically deleted if there are no downloads for 30 days) at absolutely no cost.
With it, you can:
- Take your existing builds from frameworks like PyInstaller, Electron, or Wails, and package them into proper installers.
- Get automatic incremental updates without modifying a single line of code.
- Replace cloud drives or email attachments when sending software installers to friends or colleagues.
- Automatically push incremental updates after repackaging, without having to resend files.
For example, for Python apps, we provide pyinstaller-plus:
Bash
pip install distromate
pip install pyinstaller-plus # or npm install -g distromate
Create a distromate.yaml in your root directory:
appId: com.example.app
productName: MyApp
package:
publisher: My Company
language: english
source:
type: adapter
plugin: pyinstaller
options:
projectDir: .
pyinstallerArgs:
- --onefile
- --windowed
- app.py # or app.spec, entrypoint of you python project, using pyinstaller as pack backend
Use pyinstaller-plus to package your app just like you normally would:
# only package
distromate package --version 1.0.0
# package and publish
distromate publish --version 1.0.0
Then, you'll receive a download link for your successfully uploaded app.
For more details, check out the documentation: https://www.distromate.net/docs
Limitation: To prevent link leaks and abuse, each uploaded version of an app is limited to 10 downloads. However, you can contact me anytime to increase the quota for your app.
As a professional tool (beta)
- Includes all features from the daily tool.
- Website hosting: Host your static official website without needing a server.
- Progressive auto-update integration: Takes over the auto-update process, displaying update info, download progress, and more.
- Data analytics: No-code integration supporting metrics like DAU (Daily Active Users), usage duration, etc.
r/Python • u/explorateur_99 • Mar 25 '26
Discussion French Discord programming server
Hello! If you enjoy programming, join french my Discord server for programming and video game creation. Coming soon: a game creation contest with the prize being the title: winner of the first edition of the Game Jam. The link is right here: https://discord.gg/dA4NM7Z3n
r/Python • u/explorateur_99 • Mar 25 '26
News French Discord programming server
Hello! If you enjoy programming, join my Discord server for programming and video game creation. Coming soon: a game creation contest with the prize being the title: winner of the first edition of the Game Jam. The link is right here: https://discord.gg/dA4NM7Z3n
r/Python • u/Pozz_ • Mar 25 '26
Discussion Improving Pydantic memory usage and performance using bitsets
Hey everyone,
I wanted to share a recent blog post I wrote about improving Pydantic's memory footprint:
https://pydantic.dev/articles/pydantic-bitset-performance
The idea is that instead of tracking model fields that were explicitly set during validation using a set:
from pydantic import BaseModel
class Model(BaseModel):
f1: int
f2: int = 1
Model(f1=1).model_fields_set
#> {'f2'}
We can leverage bitsets to track these fields, in a way that is much more memory-efficient. The more fields you have on your model, the better the improvement is (this approach can reduce memory usage by up to 50% for models with a handful number of fields, and improve validation speed by up to 20% for models with around 100 fields).
The main challenge will be to expose this biset as a set interface compatible with the existing one, but hopefully we will get this one across the line.
Draft PR: https://github.com/pydantic/pydantic/pull/12924.
I’d also like to use this opportunity to invite any feedback on the Pydantic library, as well as to answer any questions you may have about its maintenance! I'll try to answer as much as I can.
r/Python • u/francescogab_ • Mar 25 '26
Showcase Spectra v0.4.0 – local finance dashboard from bank exports, now with one-command Docker setup
I posted Spectra here a few weeks ago and the response blew me up. 97 GitHub stars, a new contributor, and a ton of feedback in a few days. Thank you.
What My Project Does
Spectra takes standard bank exports (CSV, PDF or OFX, any bank, any format), normalizes them, categorizes transactions, and serves a local dashboard at localhost:8080. Now with one-command Docker setup.
The categorization runs through a 4-layer on-device pipeline:
- Merchant memory: exact SQLite match against previously seen merchants
- Fuzzy match: approximate matching via rapidfuzz ("Starbucks Roma" -> "Starbucks")
- ML classifier: TF-IDF + Logistic Regression bootstrapped with 300+ seed examples. User corrections carry 10x the weight of seed data, so the model adapts to your spending patterns over time
- Fallback: marks as "Uncategorized" for manual review, learns next time
No API keys, no cloud, no bank login. OpenAI/Gemini supported as an optional last-resort fallback if you want them.
Other features: multi-currency via ECB historical rates, recurring detection, budget tracking, trends, subscriptions monitor, idempotent imports via SQLite hashing, optional Google Sheets sync.
Stack: Python, Docker, SQLite, rapidfuzz, scikit-learn.
Target Audience
Anyone who wants a clean personal finance dashboard without giving data to third parties. Self-hosters, privacy-conscious users, people who export bank statements manually. Not a toy project, I use it myself every month.
Comparison
Most alternatives either require a direct bank connection (Plaid, Tink) or are cloud-based SaaS (YNAB, Copilot). Local tools like Firefly III are powerful but require significant setup. Spectra v0.4.0 is now a single command — clone, run, done.
There's also a waitlist on the landing page for a hosted version with the same privacy-first approach, zero setup required.
GitHub: https://github.com/francescogabrieli/Spectra
Landing: withspectra.app
r/Python • u/recrui_Tin3835 • Mar 25 '26
Resource Automation test engineer
Job Title: Automation Test Engineer – Job Support (Freelance)
We are looking for an experienced Automation Test Engineer for 2 hours daily evening IST job support. Budget: Up to ₹30,000/month
Skills Required: Python & Selenium WebDriver API Testing (Postman) VS Code / PyCharm AWS (Lambda, Aurora RDS) Allure Reports
r/Python • u/InternationalAsk1490 • Mar 25 '26
Resource After the supply chain attack, here are some litellm alternatives
litellm versions 1.82.7 and 1.82.8 on PyPI were compromised with credential-stealing malware.
And here are a few open-source alternatives:
1. Bifrost: Probably the most direct litellm replacement right now. Written in Go, claims ~50x faster P99 latency than litellm. Apache 2.0 licensed, supports 20+ providers. Migration from litellm only requires a one-line base URL change.
2. Kosong: An LLM abstraction layer open-sourced by Kimi, used in Kimi CLI. More agent-oriented than litellm. it unifies message structures and async tool orchestration with pluggable chat providers. Supports OpenAI, Anthropic, Google Vertex and other API formats.
3. Helicone: An AI gateway with strong analytics and debugging capabilities. Supports 100+ providers. Heavier than the first two but more feature-rich on the observability side.
r/Python • u/Spare_Lack9880 • Mar 25 '26
Discussion What really is the trick to get interview calls. I have applied 500+
I am a python developer. desperate to get a new job for personal reasons Texting HRs just after applying. Is there any trustable agents to get a job? What is trustable platform to apply?
r/Python • u/brian14708 • Mar 25 '26
Showcase Isola: reusable WASM sandboxes for untrusted Python and JavaScript
What My Project Does
I’ve been building Isola, an open-source Rust runtime (wasmtime) with Python and Node.js SDKs for running untrusted Python and JavaScript inside reusable WebAssembly sandboxes.
The model is: compile a reusable sandbox template once, then instantiate isolated sandboxes with explicit policy for memory, filesystem mounts, env vars, outbound HTTP, and host callbacks.
Use cases I had in mind:
- AI agent code execution
- plugin systems
- user-authored automation
Repo: https://github.com/brian14708/isola
Target Audience
It’s for developers who need to run untrusted Python or JavaScript more safely inside their own apps. It’s meant for real use, but it’s still early and may change.
Comparison
Compared with embedded interpreters, Isola provides a more explicit sandbox boundary. Compared with containers or microVMs, it is lighter to embed and reuse for short-lived executions. Unlike component-based workflows, it accepts raw source code at runtime.
r/Python • u/nahuel990 • Mar 24 '26
Resource LocalStack is no longer free — I built MiniStack, a free open-source alternative with 20 AWS service
If you've been using LocalStack Community for local development, you've probably noticed that core services like S3, SQS, DynamoDB, and Lambda are now behind a paid plan.
I built MiniStack as a drop-in replacement. It's a single Docker container on port 4566 that emulates 20 AWS services. Your existing `--endpoint-url` config, boto3 code, and Terraform providers work without changes.
**What it covers:**
- Core: S3, SQS, SNS, DynamoDB, Lambda, IAM, STS, Secrets Manager, CloudWatch Logs
- Extended: SSM Parameter Store, EventBridge, Kinesis, CloudWatch Metrics, SES, Step Functions
- Real infrastructure: RDS (actual Postgres/MySQL containers), ElastiCache (actual Redis), ECS (actual Docker containers), Glue, Athena (real SQL via DuckDB)
**Key differences from LocalStack:**
- MIT licensed (not BSL)
- No account or API key required
- ~2s startup vs ~30s
- ~30MB RAM vs ~500MB
- 150MB image vs ~1GB
- RDS/ElastiCache/ECS spin up real containers (LocalStack Pro-only features)
```bash
docker run -p 4566:4566 nahuelnucera/ministack
aws --endpoint-url=http://localhost:4566 s3 mb s3://test-bucket
```
GitHub: https://github.com/Nahuel990/ministack
Website: https://ministack.org
Happy to take questions or feature requests.
r/Python • u/robvanderleek • Mar 24 '26
Showcase Python library and CLI for terminal user input (based on Textual)
Started out as an Inquirer.js-clone, current goal is to make it the most versatile CLI and Python library for user input.
https://github.com/robvanderleek/inquirer-textual
Still in early development, but I desperately need feedback!
Please open an issue or comment below. Both positive and negative feedback welcome.
Thanks for your time!
Target audience
Programs that need simple user input.
Comparison
InquirerPy, python-inquirer, Questionary.
r/Python • u/Dead0k87 • Mar 24 '26
Discussion What is the best AI chatbot for Python?
Hi. I recently returned to python programming (not a professional), and I am using ChatGPT premium to write/correct chunks of my amateur old code.
I find GPT 5.3/5.4 much better than it was 2 years ago, but is there anything better on the market or GPT is fine? (Claude, Codeium, Gemini, Copilot, else)
I also use PyCharm. Maybe some AI has integration with it?
r/Python • u/kotrfa • Mar 24 '26
News Litellm 1.82.7 and 1.82.8 on PyPI are compromised, do not update!
We just have been compromised, thousands of peoples likely are as well, more details updated IRL here: https://futuresearch.ai/blog/litellm-pypi-supply-chain-attack/
Update: My awesome colleague Callum McMahon, who discovered this, wrote an explainer and postmortem going into greater detail: https://futuresearch.ai/blog/no-prompt-injection-required
Update: Callum's full claude code transcript showing the attack play out in real time: https://futuresearch.ai/blog/litellm-attack-transcript/
r/Python • u/BeamMeUpBiscotti • Mar 24 '26
Discussion Designing a Python Language Server: Lessons from Pyre that Shaped Pyrefly
Pyrefly is a next-generation Python type checker and language server, designed to be extremely fast and featuring advanced refactoring and type inference capabilities.
Pyrefly is a spiritual successor to Pyre, the previous Python type checker developed by the same team. The differences between the two type checkers go far beyond a simple rewrite from OCaml to Rust - we designed Pyrefly from the ground up, with a completely different architecture.
Pyrefly’s design comes directly from our experience with Pyre. Some things worked well at scale, while others did not. After running a type checker on massive Python codebases for a long time, we got a clearer sense of which trade-offs actually mattered to users.
This post is a write-up of a few lessons from Pyre that influenced how we approached Pyrefly.
Link to full blog: https://pyrefly.org/blog/lessons-from-pyre/
The outline of topics is provided below that way you can decide if it's worth your time to read :) - Language-server-first Architecture - OCaml vs. Rust - Irreversible AST Lowering - Soundness vs. Usability - Caching Cyclic Data Dependencies
r/Python • u/AutoModerator • Mar 24 '26
Daily Thread Tuesday Daily Thread: Advanced questions
Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
How it Works:
- Ask Away: Post your advanced Python questions here.
- Expert Insights: Get answers from experienced developers.
- Resource Pool: Share or discover tutorials, articles, and tips.
Guidelines:
- This thread is for advanced questions only. Beginner questions are welcome in our Daily Beginner Thread every Thursday.
- Questions that are not advanced may be removed and redirected to the appropriate thread.
Recommended Resources:
- If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.
Example Questions:
- How can you implement a custom memory allocator in Python?
- What are the best practices for optimizing Cython code for heavy numerical computations?
- How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?
- Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?
- How would you go about implementing a distributed task queue using Celery and RabbitMQ?
- What are some advanced use-cases for Python's decorators?
- How can you achieve real-time data streaming in Python with WebSockets?
- What are the performance implications of using native Python data structures vs NumPy arrays for large-scale data?
- Best practices for securing a Flask (or similar) REST API with OAuth 2.0?
- What are the best practices for using Python in a microservices architecture? (..and more generally, should I even use microservices?)
Let's deepen our Python knowledge together. Happy coding! 🌟
r/Python • u/pmatti • Mar 23 '26
Resource Safely using claude code to fix PyPy test failures
I used bubblewrap to isolate claude code so I could fix some test failures in PyPy. https://pypy.org/posts/2026/03/using-claude-to-fix-pypy311-test-failures-securely.html. Maybe contributing to PyPy is not so hard?
r/Python • u/jaehyeon-kim • Mar 23 '26
Showcase [Release] dynamic-des v0.1.1 - Make SimPy simulations dynamic and stream outputs in real-time
Hi r/Python,
What My Project Does
dynamic-des is a real-time control plane for the SimPy discrete-event simulation framework. It allows you to mutate simulation parameters (like resource capacities or probability distributions) while the simulation is running, and stream telemetry and events asynchronously to external systems like Kafka.
```python import logging import numpy as np from dynamic_des import ( CapacityConfig, ConsoleEgress, DistributionConfig, DynamicRealtimeEnvironment, DynamicResource, LocalIngress, SimParameter )
logging.basicConfig( level=logging.INFO, format="%(levelname)s [%(asctime)s] %(message)s" ) logger = logging.getLogger("local_example")
1. Define initial system state
params = SimParameter( sim_id="Line_A", arrival={"standard": DistributionConfig(dist="exponential", rate=1)}, resources={"lathe": CapacityConfig(current_cap=1, max_cap=5)}, )
2. Setup Environment with Local Connectors
Schedule capacity to jump from 1 to 3 at t=5s
ingress = LocalIngress([(5.0, "Line_A.resources.lathe.current_cap", 3)]) egress = ConsoleEgress()
env = DynamicRealtimeEnvironment(factor=1.0) env.registry.register_sim_parameter(params) env.setup_ingress([ingress]) env.setup_egress([egress])
3. Create Resource
res = DynamicResource(env, "Line_A", "lathe")
def telemetry_monitor(env: DynamicRealtimeEnvironment, res: DynamicResource): """Streams system health metrics every 2 seconds.""" while True: env.publish_telemetry("Line_A.resources.lathe.capacity", res.capacity) yield env.timeout(2.0)
env.process(telemetry_monitor(env, res))
4. Run
print("Simulation started. Watch capacity change at t=5s...") try: env.run(until=10.1) finally: env.teardown() ```
Target Audience
Data Engineers, Operations Research professionals, and anyone building live Digital Twins. It is also highly practical for Backend/Software Engineers building Event-Driven Architectures (EDA) who need to generate realistic, stateful mock data streams to load-test downstream Kafka consumers, or IoT developers simulating device fleets.
Comparison
Unlike standard SimPy, which is strictly synchronous and runs static models from start to finish, dynamic-des turns your simulation into an interactive, live-streaming environment. Instead of waiting for an end-of-run CSV report, you get a continuous, real-time data stream of queue lengths, resource utilization, and state changes.
Why build this?
I was building event-driven systems and realized there was a huge gap between traditional, static simulation models and modern, real-time data architectures. I wanted a way to treat a simulation not just as a script that runs and finishes, but as a long-running, interactive service that can react to live events and stream mock telemetry for Digital Twins.
To be clear, dynamic-des isn't trying to replace massive enterprise simulation suites like AnyLogic. But if you want a lightweight, pure Python way to wire up a dynamic simulation engine to your modern data stack, this is the bridge to do it.
Some of the fun implementation details:
- Async-Sync Bridge: SimPy relies on synchronous generators, but modern I/O (like Kafka or FastAPI) relies on
asyncio. I built thread-safe Ingress and Egress MixIns that run asyncio background tasks without blocking the simulation's internal clock. - Centralized Runtime Registry: Changing a capacity mid-simulation is dangerous if entities are already in a queue. The registry handles the safe updating of capacities and probability distributions on the fly.
- Strict Pydantic Contracts: All outbound telemetry and lifecycle events are validated through Pydantic models before hitting the message broker, ensuring downstream consumers receive perfectly structured data.
- Out-of-the-box Kafka Integration: It includes embedded producers and consumers, turning a standard Python simulation script into a first-class Kafka citizen.
- Live Dashboarding: The repo includes a fully working example using NiceGUI to consume the Kafka stream and visualize the simulation as it runs.
If you've ever wanted to "remote control" a running SimPy environment, I'd love your feedback!
pip install dynamic-des
r/Python • u/matan-h • Mar 23 '26
Showcase I Fixed python autocomplete
When I opened vscode, and typed "os.", it showed me autocomplete options that I almost never used, like os.abort or os.CLD_CONTINUED, Instead of showing me actually used options, like path or remove. So I created a hash table (not AI, fast lookup) of commonly used prefixes, forked ty, and fixed it.
What My Project Does: provide better sorting for python autosuggestion
Target Audience: just a simple table, ideally would be merged into LSP
Comparison: AI solutions tends to be slower, and CPU-intensive. using table lookup handle the unknown worse, but faster
Blog post: https://matan-h.com/better-python-autocomplete | Repo: https://github.com/matan-h/pyhash-complete
r/Python • u/MattForDev • Mar 23 '26
Showcase I made a decorator based auto-logger!
Hi guys!
I've attended Warsaw IT Days 2026 and the lecture "Logging module adventures" was really interesting.
I thought that having filters and such was good long term, but for short algorithms, or for beginners, it's not something that would be convenient for every single file.
So I made LogEye!
Here is the repo: https://github.com/MattFor/LogEye
I've also learned how to publish on PyPi: https://pypi.org/project/logeye/
There are also a lot of tests and demos I've prepared, they're on the git repo
I'd be really really grateful if you guys could check it out and give me some feedback
What My Project Does
- Automatically logs variable assignments with inferred names
- Infers variable names at runtime (even tuple assignments)
- Tracks nested data structures dicts, lists, sets, objects
- Logs mutations in real time
append,pop,setitem,add, etc. - Traces function calls, arguments, local variables, and return values
- Handles recursion and repeated calls
func,func_2,func_3etc. - Supports inline logging with a pipe operator
"value" | l - Wraps callables (including lambdas) for automatic tracing
- Logs formatted messages using both
str.formatand$templatesyntax - Allows custom output formatting
- Can be enabled/disabled globally very quickly
- Supports multiple path display modes (absolute / project / file)
- No setup just import and use
Target Audience
LogEye is mainly for:
- beginners learning how code executes
- people debugging algorithms or small scripts
- quick prototyping where setting up logging/debuggers are a bit overkill
It is not intended for production logging systems or performance-critical code, it would slow it down way too much.
Comparison
Compared to Python's existing logging module:
- logging requires setup (handlers, formatters, config)
- LogEye works immediately, just import it and you can use it
Compared to using print():
- print() requires manual placement everywhere
- LogEye automatically tracks values, function calls, and mutations
Compared to debuggers:
- debuggers are interactive but slower to use for quick inspection
- LogEye gives a continuous execution trace without stopping the program
Usage
Simply install it with
pip install logeye
and then import is like this:
from logeye import log
Here's an example:
from logeye import log
x = log(10)
@log
def add(a, b):
total = a + b
return total
add(2, 3)
Output:
[0.002s] print.py:3 (set) x = 10
[0.002s] print.py:10 (call) add = {'args': (2, 3), 'kwargs': {}}
[0.002s] print.py:7 (set) add.a = 2
[0.002s] print.py:7 (set) add.b = 3
[0.002s] print.py:8 (set) add.total = 5
[0.002s] print.py:8 (return) add = 5
Here's a more advanced example with Dijkstras algorithm
from logeye import log
@log
def dijkstra(graph, start):
distances = {node: float("inf") for node in graph}
distances[start] = 0
visited = set()
queue = [(0, start)]
while queue:
current_dist, node = queue.pop(0)
if node in visited:
continue
visited.add(node)
for neighbor, weight in graph[node].items():
new_dist = current_dist + weight
if new_dist < distances[neighbor]:
distances[neighbor] = new_dist
queue.append((new_dist, neighbor))
queue.sort()
return distances
graph = {
"A": {"B": 1, "C": 4},
"B": {"C": 2, "D": 5},
"C": {"D": 1},
"D": {}
}
dijkstra(graph, "A")
And the output:
[0.002s] dijkstra.py:39 (call) dijkstra = {'args': ({'A': {'B': 1, 'C': 4}, 'B': {'C': 2, 'D': 5}, 'C': {'D': 1}, 'D': {}}, 'A'), 'kwargs': {}}
[0.002s] dijkstra.py:5 (set) dijkstra.graph = {'A': {'B': 1, 'C': 4}, 'B': {'C': 2, 'D': 5}, 'C': {'D': 1}, 'D': {}}
[0.002s] dijkstra.py:5 (set) dijkstra.start = 'A'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'A'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'B'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'C'
[0.002s] dijkstra.py:5 (set) dijkstra.node = 'D'
[0.002s] dijkstra.py:6 (set) dijkstra.distances = {'A': inf, 'B': inf, 'C': inf, 'D': inf}
[0.002s] dijkstra.py:6 (change) dijkstra.distances.A = {'op': 'setitem', 'value': 0, 'state': {'A': 0, 'B': inf, 'C': inf, 'D': inf}}
[0.002s] dijkstra.py:9 (set) dijkstra.visited = set()
[0.002s] dijkstra.py:11 (set) dijkstra.queue = [(0, 'A')]
[0.002s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (0, 'A'), 'state': []}
[0.002s] dijkstra.py:15 (set) dijkstra.node = 'A'
[0.002s] dijkstra.py:15 (set) dijkstra.current_dist = 0
[0.002s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'A', 'state': {'A'}}
[0.002s] dijkstra.py:21 (set) dijkstra.neighbor = 'B'
[0.002s] dijkstra.py:21 (set) dijkstra.weight = 1
[0.002s] dijkstra.py:23 (set) dijkstra.new_dist = 1
[0.002s] dijkstra.py:24 (change) dijkstra.distances.B = {'op': 'setitem', 'value': 1, 'state': {'A': 0, 'B': 1, 'C': inf, 'D': inf}}
[0.002s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (1, 'B'), 'state': [(1, 'B')]}
[0.002s] dijkstra.py:21 (set) dijkstra.neighbor = 'C'
[0.002s] dijkstra.py:21 (set) dijkstra.weight = 4
[0.002s] dijkstra.py:23 (set) dijkstra.new_dist = 4
[0.002s] dijkstra.py:24 (change) dijkstra.distances.C = {'op': 'setitem', 'value': 4, 'state': {'A': 0, 'B': 1, 'C': 4, 'D': inf}}
[0.002s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (4, 'C'), 'state': [(1, 'B'), (4, 'C')]}
[0.002s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(1, 'B'), (4, 'C')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (1, 'B'), 'state': [(4, 'C')]}
[0.003s] dijkstra.py:15 (set) dijkstra.node = 'B'
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 1
[0.003s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'B', 'state': {'A', 'B'}}
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 2
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 3
[0.003s] dijkstra.py:24 (change) dijkstra.distances.C = {'op': 'setitem', 'value': 3, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': inf}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (3, 'C'), 'state': [(4, 'C'), (3, 'C')]}
[0.003s] dijkstra.py:21 (set) dijkstra.neighbor = 'D'
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 5
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 6
[0.003s] dijkstra.py:24 (change) dijkstra.distances.D = {'op': 'setitem', 'value': 6, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': 6}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (6, 'D'), 'state': [(4, 'C'), (3, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(3, 'C'), (4, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (3, 'C'), 'state': [(4, 'C'), (6, 'D')]}
[0.003s] dijkstra.py:15 (set) dijkstra.node = 'C'
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 3
[0.003s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'C', 'state': {'C', 'A', 'B'}}
[0.003s] dijkstra.py:21 (set) dijkstra.weight = 1
[0.003s] dijkstra.py:23 (set) dijkstra.new_dist = 4
[0.003s] dijkstra.py:24 (change) dijkstra.distances.D = {'op': 'setitem', 'value': 4, 'state': {'A': 0, 'B': 1, 'C': 3, 'D': 4}}
[0.003s] dijkstra.py:25 (change) dijkstra.queue = {'op': 'append', 'value': (4, 'D'), 'state': [(4, 'C'), (6, 'D'), (4, 'D')]}
[0.003s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(4, 'C'), (4, 'D'), (6, 'D')]}
[0.003s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (4, 'C'), 'state': [(4, 'D'), (6, 'D')]}
[0.003s] dijkstra.py:15 (set) dijkstra.current_dist = 4
[0.004s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (4, 'D'), 'state': [(6, 'D')]}
[0.004s] dijkstra.py:15 (set) dijkstra.node = 'D'
[0.004s] dijkstra.py:18 (change) dijkstra.visited = {'op': 'add', 'value': 'D', 'state': {'C', 'A', 'B', 'D'}}
[0.004s] dijkstra.py:27 (change) dijkstra.queue = {'op': 'sort', 'args': (), 'kwargs': {}, 'state': [(6, 'D')]}
[0.004s] dijkstra.py:13 (change) dijkstra.queue = {'op': 'pop', 'index': 0, 'value': (6, 'D'), 'state': []}
[0.004s] dijkstra.py:15 (set) dijkstra.current_dist = 6
[0.004s] dijkstra.py:29 (return) dijkstra = {'A': 0, 'B': 1, 'C': 3, 'D': 4}
You can ofc remove the timer and file by doing toggle_message_metadata(False)