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
A Playbook for Writing AI-Ready, Type-Safe Python Tests (using Pytest, Ruff, Mypy)

Hi everyone,

Like many of you, I've been using AI coding assistants and have seen the productivity boost firsthand. But I also got curious about the impact on code quality. The latest data is pretty staggering: one 2025 study found AI-assisted projects have an **8x increase in code duplication** and a **40% drop in refactoring**.

This inspired me to create a practical playbook for writing Python tests that act as a "safety net" against this new wave of technical debt. This isn't just theory; it's an actionable strategy using a modern toolchain.

Here are a couple of the core principles:

# Principle 1: Test the Contract, Not the Implementation

The biggest mistake is writing tests that are tightly coupled to the internal structure of your code. This makes them brittle and resistant to refactoring.

**A brittle test looks like this (it breaks on any refactor):**

# This test breaks if we rename or inline the helper function.
def test_process_data_calls_helper_function(monkeypatch):
mock_helper = MagicMock()
monkeypatch.setattr(module, "helper_func", mock_helper)

process_data({})


/r/Python
https://redd.it/1mqr6u7
React + Django Channels Help (groupadd() and groupsend() not working)

Hi,

I am learning how to write a project using Django REST Framework + Django Channels + React for the first time and noticed that I for some reason methods like .groupadd() and .groupsend() do not seem to be working in my project, preventing me from joining the Django Channels room and sending messages between the room's members, respectively.

I have tried using ChatGPT to help me debug the problem but it keeps sending me around in circles by asking me to change the "type" field from "chat.join" to "chatjoin" (the name of my async def chatjoin() method), putting print statements before and behind groupadd() and groupsend() to see if those statements appear in the terminal and thus if execution has stopped during the execution of groupadd()/groupsend(), as well as wrapping the chatjoin() method's implementation in try-catch statements to see if it is silently failing, verifying if my Redis database is up and running at the right address (it is), and even overriding the init() and dispatch methods of the my Consumer class to verify if the "chatjoin" method is being received by my consumer (it is).

None of these have worked and it seems like my entire Consumer class is working (I

/r/djangolearning
https://redd.it/1mk8i2j
Decouple module not found in Vercel

I am doing my first ever project and I am making a poll for it.
So 2 weeks ago, I started:

1. Made the poll
2. Added css and stuff and ran it in local server
3. Then I wanted to upload it to a free hosting website
4. Spent 10 days, with no progress

Now the problem is that I have an error persisting "ModuleNotFound: Decouple" I have it downloaded and in the requirements.txt file even it runs locally. I have tried uninstalling and installing it.

If anyone would like to connect over discord and help me fix it. Please do. I would dearly appreciate it.
Ty for your time!

/r/django
https://redd.it/1mqsdcl
I measure my worth in how many tests I have

/r/flask
https://redd.it/1mqq8ex
I open sourced my marketplace app that meets clients and professionals

Hi 👋, I was trying to create an Upwork clone last year. I couldn't proceed further due to budget and time constraints. I've released it as open source on GitHub. It's missing some features, but it might still be helpful for those looking to start a similar project.

Code on Github: https://github.com/adnankaya/weforbiz



You can watch the demo video on YouTube.

Watch Demo: https://www.youtube.com/watch?v=24rpnWShZoU



Tech stack: Python, Django, Redis, PostgreSQL, Celery, Docker



My contact information is on the GitHub repo. You can reach me if you have any questions.

Good luck, everyone.

/r/django
https://redd.it/1mr5ybq
A simple home server to wirelessly stream any video file (or remote URL) to devices in my LA

I was tired of dealing with HDMI cables, "format not supported" errors, and cables just to watch videos from my PC on other devices.

So I wrote a lightweight Python server to fix it: FFmpeg-HTTP-Streamer.



GitHub Repo: https://github.com/vincenzoarico/FFmpeg-HTTP-Streamer



What it does:

\- Streams any local video file (.mkv, .mp4, etc.) on-the-fly. You don't need to convert anything.

\- Can also stream a remote URL (you can extract an internet video URL with the 1DM Android/iOS app). Just give it a direct link to a video.



How you actually watch stuff: just take the .m3u link provided by the server and load it into any player app (IINA, VLC, M3U IPTV app for TV).



On your phone: VLC for Android/iOS.

On your Smart TV (even non-Android ones like Samsung/LG): Go to your TV's app store, search for an "IPTV Player" or "M3U IPTV," and just add the link.



It's open-source, super easy to set up, and I'd love to hear what you think. Check it out and give it a star on GitHub if you find it useful.



Ask me anything!

/r/Python
https://redd.it/1mqw7zr
Python library that shrinks text for LLMs by up to 80%

Came across this library called context-compressor , it uses models like BERT, T5, and BART to compress text while keeping the meaning intact. Pretty handy for RAG pipelines or cutting token costs on OpenAI/Claude API calls.

PyPI: https://pypi.org/project/context-compressor/

/r/Python
https://redd.it/1mr35nv
Looking for a gig

hey guys i am a full stack developer (django + react + react native). I have 2 years of experience using this stack. open to freelance. let me know if i can be of help.

/r/django
https://redd.it/1mqz2mu
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# 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
https://redd.it/1mretmg
Could Python ever get something like C++’s constexpr?

I really fell in love with constexpr in c++.

I know Python doesn’t have anything like C++’s constexpr today, but I’ve been wondering if it’s even possible (or desirable) for the language to get something similar.

In C++, you can mark a function as constexpr so the compiler evaluates it at compile time:

constexpr int square(int x) {
if (x < 0) throw "negative value not allowed";
return x x;
}

constexpr int result = square(5); // OK
constexpr int bad = square(-2); // compiler/ide error here

The second call never even runs — the compiler flags it right away.

Imagine if Python had something similar:

@constexpr
def square(x: int) -> int:
if x < 0:
raise ValueError("negative value not allowed")
return x
x

result = square(5)

/r/Python
https://redd.it/1mqzamk
A Django/React Transport Rental Platform with 8 Models

Hey r/django! I built Rental, a web app using Django (8 models), React, and SQLite for renting transport. It features dynamic search, booking, user profiles, and admin DB management. Repo: https://github.com/Leongard91/rental

I’m curious about optimizing my Django models or forms for scalability. Any tips on performance or best practices? Stars/feedback appreciated if you find it useful!

/r/django
https://redd.it/1mru1lp
Sync files to cloud and manage access with Django

This is a bit beyond Django, but I'll bet most of you don't do Django then completely walk away from the computer.

I have a website built with Django for my business managing condo associations. I want to have a file storage portal where each member of the association logs in and can see the files of just their association. Further, some users (condo board members) can see association files that regular members can't. This part is all pretty straightforward.

Additionally, the portal across all associations should be synced to my laptop so I can work with the files as needed and they sync to the portal.

My current process is a script running on my laptop so that every time a file changes, it uploads it to S3-compatible storage and writes the directory structure to a JSON file that is also uploaded. When a user clicks the folder in my Django site, it reads the JSON file and displays the files

The problems: 1) this depends on my laptop 2) it's only one way. I'd like an app that runs on my laptop and any employee laptops that does 2 way sync and allows me to manage access to the uploaded

/r/django
https://redd.it/1mrymso
Why are all the task libraries and frameworks I see so heavy?

From what I can see all the libraries around task queuing (celery, huey, dramatiq, rq) are built around this idea of decorating a callable and then just calling it from the controller. Workers are then able to pick it up and execute it.

This all depends on the workers and controller having the same source code though. So your controller is dragging around dependencies that will only ever be needed by the workers, the workers are dragging around dependencies what will only ever be needed by the controller, etc.

Are there really no options between this heavyweight magical RPC business and "build your own task tracking from scratch"?

I want all the robust semantics of retries, circuit breakers, dead-letter, auditing, stuff like that. I just don't want the deep coupling all these seem to imply.

Or am I missing some reason the coupling can be avoided, etc?

/r/Python
https://redd.it/1mrxbxc
Knowing a little C, goes a long way in Python

I've been branching out and learning some C while working on the latest release for [Spectre](https://github.com/jcfitzpatrick12/spectre). Specifically, I was migrating from a Python implementation of the short-time fast Fourier transform from Scipy, to a custom implementation using the [FFTW C library](https://www.fftw.org/) (via the excellent [pyfftw](https://github.com/pyFFTW/pyFFTW)).

What I thought was quite cool was that doing the implementation first in C went a long way when writing the same in Python. In each case,

* You fill up a buffer in memory with the values you want to transform.
* You tell FFTW to execute the DFT in-place on the buffer.
* You copy the DFT out of the buffer, into the spectrogram.

Understanding what the memory model looked like in C, meant it could basically be lift-and-shifted into Python. For the curious (and critical, do have mercy - it's new to me), the core loop in C looks like (see [here on GitHub](https://github.com/jcfitzpatrick12/spectre-lite/blob/main/src/stfft.c#L264-L291)):

for (size_t n = 0; n < num_spectrums; n++)
{
// Fill up the buffer, centering the window for the current frame.


/r/Python
https://redd.it/1mrutnf
I built a lightweight functional programming toolkit for Python.


### What My Project Does
I built darkcore, a lightweight functional programming toolkit for Python.
It provides Functor / Applicative / Monad abstractions and implements classic monads (Maybe, Result, Either, Reader, Writer, State).
It also includes transformers (MaybeT, StateT, WriterT, ReaderT) and an operator DSL (|, >>, @) that makes Python feel closer to Haskell.

The library is both a learning tool (experiment with monad laws in Python) and a practical utility (safer error handling, fewer if None checks).

### Target Audience
- Python developers who enjoy functional programming concepts
- Learners who want to try Haskell-style abstractions in Python
- Teams that want safer error handling (Result, Maybe) or cleaner pipelines in production code

### Comparison
Other FP-in-Python libraries are often incomplete or unmaintained.
- darkcore focuses on providing monad transformers, rarely found in Python libraries.
- It adds a concise operator DSL (|, >>, @) for chaining computations.
- Built with mypy strict typing and pytest coverage, so it’s practical beyond just experimentation.

### Features
- Functor / Applicative / Monad base abstractions
- Core monads: Maybe, Result, Either, Reader, Writer, State
- Transformers: MaybeT, StateT, WriterT, ReaderT
-

/r/Python
https://redd.it/1ms54hv
HELP Ensuring complete transactions with long running tasks and API requests with SQLAlchemy

Hello, I am having some trouble with my Flask App having to wait long periods of time for to obtain a read write lock on database entries, that are simultaneously being read / written on by long running celery tasks (\~1 minute).

For context, I have a Flask App, and a Celery App, both interacting with the same database.

I have a table that I use to track jobs that are being ran by the Celery app. Lets call these objects JobDBO.

1. I send a request to Flask to create the Job, and trigger the Celery task.

2. Celery runs the job (\~1 minute)

3. During the 1 minute job I send a request to cancel the job. (This sets a flag on the JobDBO). However, this request stalls because the Celery task has read that same JobDBO and is keeping 1 continuous SQLAlchemy session

4. The task finally completes. The original request to cancel the job is fulfilled (or times out by now waiting to obtain a lock) and both the request and celery tasks SQL operations are fulfilled.


Now I understand that this could obviously be solved by keeping short lived sql alchemy sessions, and only opening when reading or writing quickly,

/r/flask
https://redd.it/1ms7bgc
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/1msc4g4
Help me choose Django a Niches.

Hello, guys. I've recently learned Django and python. Now, I want to do freelancing in Upwork but the competition is really high plus I also have no reviews.

So, I want to pick a niche and master it for less competition. The problem is I'm not sure what to choose. Can anyone suggest me? or give me some career advice? TIA

/r/django
https://redd.it/1ms4qy5