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
Building a Machine Learning Model from Scratch in Python

Model Architecture, Evaluation, Data Prep, and more covered in a tutorial: https://codedoodles.substack.com/p/build-your-own-machine-learning-model



/r/Python
https://redd.it/1i2z59j
Best practices for Flask and DynamoDB?

I've built a few side projects with Flask and DynamoDB and, while it's not a complicated feat, I feel like things are always a bit more cumbersome than they should be. Perhaps it's by Django background, but I think there has to be a better way to do what I'm doing. Does anyone have a favorite resource (tutorial, course, book) to learn best practices for Flask+DynamoDB?

/r/flask
https://redd.it/1i2x4i2
Friday Daily Thread: r/Python Meta and Free-Talk Fridays

# Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

## How it Works:

1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

## Guidelines:

All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.

## Example Topics:

1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟

/r/Python
https://redd.it/1i338dp
Prevent accidentally running python scripts with missing or incorrect shebang

I do this too often so I realized I could nip it with a chmod wrapper:

#!/bin/bash
# Prevent accidentally running python scripts with missing or incorrect shebang
if [ "$1" == "+x" && "$2" =~ \.py$ ]; then
firstline=$(head -n 1 "$2")
if [[ "$first
line" != "#!"python ]]; then
echo "Error: Python file detected with invalid shebang"
exit 1
fi
fi
/usr/bin/chmod "$@"

Since it's always 1. write myscript.py, 2. chmod +x myscripy.py, 3. ./myscript.py, 4. oops.

Does anyone else make this mistake? Sometimes I even write !/bin/bash...
Some lines end up being valid bash, e.g import statements via /usr/bin/import from imagemagick, and have seen random files generated (hopefully nothing destructive!).

/r/Python
https://redd.it/1i328xc
How do I Make Calender

I want to make a calender app. Should I use fullcallenderio? I've tried to make it myself but I have limited knowledge on JS

/r/flask
https://redd.it/1i2qpa8
For those of you who user raspberry pi scripts and eink screen, what driver do you use?

It is for waveshare 7.3 inch color. I looked in their documentation and added this python code

from waveshare_epd import epd7in3g,
epd = epd7in3g.EPD()



This might be stretching what is allowed to post here, but I thought I would ask. Does that look correct. I previously had a python script working correctly with a black and white screen.

/r/Python
https://redd.it/1i3dnma
flask and underscores in headers

I am writing a server that handles request from a client app that I do not have any control over. The app sends a specific header "access_token" which my server needs to receive. Unfortunately, by default, Flask seems to throw these values away. I can see the header traveling over the network in my Wireshark output, but when it arrives at my server Flask is completely blind to it. Since I can't control the client app the general solution of "just don't use underscores" isn't going to work for me. Anyone have a solution that allows Flask to receive and process headers with underscores in them?

/r/flask
https://redd.it/1i2h8po
Function use counters in Visual Studio Code

Many language extensions in VSCode include features that show the number of references to a specific function, class, or entity.


We've just released an extension that brings this functionality to Python, displaying reference counters for top-level functions and classes. Clicking a counter reveals a list of references.


Try it out here Tooltitude for Python


P.S. This is a newly released extension, and we’d love your feedback!


P.P.S. It’s not our first VSCode extension. Check out Tooltitude for Go, which has been on the marketplace for ~2 years, offering similar functionality for Go and more, with plenty of positive reviews.







/r/Python
https://redd.it/1i3hbqd
Grokking at the Edge of Numerical Stability Research

>Grokking, the sudden generalization that occurs after prolonged overfitting, is a surprising phenomenon challenging our understanding of deep learning. Although significant progress has been made in understanding grokking, the reasons behind the delayed generalization and its dependence on regularization remain unclear. In this work, we argue that without regularization, grokking tasks push models to the edge of numerical stability, introducing floating point errors in the Softmax function, which we refer to as Softmax Collapse (SC). We demonstrate that SC prevents grokking and that mitigating SC enables grokking without regularization. Investigating the root cause of SC, we find that beyond the point of overfitting, the gradients strongly align with what we call the naïve loss minimization (NLM) direction. This component of the gradient does not alter the model's predictions but decreases the loss by scaling the logits, typically by scaling the weights along their current direction. We show that this scaling of the logits explains the delay in generalization characteristic of grokking and eventually leads to SC, halting further learning. To validate our hypotheses, we introduce two key contributions that address the challenges in grokking tasks: StableMax, a new activation function that prevents SC and enables grokking without regularization, and ⊥Grad,

/r/MachineLearning
https://redd.it/1i34keg
I made a simple python scripts that automate deletion of your ChatGPT chats

Hey! I was considering whether to post this or not, and I decided other people may have had this issue too, where you been using chatGPT all the time, there's like a thousand chats, I was in this predicament and made a program that I made on Linux for firefox with Selenium, that essentially automatically goes through and starts deleting your chats on chatGPT.

I made it on Linux, I have no clue the compatibility with windows, and it's for firefox, If anyone else who's in this predicament wants to use it feel free!
Github:

https://github.com/TheBlewish/Automated-ChatGPT-Chats-Deletion

/r/Python
https://redd.it/1i35k7g
Showcase: Python-Lotion – A Lightweight Wrapper for the notion-client (Beta)

Hi everyone,



I’d like to share my new project: Python-Lotion, a lightweight Python wrapper for the notion-client. 🚀



What My Project Does



Python-Lotion is designed to make working with the Notion API simpler and more intuitive. It wraps around the popular notion-client library, providing a cleaner interface for fetching, creating, and managing Notion pages and blocks. This is especially useful for developers looking to integrate Notion into their Python projects with minimal effort.



Target Audience



This project is aimed at:

• Developers working on production applications requiring Notion API integrations.

• Enthusiasts exploring Notion automation for personal use.

• Anyone looking for a lightweight and straightforward alternative to existing Notion API libraries.



Comparison



Here’s how Python-Lotion differs from existing alternatives like notion-client:

• Simpler syntax: Python-Lotion focuses on reducing boilerplate code for common tasks.

• Lightweight design: Aims to stay small and focused, avoiding unnecessary complexity.

• Work in progress: Currently in beta, with plans to expand features and improve usability over time.



What’s Next

• Expanding the documentation to make onboarding easier.

• Adding advanced block management functionality, such as creating, updating, and organizing blocks within pages.



The source code is open on GitHub: https://github.com/koboriakira/python-lotion.

Feedback, suggestions, and ideas for improvement are highly welcome!



Thanks for checking it out! 🙌

/r/Python
https://redd.it/1i35f2u
AnonChat - Anonymous chat application

**What My Project Does**

A simple and anonymous chat application written in Python3 using sockets.

**Target Audience**

Just my first project to test my skills.

target: everybody who just want to test.

**Comparison**

* Simple
* lightweight design using tkinter
* Secure

The source code in open on Github [https://github.com/m3t4wdd/AnonChat](https://github.com/m3t4wdd/AnonChat)

Feedback, suggestions, and ideas for improvement are highly welcome!

Thanks for checking it out! 🙌

/r/Python
https://redd.it/1i3ob10
It Shouldn't Be This Much Work to Sync Data Between Django and Vue SPA

I love Django, I love Vue SPAs - but I don't like spending time writing boilerplate code to link the frontend to backend models. Serializers, Views, Services, State Management, Caching, yeah... it's a lot. So I built a system that gives Vue SPAs reactive, real-time sync with Django models. No boilerplate - just write Django models and get a reactive frontend data layer where every component's view is automatically, instantly synced with the actual database state, whether changes come from other clients, background tasks, admin panels, or anywhere else. It's snappy enough to power real-time applications like chat apps and leverages Django Rest Framework under the hood.

Demo - two clients both connected to the remote backend, staying in sync

https://i.redd.it/p89ph27enkde1.gif

Out of the box, you get smart caching that invalidates correctly when CRUD operations occur (on another client, or a Django backend initiated save), optimistic UI updates, and sophisticated backend performance optimizations. Request serializer caching, automatic model schemas, and real-time synchronization come for free - without writing any additional plumbing code. The system intelligently manages data consistency, providing a seamless, responsive experience across client and server. This approach should also work for React apps - but I've not looked into this yet.

Minimal

/r/django
https://redd.it/1i3jv5d
Best practices mocking in Django Rest Framework

From my studying I learned that to have tests that are not brittle you should use as little mocking as possible.

In my API endpoints, I have secured it with the Django OAuthlib that requires the requests to have Authorization header with a token in it. If I want to test the endpoint functionality only and thus mock the call to the library to always allow the request whatever the token value is, is that a brittle test? Since if I change my authentication method, all my mocks will have to be updated? What is the general best practice for mocking with Django DRF?

/r/djangolearning
https://redd.it/1i3i9yz