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
Send self-destructible emails

I've recently built a small free project called DiscardDraft.

Built with Flask and Nextjs. It's a project that allows people to send emails that would be deleted right after being read.

Check it out here: https://discarddraft.me


/r/flask
https://redd.it/1fanapo
Python 3.13 RC2 Available Today - Python 3.13 available October 1st

Python 3.13 will drop on October 1st.

The second release candidate just dropped today.

Don't be afraid to upgrade.

Install the RC2 from here and run your regression tests for your applications, and be ready to upgrade to Python 3.13 the moment it becomes available on October 1st.

If any of your dependencies fail when running your application on the RC2, immediately raise an issue on their github and complain loudly that they need to make the changes to make it compatible as well as publish binary wheels.


https://www.python.org/downloads/release/python-3130rc2/

/r/Python
https://redd.it/1fbb4qw
Issues with Cloud Run Deployment

I've been trying to solve this deployment issue for 2 days now and am at my wits end. I've deployed on VPSs before but never a managed service like Cloud Run.

All of my request coming from the frontend are getting the Network Error: ERR\_TOO\_MANY\_REDIRECTS. From what I've gathered, there is likely and issue with the way django is processing the internal request from Cloud Run. The google documentation says that we need to add this to our settings.py:

CLOUDRUN_SERVICE_URL = env("CLOUDRUN_SERVICE_URL", default=None)
if CLOUDRUN_SERVICE_URL:
ALLOWED_HOSTS = [urlparse(CLOUDRUN_SERVICE_URL).netloc]
CSRF_TRUSTED_ORIGINS = [CLOUDRUN_SERVICE_URL]
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")


I have added this and still continue to get these errors. I'm really not sure what else to look into or what could be causing this. I'm even will to pay you for your time if someone is willing to get on discord with me and help me work this out.

/r/django
https://redd.it/1fbcybz
Adding Python to Docker in 2 seconds using uv's Python command

Had great success speeding up our Docker workflow over at Talk Python using the brand new features of uv for managing Python and virtual environments. Wrote it up if you're interested:

https://mkennedy.codes/posts/python-docker-images-using-uv-s-new-python-features/

/r/Python
https://redd.it/1fb9qcy
How can I change the name options of this selectField based on which table was selected earlier in the form?

Edit: I fixed this issue by setting name = (column name) in each of the classes

-------------



Pretty much I am using a tutorial to make a form that will change possible selection option based on a previous selection. eg. a user chooses to see data filtered based on site and then have another dropdown with the possible site options.

the tutorial I am using uses only one table (see image one) but I have three different tables that need to be available for selection.

so far I have tried using both a variable and a function to do this but neither have worked. (the variable returned multiple selections of sites.site_name for each id in the table and the function returned multiples of <function results.<locals>.tableOptionName at 0x10e386e50>.

If it helps, the column that contains the names I am trying to display is the the second column the table for all three.

what I have at the moment is in image 2

image 1

image 2

Thank you so much!

/r/flask
https://redd.it/1fbhsk1
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? πŸ› οΈ

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1fbku4v
Custom Template filters for global use

I am building a project and created a filter to format phone numbers. initially I created it inside one of my apps but decided since it could be use for the whole project to put it at project level but now its not working and giving me

TemplateSyntaxError at /
Invalid filter: 'formatphonenumber'


here is the file structure

projectManager/
β”œβ”€β”€ main/
β”‚ └── settings.py
β”œβ”€β”€ onboarding/
β”œβ”€β”€ templates/
β”‚ └── base.html
β”œβ”€β”€ templatetags/
β”‚ β”œβ”€β”€ init.py
β”‚ └── customfilters.py
β”œβ”€β”€ theme/
β”œβ”€β”€ unit/
└──
manage.py

the custom\
filter.py contents

from
django
import


/r/django
https://redd.it/1fbjtdq
Can't get Cloudfront to work (Heroku + Whitenoise)

Hi experts, thanks for any advice: as the title says, am in deployment on Heroku, am using Whitenoise. I have set up CloudFront as per directions from Whitenoise: https://whitenoise.readthedocs.io/en/latest/django.html#instructions-for-amazon-cloudfront, but it just doesn't want to work - e.g. my admin page has no CSS. I have put my app domain under origins in Cloudfront settings of course and have changed no other settings.

Settings:

STATIC_ROOT = BASE_DIR / "staticfiles"

Successful without Cloudfront

STATIC_URL = "static/"

Unsuccessful with Cloudfront

STATIC_HOST = os.environ.get("DJANGO_STATIC_HOST", "")

STATIC_URL = STATIC_HOST + "/static/" #https://xxxxxxxx.cloudfront.net/static

Logs aren't returning errors, but the Browser console is returning various "rejected" messages - it just can't see the Cloudfront resources, or there is some other security setting I need to change. It's driving me nuts: thanks for any tips you can give!

/r/django
https://redd.it/1fbgomg
Need to make sure I added the fields from my model correctly in search_indexes.py file. This is a Haystack/Solr question

Hey guys, new to Reddit here. I'm new to Haystack/Solr. I have a Django project and I'm using Haystack to build a search index for the data in my PostgreSQL database. Here is my `search_indexes.py` code ```

from haystack import indexes

from .models import Arborist





class ArboristIndex(indexes.SearchIndex, indexes.Indexable):

text = indexes.CharField(document=True, use_template=True)

arborist_city = indexes.CharField(model_attr='city')

arborist_state = indexes.CharField(model_attr='state')

price = indexes.PositiveIntegerField()

company_name = indexes.CharField(model_attr='company')

one_star = indexes.PositiveIntegerField(default=0, null=True, blank=True)

two_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

three_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

four_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

five_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

review_by_homeowner = indexes.CharField(model_attr='reviews')

tree_pruning = indexes.CharField(model_attr='tree_pruning')

tree_removal = indexes.CharField(model_attr='tree_removal')

tree_planting = indexes.CharField(model_attr='tree_planting')

pesticide_applications = indexes.CharField(model_attr='pesticide_applications')

soil_management = indexes.CharField(model_attr='soil_management')

tree_protection = indexes.CharField(model_attr='tree_protection')

tree_risk_management = indexes.CharField(model_attr='tree_risk_management')

tree_biology = indexes.CharField(model_attr='tree_biology')





def get_model(self):

return Arborist



def prepare_arborist_cty(self, obj):

return [arborist_city.id for arborist_city in obj.aborist_city_set.active().order_by('-created')\]

```. I'm also following the docs tutorial https://django-haystack.readthedocs.io/en/v2.4.1/tutorial.html. Where I'm stuck, is that some of these fields are different field types than what the tutorial is using, for example, `PositiveInteger` and also some of these fields are from two other models that are foreign keys to this `Arborist` model.



I just want to make sure that I'm setting up the fields properly to be indexed. It's probably best to view this in my Github repo https://github.com/remoteconn-7891/MyProject/tree/master since I have five different model files in my models folder. I was using Discord Django, but they weren't helpful with this

/r/djangolearning
https://redd.it/1fbmrpe
VitePress vs. Material for MkDocs

Hey everyone,
I’m torn between using VitePress and Material for MkDocs to generate documentation for my code.

# mkdocstring support

I prefer VitePress for its interface, but Material for MkDocs can generate HTML directly from the source code and docstrings thanks to mkdocstrings library (see an example here), which VitePress doesn’t seem to support (or maybe I'm missing something?).

# Question

Why is such a common feature not available in VitePress? Would love to hear your thoughts or workarounds!

/r/Python
https://redd.it/1fbs772
global installations or project-specific environments

When installing libraries on python which one is better? Global installations or project-specific environment installation? Can you also write important bulletpoints for each?

/r/Python
https://redd.it/1fbs3ge
Flask authorization question ❓

Welcome, I am a jonuior web developer,
I have a question, now I know how can I implement a an authentication functionality with flask, flask-login, and also can I implement a More than role like an admin role manager role, and an employee role, I defined this roles in the code after the routes definition, and that's not helpful and not easiler in the development, what's the best way to can I implement the authorization functionality? I hope to find something let me to add the authorization feature for the client, as example like if I build a hr management system, the admin can add the employees and can add a new role from the GUI , and can select if The employee can add or read or update for something, and he also can select what is the page's the employee can access to it,
Please share the best resources and toturials for that, thanks guys.


/r/flask
https://redd.it/1fam8as
R Training models with multiple losses

Instead of using gradient descent to minimize a single loss, we propose to use Jacobian descent to minimize multiple losses simultaneously. Basically, this algorithm updates the parameters of the model by reducing the Jacobian of the (vector-valued) objective function into an update vector.

To make it accessible to everyone, we have developed TorchJD: a library extending autograd to support Jacobian descent. After a simple pip install torchjd, transforming a PyTorch-based training function is very easy. With the recent release v0.2.0, TorchJD finally supports multi-task learning!

Github: https://github.com/TorchJD/torchjd
Documentation: https://torchjd.org
Paper: https://arxiv.org/pdf/2406.16232

We would love to hear some feedback from the community. If you want to support us, a star on the repo would be grealy appreciated! We're also open to discussion and criticism.

/r/MachineLearning
https://redd.it/1fbvuhs
winaccent - A Python module for getting Windows' accent color or a shade of it

# What my project does

winaccent allows you to get the Windows' accent color or a shade of it. Works on both Windows 10 and 11 and doesn't require additional dependencies. Useful if you are creating a GUI using Python and you want to style your app with the system's accent color.

# Target audience

It is meant for production.

# Comparison

Unlike other alternatives that only allow you to get the accent color, this project also allows you to get a shade of it. Also, it allows you to listen for accent color changes for easily updating your app's colors to match it.

# Installation

The module can be installed using the following command:

pip install winaccent

# Documentation & Source code

The documentation and the source code is available here: https://github.com/Valer100/winaccent . Feedback is greatly appreciated. If you found this module useful, please consider starring it on GitHub.

/r/Python
https://redd.it/1fbvhmr
Thoughts about my project design

Hey all, hope everyone is good!

Brief introduction to me: A data engineer with 4+ years of experience and 3+ years of experience in AWS who is currently employed at one of the big automative company. I did one freelance django project in the past and now I am doing another one for my wife whom is a yoga instructor.

The requirements of the project:

Subscription based model that people can subscribe and watch her content in the website
Auth, registering, video streaming, stripe, paypal
Assuming will be 50 active users in the beginning can increase to 500 in 1 year
Assuming there will be 30gb of video content in the beginning and it may increase to \~100gb in one year
1 developer is developing the project, it is me

Decisions:

After a pricing research I decided to use digital ocean because it was giving better server with a cheaper cost also the data transfer limits.
I did not wanted to use a managed pg db because of cost also the db load will be very low due to number of active users, for that reason I decided to up all the system on docker
I set hourly email backups, the size

/r/django
https://redd.it/1fbw4se
I need some help with an issue regarding enumerations in Flask.



I need some help with an issue regarding enumerations in Flask.



My model is as follows:



```python

class ApprovalStatus(PyEnum):

PENDING = 'pending'

APPROVED = 'approved'

REJECTED = 'rejected'



class Approval(db.Model):

id = db.Column(db.Integer, primary_key=True)

content_type = db.Column(db.String(50), nullable=False)

content_id = db.Column(db.Integer, nullable=False)

field_name = db.Column(db.String(50), nullable=False)

new_value = db.Column(db.Text, nullable=False)

status = db.Column(SQLAlchemyEnum(ApprovalStatus), default=ApprovalStatus.PENDING)



submitter_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

submit_time = db.Column(db.DateTime, default=current_time)

reviewer_id = db.Column(db.Integer, db.ForeignKey('user.id'))

review_time = db.Column(db.DateTime, default=current_time)

review_comment = db.Column(db.Text)



submitter = db.relationship('User', foreign_keys=[submitter_id\])

reviewer = db.relationship('User', foreign_keys=[reviewer_id\])



__table_args__ = (UniqueConstraint('content_type', 'content_id'),)



u/property

def content(self):

model = getattr(models, self.content_type)

return model.query.get(self.content_id)

```



However, I keep encountering the following error:



```

LookupError: 'pending' is not among the defined enum values. Enum name: approvalstatus. Possible values: PENDING, APPROVED, REJECTED

```



/r/flask
https://redd.it/1fc2ltr
Just Released Version 0.4.0 of Django Action Triggers!

First off, a huge thank you to everyone who provided feedback after the release of version 0.1.0! I've taken your input to heart and have been hard at work iterating. I’m excited to announce the release of **version 0.4.0** of **django-action-triggers**.

There’s still more to come in terms of features and addressing suggestions, but here’s an overview of the current progress.

# What is Django Action Triggers

[Django Action Triggers](https://github.com/Salaah01/django-action-triggers) is a Django library that lets you trigger specific actions based on database events, detected via Django Signals. With this library, you can configure **actions** that run asynchronously when certain triggers (e.g., a model save) are detected.

For example, you could set up a trigger that hits a webhook and sends a message to AWS SQS whenever a new sale record is saved.

# What's New in Version 0.4.0?

Here’s a quick comparison of **version 0.1.0** vs. **version 0.4.0**:

**Version 0.1.0** features:

* Webhook integration
* RabbitMQ integration
* Kafka integration

**Version 0.4.0** features:

* Webhook integration
* RabbitMQ integration
* Kafka integration
* Redis integration
* AWS SQS (Simple Queue Service) integration
* AWS SNS (Simple Notification Service) integration
* Actions all run asynchronously
* Actions can have a timeout

# Looking Forward

As always, I’d love to hear your feedback. This project started as a passion project but has

/r/Python
https://redd.it/1fc2t9a
Audio Book Reader: Read .epub, .rtf, and .txt as audio books!

https://github.com/RNRetailer/audio-book-reader



What My Project Does

This program is for the Linux terminal.

It breaks text files into lines and reads them out loud one line at a time.

Your progress for each file is stored in a .json file.

You can choose to skip to a certain line by passing it as a parameter when running the script.

Please make an issue or a pull request if you think any changes are needed.

Thanks!



Target Audience (e.g., Is it meant for production, just a toy project, etc.)

Anyone who uses Linux and wants to have a text file read out loud to them.



Comparison (A brief comparison explaining how it differs from existing alternatives.)

I haven't looked into alternatives in this space, I just made it on a whim.



/r/Python
https://redd.it/1fb3f8p
How do I stop my Socket IO chat room from disconnecting users 30 seconds after joining the room? I'm hosting using Adaptable's free plan.

I've been working on a chat room application using Flask and JS where you can join a room and message people and it works fine on my local server but when I access the site from Adaptable, 30 seconds into joining a room, it boots the user out, so I was wondering if anyone knows why this is happening. I've tried a couple solutions already including implementing a heartbeat. Any help would be great, I'm just trying to diagnose the issue. Thanks!

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