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
Django ORM Race Condition tip

/r/django
https://redd.it/1gh4ep2
PyCon US 2025 Site Launches, CFP Live!

## PyCon US 2025

We're excited to announce that the PyCon US 2025 website and call for (talk) proposals are officially live!

Please help us spread the word, and if you're interested in giving a talk read the guidelines and submit one!
- Blog: <https://pycon.blogspot.com/2024/11/pycon-us-2025-launches.html>
- PyCon Website: https://us.pycon.org/2025

/r/Python
https://redd.it/1ghdnfr
Handling errors with OOP

I'm currentrly trying to create a bank system using OOP with Flask, I wanted that when the if statement that I underlineded in the screenshot goes false, it should redirect the user to a "failure operation" page or something like that.

https://preview.redd.it/mjzdaqgp0cyd1.png?width=509&format=png&auto=webp&s=a0793a592fc091fd2359341d175794c8d1b6a825

https://preview.redd.it/4trn3xte0cyd1.png?width=497&format=png&auto=webp&s=c7cb19bac027aa8111bbf83a6600ccf16022d530



/r/flask
https://redd.it/1ghct6x
Thank you r/Python - I'd like to give something back

Last month I asked this community if anyone would be willing to take my new course on how to code Python and give me some feedback in return.

The response was overwhelming and I am so grateful! Loads of people took the course and I got tonnes of feedback which I was able to implement. I'm really pleased to share that since then I have now had over 300 enrolments on the course and a small amount of income coming my way.

This is massive for me, since this was my first course and I am now going forward onto making more courses - this time on the topic of simulation in Python.

So as a thank you, I'd like to give away 100 complimentary vouchers for the course, just for this community: https://www.udemy.com/course/python-for-engineers-scientists-and-analysts/?couponCode=THANKSREDDIT

Please take one of the vouchers if you feel you might benefit from the course. It is aimed at people with some kind of existing technical skillset (e.g. engineers, scientists, etc) so has a focus on data, statistics and modelling. The main libraries covered are numpy, pandas and seaborn.

Thanks again r/Python

/r/Python
https://redd.it/1gh1svl
State of the Art Python in 2024

I was asked to write a short list of good python defaults at work. To align all teams. This is what I came up with. Do you agree?

1. Use uv for deps (and everything else)
2. Use ruff for formatting and linting
3. Support Python 3.9 (but use 3.13)
4. Use pyproject.toml for all tooling cfg
5. Use type hints (pyrite for us)
6. Use pydantic for data classes
7. Use pytest instead of unittest
8. Use click instead of argparse


/r/Python
https://redd.it/1ghiln0
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/1ghjow6
Feature Friday: LoginRequiredMiddleware!

The LoginRequiredMiddleware (new in Django 5.1) is great for any Django app that is mostly behind authentication. When enabled, views will require login by default. No more login_required decorators everywhere!

So how do you make a view not require login?

Use the new login_not_required decorator! This works just like the login_required decorator but for the opposite: any view it decorates will bypass the login requirement and be public. Be sure to put it on your login page otherwise you might get caught in redirect loops!

If you're building an app that mostly requires login, using the LoginRequiredMiddleware is a great way to simplify code and prevent accidentally leaking content—by making your app private by default.

Read more in the documentation here: https://docs.djangoproject.com/en/5.1/ref/middleware/#django.contrib.auth.middleware.LoginRequiredMiddleware

/r/django
https://redd.it/1gh51ai
I have finally released a new version for my package, Arrest 0.1.10

After many months of procrastination, I have finally managed to release version 0.1.10 of my package Arrest.

What it does

It is a package that lets you declaratively write a REST service client, configured with the sets of resources, routes and methods you want to call, and provide Pydantic models for request and responses to automatically parse them during the HTTP calls. Arrest also provides retry mechanisms, exception handling, automatic code generation from the OpenAPI specification, and much more.

Target audience

Primarily backend developers working on communicating with multiple web services from a Python client. It can also be useful in a microservice architecture where you have to write API bindings for all the dependant sevices for another service.

Comparison

There are packages that does similar things which I got to know about from this subreddit after my initial post. For example:

1. flask-muck by u/beef-runner
2. django-rest-client by u/16withScars

The key highlights of the new version are:

1. Support for arbitrary python types for request and response. These can be `list`, `dict`, `dataclass`, or `pydantic.BaseModel`, or anything that is JSON serializable.
2. Added custom hooks for handling different types of exceptions.
3. Revamped retry mechanism to make it more configurable and no implicit retries built-in

/r/Python
https://redd.it/1ghjt23
Any flask github suggestion

I'm currently learning Flaks and i want to improve my quality of code.

Do you have any good repo to look for ?

/r/flask
https://redd.it/1ghcthh
pgmooncake: run python on your Postgres tables

**What it does**

[pg\
mooncake](https://github.com/Mooncake-Labs/pgmooncake) brings a columnstore table to Postgres with DuckDb execution. These tables are written as Iceberg and Delta tables (parquet files + metadata) to your object store.

Query them outside of Postgres with DuckDB, Polars, Pandas, Spark directly without complex pipelines, stitching together ad-hoc files, or dataframe wangling.


**Target audience**

Product engineers, data engineers, data scientist.


**Comparison**

You can use psycopg2 / sqlalchemy today. But the approach here is fundamentally different. You're writing data to an s3 bucket. You can share that bucket to your data science, engineering, analyst team without giving them access to your Postgres.


There are some Parquet exporters in Postgres (pg\
duckdb, pg_parquet, pg_analytics). pg_mooncake actually exposes table semantics inside of Postgres (updates, deletes, transactions). And table semantics outside of Postgres (Iceberg/Delta).

Story time!

I'm one of the founders of Mooncake Labs. We are building the simple lakehouse without the complex pipelines / data engineering infra.

Modern apps are built on Postgres. And we want to bring the python processing and analytics closer to this ecosystem.

Postgres and Python are all you need.



/r/Python
https://redd.it/1ghgmmq
Projects for open source contributions

I am a junior developer currently and I am interested in contributing to some good, impactful open source projects that are making people's lives easier. I am primarily looking for projects in Python and Django to contribute to.
Can I get some recommended projects, especially in django (or django-rest for that matter). Since I'm a beginner and do not have a rich experience (especially in large-scale projects) I would like to be recommended projects that are not so daunting (like django itself) :)

/r/django
https://redd.it/1ghpb2r
Run a command, then stream the stdout in real time?

Been researching how to do this and simply couldn't get any of the answers / idk if they are even relevant to me.

I have a command that runs after a POST to the server, via `subprocess.run`. Let's just say it's `ping -c 100 8.8.8.8`.

import subprocess

u/app.route("/whatever", methods=["POST"])
def whatever():
proc = subprocess.run(
"ping -c 100 8.8.8.8",
shell = True,
capture_output = True
)

I want to receive the stdout of that command from HTTP(S), appearing in real time as they come. I'm fine if we're just checking stdout every, say, 5 seconds, as long as the output is sent to the user as it

/r/flask
https://redd.it/1gi0vjs
A filesystem navigator for the terminal


## What My Project Does

Terminal-tree is an experimental terminal-based filesystem navigator. You can explore your filesystem and preview files within the terminal.

Very early stage, I've been playing with the look and feel, but it could form the basis of a larger tool. Possibly a file manager, or file picker.

It is built with the Textual framework (which I also develop), and is a reasonably good example of a more complex widget which integrates blocking calls with an async framework.

The code is currently a single file:

https://github.com/willmcgugan/terminal-tree/blob/main/tree.py

More details on the repository:

https://github.com/willmcgugan/terminal-tree


## Target Audience

Anyone interested in building a terminal app. It is fun to play with (hopefully) but doesn't have any functionality on top of navigating and previewing files.

I'm open to suggestions on what could be built on top of this.

## Comparison

You could compare it to Ranger, Midnight Commander, or similar tools.

/r/Python
https://redd.it/1gi3tqo
I discovered context processors

Today I discovered context processors, basically I needed a variable to be globally accessible across all the templates, and wola Django has a built-in and elegant solution.

I love this tool so much!

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