Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
How to efficiently combine Redis-based recommendation scoring with Django QuerySet for paginated feeds?

I'm building a marketplace app and trying to implement a personalized recommendation feed. I have a hybrid architecture question about the best way to handle this:

Current Setup:
- Django backend with PostgreSQL for product data
- Redis for user preferences, actions, and computed recommendation scores
- Celery for background recommendation generation

The Challenge:
I need to serve a paginated feed where the order is determined by Redis-based scoring (user preferences, trending items, etc), but the actual product data comes from Django models.

My Current Approach:
1. Celery task generates ordered list of product IDs based on Redis metrics
2. Cache this ordered list in Redis (e.g., [123, 456, 789, ...])
3. For each page request, slice the cached ID list
4. Use Django's Case/When to maintain the Redis-determined order:


Questions:
1. Is using Case/When with enumerate() the most efficient way to preserve Redis-determined order in Django?
2. Should I be caching the actual product data in Redis instead of just IDs?
3. Any better patterns for this Redis scoring + Django data combination?
4. How do you handle the "cold start" problem when recommendations aren't ready yet?

The feed needs to handle —10k products with real-time scoring updates. Any architecture advice or alternative approaches would be greatly appreciated!

Tech Stack: Django 4.2, Redis, Celery, PostgreSQL, DRF


/r/django
https://redd.it/1l5n3n9
How can I crat a heartbeat type thread in Flask-MQTT

EDIT: crat s/b create

I have a working flask-MQQT app. But I want it to have a background thread always running that can check and react to outside events, such as broker on other machine is disconnected or a GPIO pin is high/low on the host Raspberry Pi.

I just want this thread to work full time and have it's own sleep(n) step. i would like it to be able to call functions in he main program.

Is this possible? Or..... Any suggestions?

/r/flask
https://redd.it/1l5oze2
R Apple Research: The Illusion of Thinking: Understanding the Strengths and Limitations of Reasoning Models via the Lens of Problem Complexity

Abstract:

>Recent generations of frontier language models have introduced Large Reasoning Models (LRMs) that generate detailed thinking processes before providing answers. While these models demonstrate improved performance on reasoning benchmarks, their fundamental capabilities, scal ing properties, and limitations remain insufficiently understood. Current evaluations primarily fo cus on established mathematical and coding benchmarks, emphasizing final answer accuracy. How ever, this evaluation paradigm often suffers from data contamination and does not provide insights into the reasoning traces’ structure and quality. In this work, we systematically investigate these gaps with the help of controllable puzzle environments that allow precise manipulation of composi tional complexity while maintaining consistent logical structures. This setup enables the analysis of not only final answers but also the internal reasoning traces, offering insights into how LRMs “think”. Through extensive experimentation across diverse puzzles, we show that frontier LRMs face a complete accuracy collapse beyond certain complexities. Moreover, they exhibit a counter intuitive scaling limit: their reasoning effort increases with problem complexity up to a point, then declines despite having an adequate token budget. By comparing LRMs with their standard LLM counterparts under equivalent inference compute, we identify three performance regimes: (1) low complexity tasks where standard models surprisingly outperform LRMs,

/r/MachineLearning
https://redd.it/1l5hzhs
Python on tablet?

I have damaged my laptops hard disk and difficult to operate it in a remote area as there are no repair shops nearby. But i need to learn programming and dsa in 2 months. Can I code on my laptop? Any online softwares for it?

/r/Python
https://redd.it/1l5tscy
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1l5yvhd
Audited SSS (shamir shared secret) code?

I’m currently looking for audited implementations of Shamir’s Secret Sharing (SSS). I recall coming across a dual-audited Java library on GitHub some time ago, but unfortunately, I can’t seem to locate it again.

Are there any audited Python implementations of SSS available? I've searched extensively but haven't been able to find any.

Can anyone found some? I'm thinking about: https://github.com/konidev20/pyshamir but I don't know.

/r/Python
https://redd.it/1l5xtz5
Django CSS Production not loading

Refused to apply style from because its MIME type ('text/html') is not a supported stylesheet MIME

settings.py

BASEDIR = Path(file).resolve().parent.parent

STATIC
URL = '/static/'
STATICROOT = BASEDIR / 'staticfiles'
STATICFILESDIRS = [
    BASE
DIR / 'myapp' / 'static',
]

base.html

<link rel="stylesheet" href="{% static 'styles.css' %}" />

I also am running

python manage.py collectstatic --noinput

So when I am in production its picking up nothing in my static folder I'm so confused help please!

/r/django
https://redd.it/1l5vhcs
Help Django ModuleNotFoundError when deploying to Render

I'm struggling with a deployment issue on Render with my Django project.I'm struggling with a deployment issue on Render with my Django project. When deploying, I get
ModuleNotFoundError: No module named 'accounts'
Project Structure:
portfolio_app/
└── django_portfolio_app/
├── portfolio_app/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── accounts/
├── projects/
├── resume/
├── forum/
├── theme/
│ └── static/
└── manage.py
I did specify in the render deployment settings that django_portfolio_app is the root directory. No idea where to go from now on, as I'm stuck on this error since yesterday. Thanks for any advice and feedback

/r/django
https://redd.it/1l5t4wr
Project RCPTelegram – A Telegram Bot to Remotely Control Remotely your PC

---

Project RCPTelegram – A Telegram Bot to Remotely Control Your PC (Webcam, Screen, Keylogger, Pranks & More)


---

🔧 What My Project Does

RCPTelegram is a Telegram bot that lets you remotely control your PC via chat commands. Some of the features include:

📸 Streaming your webcam and screen (via ngrok tunnels)

🖼️ Taking screenshots and webcam photos

⌨️ Keylogger

📶 Getting saved Wi-Fi passwords

🌍 Grabbing your public IP

🔊 Setting volume and managing output devices

🎭 Pranks and other fun tools

🔩 Many system automation commands (power, sleep, lock, etc.)


All features are accessible from a single Telegram chat — no GUI needed.


---

🎯 Target Audience

This is not meant for production — it's a toy/educational project designed to explore remote PC control using Python and Telegram. It’s great for learning purposes, automation experiments, or building your own personal remote assistant.


---

⚖️ Comparison to Existing Tools

Unlike commercial tools like TeamViewer or AnyDesk:

🟢 This works headlessly via Telegram

🛠️ Fully scriptable and open-source

🔌 Uses ngrok for quick and easy tunneling

🎉 Has playful features (like pranks) you won’t find in standard tools

🧩 You can modify and extend it however you like



---

🗂️ Links

Bot Code: https://github.com/RiccardoZappitelli/RCPTelegram

GUI Builder: https://github.com/RiccardoZappitelli/RCPTMaker



---

Let me know what features you’d add or how you'd improve it. I’m also planning to split the code into multiple

/r/Python
https://redd.it/1l69934
Django tip Component-Based Design With Django Cotton

/r/django
https://redd.it/1l6f2f3
Anyone successfully hosted on Plannethoster?

Trying to host my first Django/HTML project on Plannethoster as I'm with them for other projects, so thought how hard can it be 😵‍💫

Now I've read though the docs on the site about python and Django project, but I seem to be missing something or they have changed something 🤷 an their support support are not very helpful with it.

From what I've read you need to create the python app and navigate to via terminal, then in stall Django and a Django app, or instead of the Django app you upload you own.

But there's nothing on does it need to be in the app folder you created for the python app before, or can it be in a subfolder? Do I have to upload from their file manager or can I do it from git?

I'm sure there's more questions after this as it seems very convoluted in the setting up.

Thanks for your help and your time, if you have any knowledge on this.

/r/django
https://redd.it/1l69zp9
Docker container running not able to reach localhost

Hi All,

There is an issue that I am facing where I am trying to run the application on docker container. Docker build works absolutely fine. The container is running as well but I am not able to reach the application.

Dockerfile

FROM python:3.10
EXPOSE 5000
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY . .
CMD ["flask", "run", "--host","0.0.0.0"]

Docker Run Command

docker build -t flask-smorest-api .
docker run -dp 5005:5000 -w /app -v "$(pwd):/app" flask-smorest-api

Container Logs

Serving Flask app 'app'
Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
Running on all addresses (0.0.0.0)
Running on http://127.0.0.1:5005
Running on http://172.17.0.2:5005
Press CTRL+C to quit
Restarting with stat
Debugger is active!
Debugger PIN: 502-466-638


When i am trying to access the endpoint from POSTMAN there is

/r/flask
https://redd.it/1l6hapd
Why is there no python auto-instrument module for open telemetry ?

Hi all,

I use open telemetry auto-instrumentors to get insights of my python application. These auto-instrumentors will instrument particular modules:

* [fast-api auto instrumentor](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-fastapi)
* [openai auto instrumentor](https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation-genai/opentelemetry-instrumentation-openai-v2)
* etc...

As far as I understand, these modules will create spans for different events (fastapi request, openai llm call etc..), adding inputs and outputs of event as span attributes

# My question:

Why isn't there a python auto instrumentor that will create a span for each function, adding arguments and return values as attributes ?

Is it a bad idea to do such auto instrumentor ? Is it just not feasible ?


## Edit :
For those who are interested, I have coded an auto-instrumentor that will automatically create a span for the functions that are called **in user code** (not in imported modules etc...)

Check it ou there [repo](https://github.com/le-codeur-rapide/opentelemetry-instrumentation-python/tree/main/examples)

/r/Python
https://redd.it/1l6crs2
Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

/r/Python
https://redd.it/1l6qq6d