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
form."field" vs models."field": Defining field parameters in a single location

I plan to pass my models to the forms.py file and I'm wondering if it's possible to define parameters for form.field & models.field in the same line? For example: I want to define required=True & blank = Flalse.

userfirstname = (???).CharField(required=True, blank=False, max_length= 40, verbose_name="First Name")



edit: had true and false reversed in first paragraph

/r/djangolearning
https://redd.it/1ikxiji
RedCoffee: Making SonarQube Reports Shareable for Everyone

Hi everyone,

I’m excited to share a new update for [RedCoffee](https://pypi.org/project/redcoffee/), a Python package that generates SonarQube reports in PDF format, making it easier for developers to share analysis results efficiently.

# Motivation:

Last year, while working on a collaborative side project, my team and I integrated SonarQube to track code quality. Since this was purely a learning-focused initiative, we decided to use the SonarQube Community Edition, which met our needs—except for a few major limitations:

* There was no built-in way to share the analysis report.
* Our SonarQube instance was running locally in a Docker container.
* No actively maintained plugins were available to generate reports.

After some research, I found an old plugin that supported PDF reports, but it had not been updated since 2016. Seeing no viable solution, I decided to build RedCoffee, a CLI-based tool that allows users to generate a PDF report for any SonarQube analysis, specifically designed for teams using the Community Edition.

I first introduced RedCoffee on this subreddit around nine months ago, and I received a lot of valuable feedback. Some developers forked the repository, while others raised feature requests and reported bugs. This update includes fixes and enhancements based on that input.

**What's new in the recent update ?**

/r/Python
https://redd.it/1iklryk
How to Synchronize a Dropdown and Slider in Plotly for Dynamic Map Updates?

Hi all,

I’m working on a dynamic choropleth map using Plotly, where I have:
1. A dropdown menu to select between different questions (e.g., ‘C006’, ‘C039’, ‘C041’).
2. A slider to select the time period (e.g., 1981-2004, 2005-2022, 1981-2022).

The map should update based on both the selected question and period. However, I’m facing an issue:
• When I select a question from the dropdown, the map updates correctly.
• But, when I use the slider to change the period, the map sometimes resets to the first question and doesn’t update correctly based on the selected question.

I need the map to stay synchronized with both the selected question and period.

Here’s the code I’m using:

# Define the full questions for each column
questionlabels = {
'C006': 'Satisfaction with financial situation of household: 1 = Dissatisfied, 10 = Satisfied',
'C039': 'Work is a duty towards society: 1 = Strongly Disagree, 5 = Strongly Agree',
'C041': 'Work should come first even if it means less spare time: 1 = Strongly Disagree, 5 = Strongly Agree'
}

# Combine all periods into a single DataFrame with a new column for the period
means
period1merged'Period' = '1981-2004'
meansperiod2merged['Period'] = '2005-2022'
means
period3merged'Period' = '1981-2022'

combineddf = pd.concat([meansperiod1merged, meansperiod2merged, meansperiod3merged])

# Create a list of frames for

/r/Python
https://redd.it/1ikm1t1
ParLlama v0.3.15 released. Supports Ollama, OpenAI, GoogleAI, Anthropic, Groq, Bedrock, OpenRouter

# What My project Does:

PAR LLAMA is a powerful TUI (Text User Interface) written in Python and designed for easy management and use of Ollama and Large Language Models as well as interfacing with online Providers such as Ollama, OpenAI, GoogleAI, Anthropic, Bedrock, Groq, xAI, OpenRouter

# Whats New:

# v0.3.15

* Added copy button to the fence blocks in chat markdown for easy code copy.

# v0.3.14

* Fix crash caused some models having some missing fields in model file

# v0.3.13

* Handle clipboard errors

# v0.3.12

* Fixed bug where changing providers that have custom urls would break other providers
* Fixed bug where changing Ollama base url would cause connection timed out

# Key Features:

* Easy-to-use interface for interacting with Ollama and cloud hosted LLMs
* Dark and Light mode support, plus custom themes
* Flexible installation options (uv, pipx, pip or dev mode)
* Chat session management
* Custom prompt library support

# GitHub and PyPI

* PAR LLAMA is under active development and getting new features all the time.
* Check out the project on GitHub or for full documentation, installation instructions, and to contribute: [https://github.com/paulrobello/parllama](https://github.com/paulrobello/parllama)
* PyPI [https://pypi.org/project/parllama/](https://pypi.org/project/parllama/)

# Comparison:

I have seem many command line and web applications for interacting with LLM's but have not found any TUI related applications

# Target Audience

Anybody that loves

/r/Python
https://redd.it/1il7vim
Sync clipboard across guest and host with both running on wayland

# What My Project Does

WayClipSync enables clipboard sharing between guest and host in wayland sessions.

# Target Audience

People who like to tinker with different virtual machines and use wayland compositors that do not automatically support the clipboard sync.

# Comparison

spice-vdagent only works on X-org. On wayland the simplest way to copy from host is xsel -ob and send to host from guest is xsel -ib. It was annoying for me to remember to use this command, so I made this.

# Note

This program requires wl-clipboard to work

Github

/r/Python
https://redd.it/1il8lcd
Tailwind v4 problems with Flask

Hey guys I installed Tailwind v4 with CLI to work with Flask but I am having problems in that the UI does not show everything it must show (for example, colors). Anyone with the same issue? By the way v3 works fine!

/r/flask
https://redd.it/1il8x4i
IntentGuard - verify code properties using natural language assertions

I'm sharing IntentGuard, a testing tool that lets you verify code properties using natural language assertions. It's designed for scenarios where traditional test code becomes unwieldy, but comes with important caveats.

What My Project Does:

Lets you write test assertions like "All database queries should be parameterized" or "Public methods must have complete docstrings"
Integrates with pytest/unittest
Uses a local AI model (1B parameter fine-tuned Llama 3.2) via llamafile
Provides detailed failure explanations
MIT licensed

 Working Today:

Basic natural language assertions for Python code
pytest/unittest integration
Local model execution (no API calls)
Result caching for unchanged code/assertions
Self-testing capability (entire test suite uses IntentGuard itself)

⚠️ Known Limitations:

Even with consensus voting, misjudgments can happen due to the weakness of the model
Performance and reliability benchmarks are unfortunately not yet available

Why This Might Be Interesting:

Could help catch architectural drift in large codebases
Useful for enforcing team coding standards
Potential for documentation/compliance checks
Complements traditional testing rather than replacing it

Next Steps:

1. Measure the performance and reliability across a set of diverse problems
2. Improve model precision by expanding the training data and using a stronger base model

Installation & Docs:

pip install intentguard

GitHub Repository

Comparison: I'm not aware of any direct alternatives.

Target Audience: The tool works but needs rigorous evaluation -

/r/Python
https://redd.it/1ilfqtm
Need advice with search functionality design

Hi, I've been developing my first project in Django and one of its features is that users can search for movies/series by title (shouldn't match the exact name) and add them to their watchlist. The problem I ran into is that I'm not sure of how to provide the search results.
The first thing that came to my mind was to use API that I'd found on rapidapi, but the free plan offers only 500 requests per month which might get problematic when the app is used by multiple users. Then I thought I would query a database first and if there are no matches, I'd make an API call and store it into the database.
However, now I can't know for sure if the search query contains any possible match. For example, it can be some nonsense, which won't retrieve any data from the db and I would need to make API request to find out that there are no such movies. Or I can't be certain that the query will get enough data from the db. Like, if the first 3 Jurassic Park movies are in the db and a user searches for 'jurassic', they

/r/django
https://redd.it/1ilazjf
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/1ilhw29
R LIMO: Less is More for Reasoning

>We present a fundamental discovery that challenges our understanding of how complex reasoning emerges in large language models. While conventional wisdom suggests that sophisticated reasoning tasks demand extensive training data (often >100,000 examples), we demonstrate a striking phenomenon: complex mathematical reasoning abilities can be effectively elicited with surprisingly few examples. This finding challenges not only the assumption of massive data requirements but also the common belief that supervised fine-tuning primarily leads to memorization rather than generalization. Through comprehensive experiments, our proposed model LIMO demonstrates unprecedented performance and efficiency in mathematical reasoning. With merely 817 curated training samples, LIMO achieves 57.1% accuracy on the highly challenging AIME benchmark and 94.8% on MATH, improving the performance of previous strong SFT-based models from 6.5% to 57.1% on AIME and from 59.2% to 94.8% on MATH, while only using 1% of the training data required by previous approaches. Most remarkably, LIMO demonstrates exceptional out-of-distribution generalization, achieving 40.5% absolute improvement across 10 diverse benchmarks, outperforming models trained on 100x more data, directly challenging the prevailing notion that SFT inherently leads to memorization rather than generalization. Synthesizing these pioneering results, we propose the Less-Is-More Reasoning Hypothesis (LIMO Hypothesis): In foundation models where domain knowledge has been comprehensively encoded during pre-training, sophisticated reasoning capabilities can emerge through minimal but precisely orchestrated demonstrations of cognitive processes.

/r/MachineLearning
https://redd.it/1ile9nu
FastAPI Guard - A FastAPI extension to secure your APIs

Hi everyone,

I've published FastAPI Guard some time ago:

Documentation: rennf93.github.io/fastapi-guard/

GitHub repo: github.com/rennf93/fastapi-guard

What is it?
FastAPI Guard is a security middleware for FastAPI that provides:
- IP whitelisting/blacklisting
- Rate limiting & automatic IP banning
- Penetration attempt detection
- Cloud provider IP blocking
- IP geolocation via IPInfo.io
- Custom security logging
- CORS configuration helpers

It's licensed under MIT and integrates seamlessly with FastAPI applications.

Comparison to alternatives:
- fastapi-security: Focuses more on authentication, while FastAPI Guard provides broader network-layer protection
- slowapi: Handles rate limiting but lacks IP analysis/geolocation features
- fastapi-limiter: Pure rate limiting without security features
- fastapi-auth: Authentication-focused without IP management

Key differentiators:
- Combines multiple security layers in single middleware
- Automatic IP banning based on suspicious activity
- Built-in cloud provider detection
- Daily-updated IP geolocation database
- Production-ready configuration defaults

Target Audience:
FastAPI developers needing:
- Defense-in-depth security strategy
- IP-based access control
- Automated threat mitigation
- Compliance with geo-restriction requirements
- Penetration attempt monitoring

Feedback wanted

Thanks!

/r/Python
https://redd.it/1ilhbkk
Django REST framework, Django Ninja, FastAPI with Pydantic, and Golang API serialization performance.

A few months ago I wrote a post about comparing the API serialization performance retrieve large amount of records in Django REST Framework, Django Ninja, and Golang. I provided a step-by-step guide in optimization for Django as well as dockerized example for each framework tested. A lot of you liked it, and one common ask was, how does FastAPI compared.

It's taken me a while to sit down and work on this again, but I have now included a dockerized example of FastAPI with SQLAlchemy and Pydantic on the same set of data models with exact same API for comparison. I also added a dockerized example of Locust to do testing now. You can check it out and test it for yourself: https://github.com/oscarychen/building-efficient-api

I gotta say I was expecting FastAPI with Pydantic to perform not far behind Django Ninja, because the serialization of response data mechanism was expected to be similar. I am actually surprised FastAPI is quite a bit faster. Obviously, if we strip parsing response payload through the schema/serializer, Django REST Framework and Django Ninja are a lot faster, but typically on most APIs we would have those mechanism as part of response data parsing, and FastAPI does it significantly

/r/django
https://redd.it/1ilp876
Two Fast Auth - A FastAPI extension to implement 2FA

Hi everyone,

I've published Two Fast Auth:

Documentation: rennf93.github.io/two-fast-auth/

GitHub repo: github.com/rennf93/two-fast-auth

What is it?

Two Fast Auth is a FastAPI middleware that provides seamless two-factor authentication implementation with:

- QR code generation for authenticator apps
- Time-based one-time password (TOTP) verification
- Secure recovery code management
- Optional secret encryption
- Middleware integration for route protection
- Production-ready configuration defaults

MIT licensed and designed specifically for FastAPI applications.

Comparison to alternatives:
- fastapi-jwt-auth: Focuses on JWT authentication without native 2FA
- python-otp: Provides OTP generation but no framework integration
- authlib: General-purpose auth library without FastAPI-specific middleware

Key differentiators:
- Native FastAPI middleware implementation
- Built-in QR code generation endpoint
- Recovery code lifecycle management
- Fernet encryption for secret storage
- Zero-configuration defaults for quick setup
- Active maintenance with production use cases

Target Audience:
FastAPI developers needing:
- Quick 2FA implementation without vendor lock-in
- Compliance with security standards requiring MFA
- Recovery code workflows for end-users
- Encrypted secret storage capabilities
- QR code-based authenticator app setup

Feedback wanted :)

Thanks!

/r/Python
https://redd.it/1ilhnfm
Unknown field(s) (usablepassword) specified for CustomUser. Check fields/fieldsets/exclude attributes of class CustomUserAdmin.

I inherited a CustomUser class from AbstractUser like this:

class CustomUser(AbstractUser):
passclass CustomUser(AbstractUser):
pass

Here is the admin for this class:

from django.contrib import admin
from django.contrib.auth import get
usermodel
from django.contrib.auth.admin import UserAdmin

from .forms import CustomUserChangeForm, CustomUserCreationForm

CustomUser = get
usermodel()


class CustomUserAdmin(UserAdmin):
add
form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
listdisplay = [
"email",
"username",
"is
superuser",
]


admin.site.register(CustomUser, CustomUserAdmin)

The forms only define email and username:

class

/r/djangolearning
https://redd.it/1ile16j
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/1ilt1is
Inviting Collaborators for a Differentiable Geometric Loss Function Library

Hello,
I am a grad student at Stanford, working on shape optimization for aircraft design.

I am looking for collaborators on a project for creating a differentiable geometric loss function library in pytorch.

I put a few initial commits on a repository here to give an idea of what things might look like:
Github repo

Inviting collaborators on twitter

/r/Python
https://redd.it/1ilzsly
Question about store environment variables

I am trying to store secret environment variables. All the tutorials I have checked tell me to download python-datoenv and create a .env file. My file is called .flaskenv. Is that technically wrong? I followed Miguel's mega tutorial and he told me to call that file .flaskenv.

/r/flask
https://redd.it/1ilmnpc