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
I have a angular + Django backend . When I am click on a button, it calls an api which starts execution of a process via python. It takes almost 2mins to complete the process. Now I want that suppose when a user closes the tab, the api call should be cancelled. How to achieve that?



/r/djangolearning
https://redd.it/1j7acrn
The current landscape of UI components and design systems for Django applications

When I start developing a new web application, it's almost always a Django project. ORM, migrations, templates, etc. It's that familiar all-in-one package we've all come to love.

But the one area that keeps bugging me is how to add componentization of the UI and fill in a design system to the components. I don't want to always start from the scratch when starting a new project but I haven't solved this issue for me.

I know I could just use template snippets for reusability but it feels off and I've seen myself how quickly the DX of going through template after another falls off.

So what's the current rave for adding components to a Django codebase? Web components? django-components? Daisy UI? django-cotton? And how about adding a design system in? Tailwind? Bootstrap 5?

Note that I don't want a full-fledged SPA with a UI framework like React or Svelte on the client-side. The more SSR the merrier.

Would love to hear your experiences and suggestions.



/r/django
https://redd.it/1j7jtmr
Implemented 20 RAG Techniques in a Simpler Way

# What My Project Does

I created a comprehensive learning project in a Jupyter Notebook to implement RAG techniques such as self-RAG, fusion, and more.

# Target audience

This project is designed for students and researchers who want to gain a clear understanding of RAG techniques in a simplified manner.

# Comparison

Unlike other implementations, this project does not rely on LangChain or FAISS libraries. Instead, it uses only basic libraries to guide users understand the underlying processes. Any recommendations for improvement are welcome.

# GitHub

Code, documentation, and example can all be found on GitHub:

https://github.com/FareedKhan-dev/all-rag-techniques

/r/Python
https://redd.it/1j7rl6o
This is just the beginning and I'm crumbling with Django learning curve

I cannot thank everyone enough for motivating me to learn Django regardless of my age in the last post. And I'm trying to work on it. But, yet I find all this code overwhelming. I have been just following UDEMY tutorial. Sometimes the code work, sometimes does not. And I had to look up over the internet to fix it . And that searching takes like 30 minutes for each bug I encounter. Prolly, it is because I have no partner to learn with. Nevertheless, just look at the code I just posted. I was understanding until Employee.objects.all() from models was called and displayed in template. But, now with this foreign key, select_related and even with line 30,37 where employees are called with array position. I cannot comprehend it much. Should I just go through this again and again and practice or is there any easy way out. or any books to help me. I guess tutorial is not the way. Please please please help me overcome this learning curve. I do not wanna feel overwhelmed. I have already finished 30 hours of video and practice along with. And I can only give 3 hours everyday for 1 year

/r/django
https://redd.it/1j7e35h
Performance gains of the Python 3.14 tail-call interpreter were largely due to benchmark errors

I was really surprised and confused by last month's claims of a 15% speedup for the new interpreter. It turned out it was an error in the benchmark setup, caused by a bug in LLVM 19.

See https://blog.nelhage.com/post/cpython-tail-call/ and the correction in https://docs.python.org/3.14/whatsnew/3.14.html#whatsnew314-tail-call

A 5% speedup is still nice though!

/r/Python
https://redd.it/1j7usy1
I built Lightweight & Flexible AI Agent Manager

# What My Project Does

I built a simple, lightweight tool that allows developers to create and manage AI agents efficiently. This package provides:

* **Agent Definition**: Assign roles and instructions to agents.
* **Model Flexibility**: Easily switch between popular LLMs.
* **Tool Integration**: Equip agents with tools for specific tasks.
* **Multi-Agent Orchestration**: Seamlessly manage interactions between agents.

# Target Audience

This tool is designed for developers working with **Django, Flask, FastAPI**, and other Python frameworks who need:

* A **lightweight** and **flexible** alternative to Langchain/Langraph.
* Easy integration into **views, background tasks**, and other workflows.
* A **simpler learning curve** without excessive abstraction.

# Comparison with Existing Tools

Unlike **Langchain, Langraph, and Pydantic**, which have a **steep learning curve** and heavy abstractions, this package is:

**Lightweight & Minimal** – No unnecessary overhead.
**Flexible** – Use it wherever you want.
**Supports Multiple LLMs** – Easily switch between:

* OpenAI
* Grok
* DeepSeek
* Anthropic
* Llama
* GenAI (Gemini)

# GitHub

Check it out and show some love by **giving stars and feedback**!
🔗 [**https://github.com/sandeshnaroju/agents\_manager**](https://github.com/sandeshnaroju/agents_manager)

/r/Python
https://redd.it/1j7td2q
Redis as cache.


At work, we needed to implement Redis for a caching solution. After some searching, btw clickhouse has great website for searching python packages here.
I found a library that that made working with redis a breeze Redis-Dict.


from redis_dict import RedisDict
from datetime import timedelta

cache = RedisDict(expire=timedelta(minutes=60))

request = {"data": {"1": "23"}}

web_id = "123"
cache[web_id] = request["data"]


Finished implementing our entire caching feature the same day I found this library (didn't push until the end of the week though...).



/r/Python
https://redd.it/1j7zgsd
I built a better Python playground with file handling and libraries

**What My Project Does**

Online Python compiler with:

* file uploads
* data viz
* Python libraries
* script scheduling
* keyboard shortcuts, dark mode, autocomplete, etc.

**Target Audience**

Python students, low-coders

**Comparison**

No sign up or usage limits (unlike Replit, PythonAnywhere). Has libraries, file uploads and scheduling, which most online Python environments don't have.

Uses the incredible Pyodide to execute Python using WebAssembly: [https://github.com/pyodide/pyodide](https://github.com/pyodide/pyodide)

**Try it here:** [https://cliprun.com/online-python-compiler-with-file-upload](https://cliprun.com/online-python-compiler-with-file-upload)

/r/Python
https://redd.it/1j82tnw
At what point is HTMx not going to suffice for large ERP?

I'm starting a new project that will be large with lots of moving parts, complex modules, and different spaces for different users. Its an ERP, so you can imagine the types of data and functionality I will be building.

For past large projects, I have always used Django DRF as an API backend and a VueJS frontend to consume the API. This has worked well in the past, providing a rich user interface and experience. However, it always comes at the cost of overall project complexity given that there are two separate code bases to manage.

So, instead of DRF + VueJS I'm considering Django templates + HTMx. I've worked with HTMx in the past, but not extensively. I've also always heard the phrase "unless you're building a spreadsheet type app, HTMx will be fine". OK - but, I might need some of that level of complexity given that I'm building an ERP. I just don't want to get into Django + HTMx and realize 6 months down the road, HTMx isn't going to cut it.

My question is - have any of you built really large projects with complex UI/UX and only used the Django templates + HTMx? Can

/r/django
https://redd.it/1j7zd1c
blob-path: pathlib-like cloud agnostic object storage library

# What My Project Does
Having worked with applications which run on multiple clouds and on-premise systems, I’ve been developing a library which abstracts away some common functionalities, while being close to the pathlib interface
tutorial notebook

Example snippet
from blob_path.backends.s3 import S3BlobPath
from pathlib import PurePath

bucket_name = "my-bucket"
object_key = PurePath(
"hello_world.txt"
)
region = "us-east-1"
blob_path = S3BlobPath(
bucket_name,
region,
object_key,
)

# check if the file exists
print(blob_path.exists())

# read the file
with blob_path.open("rb") as f:
# a file handle is returned here, just like `open`
print(f.read())


destination = AzureBlobPath(
"my-blob-store",
"testcontainer",
PurePath("copied_from") / "s3.txt"
)

blob_path.cp(destination)



Features:
- A pathlib-like interface for handling cloud object storage paths, I just love that interface
- Built-in serialisation and deserialisation: this, in my experience, is something people have trouble with when they begin abstracting away cloud storages. Generally because they don’t realise it after some time and it keeps getting deprioritised. Users instead rely on stuff like using the same bucket across the application
- Having a pathlib interface where all the functionality is packaged in the path itself (instead of writing “clients” for each cloud backend make this trivial)
-

/r/Python
https://redd.it/1j85fui
Should I Use CDNs for Bootstrap & HTMX in My Django App?

Hey everyone,

I'm currently building a Django app and considering using CDNs to serve Bootstrap and HTMX. A friend of mine warned me against using CDNs in production, but neither of us have much experience, so I wanted to get insights from more experienced developers.

Are there any security, performance, or reliability concerns I should be aware of when relying on CDNs for these libraries? Would it be better to self-host them instead? If so, what’s the best approach for managing updates efficiently?

I’d really appreciate any advice or best practices you can share. Thanks in advance!

/r/django
https://redd.it/1j83ywp
What is your go-to way of structuring Django projects?

Been using Django for a bit now and I feel like my structure is lacking. Sometimes I just put all models in the main app, sometimes I split them across apps and that's a mess.

Wondering how to test out for the sweet spot.

/r/djangolearning
https://redd.it/1j7u3bc
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:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **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](#daily-beginner-thread-link) 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](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/1j8dhis
Keeping Azure Blob synchronised with Django Database

This is the Image Model for a Gallery app. I realised that the default behaviour of django-storages is that it uploads files to AzureBlob but doesn't delete the files when the database entry is deleted. Not sure if this is the way to do it? It seems like it should be really common but I've had to dig up the AzureBlob SDK manually to do it. I also have a thumbnail function for faster loading (will change some parameters later)

class Image(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    description = models.TextField()
    image_file = models.ImageField(upload_to='images/')
    thumbnail_file = models.URLField(null=True, blank=True)  # Store Azure URL instead of ImageField
    uploaded_at = models.DateTimeField(auto_now_add=True)

    def save(self, *args, **kwargs):       


/r/django
https://redd.it/1j8i62i
Launched a hosting platform optimized for Django deployment

Hey, I'm Isaac. I've been deploying Django apps for years, and one thing that always annoyed me is how expensive it is—especially if you have multiple small projects.



The problem:

1. Paying for idle time – Most hosting options charge you 24/7, even though your app is idle most of the time.

2. Multiple apps, multiple bills – Want to deploy more than one Django service? Get ready to pay for each, even if they get minimal traffic.



I built Leapcell to fix this. It lets you deploy Django apps instantly, get a URL, and only pay for actual usage. No more idle costs.



If you’ve struggled with the cost of Django hosting, I’d love to hear your thoughts!

Try Leapcell: **https://leapcell.io/**

/r/django
https://redd.it/1j8mftd
Your notes on Django Fundamentals

Does anyone here have an organised notes that you have written on Django Fundamentals while you learned it? And if you did could you please share it. It’ll be useful for me to refer and also update my existing notes.

/r/djangolearning
https://redd.it/1j5kmk0
What are the best linters and language servers for python?

I am confused at the different language servers, linters, and formatters available. Here is what I have been able to figure out, is this correct?

Ruff is a linter / code formatter. It has overtaken Black and Flake8 as the best / most popular. Rust.\
\
JEDI is a library (~~but not a language server?~~) that supports autocompletion, goto, and refactoring.

Pyright is a language server maintained by Microsoft. It supports type checking, goto, autocomplete, similar to JEDI. It is written in TypeScript. I think Pylance is technically the language server and Pyright is the type checker (??)

MyPy is also a language server. It is considered slower and less fully featured than Pyright. It is used primarily because it supports plugins, such as for Pydantic and Django. It was started in 2012 and is written in Python.\
\
PyLSP/Python LSP Server is another language server but it requires another implementation such as JEDI to work. I am not sure what the advantages/disadvantages of it are.\
\
Some commercial IDEs like PyCharm use their own linters and type checkers.\
\
I use the Helix editor and by default it will use Ruff, JEDI, and pylsp together. While it works great,

/r/Python
https://redd.it/1j8bd2n
The best CI/CD strategy with Django App

Hi everyone! I've launched the personal project based on django and untill the last moment, after some updates I just log in to the server and update everything on my own via ftp, and then just restart gunicorn, which was fine until now. Since it starts being hard to manage project in such a way, there is a need to implement CI/CD for it, so i would really like to get an advise from expirienced (or who has dealt with it at least) developers, what are the best steps to do that without Docker (in case of Docker everything is kinda clear), but with Git for sure

The questions ISN'T about certain CI/CD tool or piece of code, but just about strategy. I definitely reffered to SO, but it's all about specific issues with particular pieces of advise.

Ideally, i would like to see the following: there is a stable version (should it be another branch or just a generated folder with timestamp? - also the question), there is a new version with features - I deliver it with job to the server and if everything is ok - mark it as stable, if it's not - to rollback to previous one.

/r/django
https://redd.it/1j8qbt1
I built a simple Terminal UI for pytest, feedback welcome!

# What My Project Does

I missed an easy, simple and quick way to run pytests in the terminal.

Link to project: https://github.com/0-sv/pytesttui.

My project lets you run `pytesttui` in your terminal. After opening, it shows you a tree of all your tests in the tests directory. Still in an early stage, so all it does is if you hit "r" and selected your test, it will run it. It scaled in the repository I use at work which contains about 500 tests. It is more efficient than running it in an IDE because it runs instantly, which is why I like terminal UIs.

If you'd like to try it and you have a Macbook, then visit my github page and download the release. Extract the files and place it in a PATH location like \~/.local/bin. You will probaby have to accept a security warning by MacOS, which is done by browsing to the "Privacy & Security" tab in settings and clicking on "Allow anyway" after running it. Make sure `pytest` is also accessible in a PATH location or installed using pip.

# Target Audience

This is meant as a toy project and just to get some feedback, and if there's enough attention, then I will keep

/r/Python
https://redd.it/1j8qdqa
Nested Images in Wagtail

I have noticed by default images break the list structure and is inserted outside of the list. Is it possible to have nested images within a list item in Wagtail?

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