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
Weak Incentives (Py3.12+) — typed, stdlib‑only agent toolkit

What My Project Does
Weak Incentives is a lean, stdlib‑first runtime for side‑effect‑free background agents in Python. It composes dataclass‑backed prompt trees that render deterministic Markdown, parses strict JSON, and records plans/tool calls/staged edits in a session ledger with reducers, rollback, a sandboxed VFS, planning tools, and optional Python‑eval (via asteval). Adapters (OpenAI/LiteLLM) are optional and add structured output + tool orchestration.

Target Audience
Python developers building LLM agents or automation who want reproducibility/auditability, typed I/O, and minimal dependencies (Python 3.12+).

Comparison
Most frameworks emphasize graph schedulers/optimizers or pull in heavy deps. Weak Incentives centers deterministic prompt composition and fail‑closed structured outputs, with a built‑in session/event model (reducers, rollback) and sandboxed VFS/planning; it works provider‑free for rendering/state and adds adapters only when you evaluate.

Source Code:
https://github.com/weakincentives/weakincentives

/r/Python
https://redd.it/1oohs41
pyro-mysql v0.1.8: a fast MySQL client library

What My Project Does
pyro-mysql is a fast sync/async MySQL library backed by Rust
Repo
https://github.com/elbaro/pyro-mysql/
Bench
https://github.com/elbaro/pyro-mysql/blob/main/BENCHMARK.md
For small sync SELECT, `pyro-mysql` is 40% faster than `mysqlclient`
For small async SELECT, pyro-mysql is 30% faster than aiomysql
For large SELECT, `pyro-mysql (async)` is x3 faster than `aiomysql/asyncmy`
An experimental wtx backend (not included in v0.1.8) is x5 faster than aiomysql.
For sync INSERT, `pyro-mysql` is 50% faster than `mysqlclient`
For async INSERT, pyro-mysql is 20% slower than aiomysql
Target Audience: the library aims to be production-ready
Comparison: see the previous post

v0.1.8 adds the sqlalchemy support with the following dialects:

mysql+pyro\_mysql://
mysql+pyro_mysql_async://
mariadb+pyro\_mysql://
mariadb+pyro_mysql_async://

It is tested against related test suites from the sqlalchemy repo.

/r/Python
https://redd.it/1oo4uuk
Optimizing filtered vector queries from tens of seconds to single-digit milliseconds in PostgreSQL

We actively use pgvector in a production setting for maintaining and querying HNSW vector indexes used to power our recommendation algorithms. A couple of weeks ago, however, as we were adding many more candidates into our database, we suddenly noticed our query times increasing linearly with the number of profiles, which turned out to be a result of incorrectly structured and overly complicated SQL queries.

Turns out that I hadn't fully internalized how filtering vector queries really worked. I knew vector indexes were fundamentally different from B-trees, hash maps, GIN indexes, etc., but I had not understood that they were essentially incompatible with more standard filtering approaches in the way that they are typically executed.

I searched through google until page 10 and beyond with various different searches, but struggled to find thorough examples addressing the issues I was facing in real production scenarios that I could use to ground my expectations and guide my implementation.

Now, I wrote a blog post about some of the best practices I learned for filtering vector queries using pgvector with PostgreSQL based on all the information I could find, thoroughly tried and tested, and currently in deployed in production use. In it I try to provide:

\-

/r/Python
https://redd.it/1ooy326
What is the point of CSRF for form validation?

Hello,

I am currently in the process of building a small app aiming to localy train small AI models. I keep seeing on the internet that desactivating the CSRF in forms is super dangerous, but is it if the app will be run localy only, and not have "sensitive" (ie account management) informations uploaded?

Right now I have forms to upload a project name and training files, I don't think I need CSRF for these?

Thanks in advance

/r/flask
https://redd.it/1oo94xx
Free Introductory Python Book (amongst others)

I recently discovered the wonderful collection of free textbooks made available by the openstax organisation (https://openstax.org/). There are many books available covering a wide range of disciplines but there’s one in particular that may be of interest to redditors here, namely Introduction to Python Programming: https://openstax.org/details/books/introduction-python-programming

Another notable example is Principles of Data Science: https://openstax.org/details/books/principles-data-science

There are many others including texts on mathematics and computer science.

/r/Python
https://redd.it/1op1ghd
First event Django Day India is here - November 8, 2025

We’re excited to invite you to Django Day India 2025, the biggest Django community event in the country!

The schedule is now live, featuring talks on Django, Python, architecture, scalability, and open source from some of the most active contributors in the ecosystem.

Keynote Speakers:

Thibaud Colas — President, Django Software Foundation & Tech Lead at Torchbox

Sarah Abderemane — Vice President, Django Software Foundation & Software Engineer at Kraken Tech

Whether you’re building with Django daily or just passionate about web development, this is a great chance to learn, connect, and be part of India’s growing Django community

Tickets are closing tomorrow , so grab yours before they sell out!

tickets: https://konfhub.com/djangoday-india-2025

Official website: djangoday.in

Come for the code, stay for the community!

/r/django
https://redd.it/1op14p2
Looking for a Mentor

Hello Everyone,

I started learning Django today, I need a mentor, who can guide me in this Journey.

TIA.

/r/djangolearning
https://redd.it/1ooqqdb
Can anyone suggest me resources to learn django, need to make an ai chat ap with semantic search on chats



/r/djangolearning
https://redd.it/1oms8o8
Flask-Compress 1.22 released

2 releases were made recently to add support for streaming responses.
No more buffering the entire response to compress it, it now happens on the fly

/r/flask
https://redd.it/1op4w9f
Create a Flask app-website

Hi I am learning python and I would like to create a website using Flask like a personal page. How does it work? Do you know useful materials? How do I buy a domain? Should I buy it?

/r/flask
https://redd.it/1ondv3r
Best practice for Django PKs in 2025 - Auto-Incrementing or UUIDField?

I am wondering what the consensus is for a public website and if you should use Django's default auto-incrementing IDs or switch to using UUID4 as the primary key.

I've read arguments of both sides and am still not able to draw a conclusion.

I'm slowly settling on keep the PK as the Django auto-incrementing and adding separate UUID field that is a generated UUID4 value.

Thoughts?

import uuid
from django.db import models
from nanoid import generate

class Product(models.Model):
# Keep the default original Django auto-incrementing PK

# uuid4 for internal use and for distributed databases to work together
uuid = models.UUIDField(
default=uuid.uuid4,
editable=False,
db_index=True,
)

#

/r/django
https://redd.it/1opi4xl
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

# Weekly Thread: Professional Use, Jobs, and Education 🏢

Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.

---

## How it Works:

1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.

---

## Guidelines:

- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.

---

## Example Topics:

1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?

---

Let's help each other grow in our careers and education. Happy discussing! 🌟

/r/Python
https://redd.it/1opjo5c
FastAPI’s creator on the framework’s popularity, FastAPI Cloud, self-taught developers, and more

Hi there! I’m a huge fan of FastAPI for its focus on developer experience. This year it became the most popular Python framework, which comes as no surprise.

Recently I had the chance to chat with Sebastián Ramírez, the creator of FastAPI. We talked about why it became so popular since its launch seven years ago, what’s next on the roadmap, FastAPI Cloud, the impact of the faster CPython initiative, and being a self-taught developer (yes, he’s self-taught!). We also talked about that famous tweet about companies asking for more years of experience with a framework than it’s even existed.

Sebastián was super nice, kind and humble. I didn't expect someone so popular to be so down-to-earth.

I think there are some useful takeaways here for other devs in this community, so I'm sharing the link below. I welcome any feedback for how I can make these interviews better.

https://youtu.be/iaDRYUQ0OMM

/r/Python
https://redd.it/1op2dut
Cleanest way to handle a dummy or no-op async call with the return value already known?

Since there doesn't appear to be an async lambda, what's the cleanest way you've found to handle a batch of async calls where the number of calls are variable?

An example use case is that I have a variable passed into a function and if it's true, then I do an additional database look-up.

Real world code:

        emails, confirmed = await asyncio.gather(
            self._get_emails_for_notifications(),
            (
                self._get_notification_email_confirmed()
                if exclude_unconfirmed_email
                else asyncio.sleep(0, True)
            ),
        )
        if not emails or not confirmed:
            raise NoPrimaryNotificationEmailError(self.user_id)
        return emails[0]

Using a sleep feels icky. Is this really the best approach?

/r/Python
https://redd.it/1opdok1
Nuttiest 1 Line of Code You have Seen?

Quality over quantity with chained methods, but yeah I'm interested in the maximum set up for the most concise pull of the trigger that you've encountered

/r/Python
https://redd.it/1ooysmw
htmx is back with version 4.0 - the fetch()ening

So even though Carson said that 2.0 is the final version and there will not be version 3.0, he didn’t lie - it's version 4.0.

https://preview.redd.it/f15rokhuvmzf1.png?width=577&format=png&auto=webp&s=925c3c3689333134a1f2dcb5aaee737f1dc0f7bd

There are some cool backstage enhancements and also some breaking changes if you want to use the new version. But some really fix the annoying quirks.

I know lots of Django folks use the library, so I thought I’ll post it here. I know I use it today almost on all my new projects when fit.

Official announcement here: https://htmx.org/essays/the-fetchening/
I wrote a short migration piece with some extra unneeded info on Medium here: https://medium.com/@alonwo/htmx-4-0-the-fetchening-a-developers-guide-to-what-s-actually-changing-28fb80b36bd9

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