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
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/1kaagpl
Clean method for ORM

Hello People,
I just picked up a ticket in which there appears to be DB savings in the clean() method of a model. I’ve never seen this before and I think it’s probably not good practice as clean() should be validating data only and not actually saving anything to the DB.

My question, how do you go about updating an attribute from another model?

Such as ModelA gets updated. So we have to update ModelB timestamp.
I was thinking of using a postsave() but unsure.


Context:

Model1:
Cost Model

def clean():
cost.account.timestamp =
timezone.now()
cost.account.validated
save()

Model2:
Account Model




/r/django
https://redd.it/1ka6ht5
Looking for Django project

Hey everyone!
I'm planning to start a Django project and I'm looking for some cool and interesting project title ideas. It can be anything—web apps, automation tools, dashboards, or something creative! If you have any suggestions or ideas, please drop them here.
Would love to hear your thoughts!

/r/djangolearning
https://redd.it/1k6bu2v
lblprof: Easily see your python code’s performance, Line by Line

Hello [r/Python](https://www.reddit.com/r/Python/),

I built this small python package ([lblprof](https://github.com/le-codeur-rapide/lblprof)) because I needed it for other projects optimization (also just for fun haha) and **I would love to have some feedback on it.**

# What my project Does ?

The goal is to be able to know very quickly how much time was spent on each line during my code execution.

I don't aim to be precise at the nano second like other lower level profiling tool, but I really care at seeing **easily** where my 100s of milliseconds are spent. I built this project to replace the old good `print(start - time.time())` that I was abusing.

This package profile your code and display a tree in the terminal showing the duration of each line (you can expand each call to display the duration of each line in this frame)

Example of the terminal UI: [terminalui\_showcase.png (1210×523)](https://raw.githubusercontent.com/le-codeur-rapide/lblprof/refs/heads/main/docs/terminalui_showcase.png)

# Target Audience

Devs who want a quick insight into how their code’s execution time is distributed. (what are the longest lines ? Does the concurrence work ? Which of these imports is taking so much time ? ...)

# Installation

pip install lblprof

The only dependency of this package is pydantic, the rest is standard library.

# Usage

This package contains **4 main functions**:

* `start_tracing()`: Start the tracing of

/r/Python
https://redd.it/1ka71qs
Some security in LLM based apps

Hi everyone!

I'm excited to share a project I've been working on: Resk-LLM, a Python library designed to enhance the security of applications based on Large Language Models (LLMs) like OpenAI, Anthropic, Cohere, and others.

## What My Project Does
Resk-LLM focuses on adding a protective layer to LLM interactions, helping developers experiment with strategies to mitigate risks like prompt injection, data leaks, and content moderation challenges.

🔗 GitHub Repository: https://github.com/Resk-Security/Resk-LLM

## Motivation
As LLMs become more integrated into apps, security challenges like prompt injection, data leakage, and manipulation attacks have become serious concerns.
However, many developers lack accessible tools to experiment with LLM security mechanisms easily.

While some solutions exist, they are often closed-source, narrowly scoped, or too tied to a single provider.

I built Resk-LLM to make it easier for developers to prototype, test, and understand LLM vulnerabilities and defenses — with a focus on transparency, flexibility, and multi-provider support.

The project is still experimental and intended for learning and prototyping, not production-grade security yet — but I'm excited to open it up for feedback and contributions.

## Target Audience
Resk-LLM is aimed at:

Developers building LLM-based applications who want to explore basic security protections.

Security researchers interested in LLM attack surface exploration.

Hobbyists or students learning about the security challenges of generative

/r/Python
https://redd.it/1kahx5r
Implementing a confirmation view after a form submission

Hi everyone,

I'm very new to Django and web development. I have a simple form where a user can enter a list of data, say names. Since the user isn't savvy with SQL, I want the app to basically update some rows in our database based on the list. But before the changes are written to the database, I want there to be a view which basically shows what the user entered into the form. So here's the interface/sequence I'm trying to implement:

1. User is presented with a textbox which allows them to submit a list, eg "Bob, John"
2. Django app presents the user with a summary of the input and asks them to confirm, eg "you have entered 2 names, double check that this is correct". If the database doesn't know about Bob or John, then this is when it would notify the user.
3. The Django app performs the relevant update

I've been researching this online and I'm seeing different recommendations. The simplest solution seems to be to have a confirmation view which has a hidden input with the same data as the original form? But then wouldn't the app be processing the input data twice? Do you guys have

/r/django
https://redd.it/1kanhms
RYLR: Python Library for Lora uart modules

Hi, RYLR is a simple python library to work with the RYLR896/406 modules. It can be use for configuration of the modules, send message and receive messages from the module.


What does it do:

Configuration modules
Get Configuration data from modules
Send message
Receive messages from module

Target Audience?

Developers working with rylr897/406 modules

Comparison?

Currently there isn't a library for this task

/r/Python
https://redd.it/1kak4r7
[P] hacking on graph-grounded retrieval for SEC filings + an AI “legal pen-tester”—looking for feedback & maybe collaborators

Hey ML friends,

Quick intro: I’m an ex-BigLaw attorney turned founder. For the past few months I’ve been teaching myself anything AI/ML, and prototyping two related ideas and would love your thoughts (or a sanity check):

1. **Graph-first ingestion & retrieval**
* Take 300-page SEC filings → normalise tables, footnotes, exhibits → emit embedding JSON-L/markdown representations .
* Goal: 50 ms query latency over the whole doc with traceable citations.
* Current status: building a patent-pending pipeline
2. **Legal pen-testing RAG loop**
* Corpus: 40 yrs of SEC enforcement actions + 400 class-action complaints.
* Potential work thrusts: For any draft disclosure, rank sentences by estimated Rule 10b-5 litigation lift and suggest rewrites with supporting precedent.

All in all, we are playing with long-context retrieval. Need to push a retrieval encoder beyond today's oken window so an entire listing document fits in a single pass. This might include extending the LoCo/M2-BERT playbook potentially to pull the right spans from full-length filings (tens-of-thousands of tokens) without brittle chunking. We are also experimenting with some scaffolding techniques to approximate infinite context window. Not an expert in this so would love to hear your thoughts on best

/r/MachineLearning
https://redd.it/1kag8w2
Bring Python 3.10’s match/case to 3.7+ with patterna

# Python Structural Pattern Matching for 3.7+

Patterna is a pure Python library that backports the structural pattern matching functionality (match/case statements) introduced in Python 3.10 to earlier Python versions (3.7 and above). It provides a decorator-based approach to enable pattern matching in your code without requiring Python 3.10.

# Installation

pip3 install patterna

# GitHub, PyPI, Docs

GitHub: saadman/patterna
PyPI: patterna/0.1.0.dev1/

(Post edited for those who wants more context into the inner workings)

Wiki For those Further interested in the inner workings: https://deepwiki.com/saadmanrafat/patterna

# Usage

from patterna import match

class Point:
matchargs = ("x", "y")

def init(self, x, y):
self.x = x
self.y = y

u/match
def describe
point(point):
match point:
case Point(0, 0):


/r/Python
https://redd.it/1kardx9
Python projects for beginners

Hello,

I'm very new to Python and looking beginner friendly tasks for practice.
I don't have any idea what I could prgramm.
I know you can use Python for practically everything.
My interest is programming a calculator or a game.
I've already asked chat gpt for ideas but it gives you the codes to cooy but that's no very helpful.
Do you have any ideas which codes helped you?
Are there good sites you could recomment?

Thanks



/r/Python
https://redd.it/1kat5bh
What is lightweight framework means in context of flask

What exactly lightweight framework means always heard that throughout various yt videos and documentation about flask that flask is a lightweight framework.

My question is flasks can't create big websites or web application as compared to django or nodejs ..

/r/flask
https://redd.it/1kat0pw
How to go from Mid Level to Senior / Expert Django Python developer

I am developing django, python, postgreSQL projects more than couple of years now. I will not consider myself as a fresher or junior in my job But how can I go forward to become senior, expert level?

From your experience, what are the best ways to develop this kind of mindset and skill set? How can I effectively reason about complex system design and architecture? Are there particular resources, practices, or ways of thinking that have helped you transition from a competent developer to a senior or expert level?

I would greatly appreciate any advice, insights, or recommendations.

/r/django
https://redd.it/1karcb5
What is learning curve in flask

I have started flask but I did not found any good video I am confused what to learn

Like there is so many things you have to do in flask
To start

Like libraries,
Request
Url_for
redirected
werkzeug
login library

etc..
I want the learning curve to which library and for what

/r/flask
https://redd.it/1kan3ae
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

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