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
Trending on GitHub globally 3 days in a row: SuperDuperDB, a Python framework for integrating AI with major databases (making them super-duper)

It is for building AI (into your) apps easily without complex pipelines and make your database intelligent (including vector search), definitely check it out: https://github.com/SuperDuperDB/superduperdb

/r/Python
https://redd.it/18ec2p7
Working on updating the PyDev debugger to use sys.monitoring... I just love my multi-monitor setup with LiClipse ;)

Ok, so, I'm updating the PyDev debugger to use sys.monitoring...Hopefully it'll land soon (I've been working on and off in it for a while and not that much is missing for a final release).

Now, I stopped to breath a little and I just realized I really like using LiClipse with multiple monitors.

My window arrangement using LiClipse

/r/Python
https://redd.it/18eb2aq
Django email, need help

I'm trying to send an email to people when 3 or fewer days are remain, I'm using Django, this is the models.py in my main app, I want to automatically send emails when 3 days or less remain I'm using 4.2

class sub(models.Model):

id = models.UUIDField(default=uuid.uuid4, primary_key = True, editable = False)

provider = models.CharField(max_length=70)

tier = models.CharField(max_length=40)

date_started = models.DateField(auto_now=False, auto_now_add=False)

date_end = models.DateField(auto_now=False, auto_now_add=False, )

author = models.ForeignKey(User, on_delete=models.CASCADE)



def remain(self):

today = date.today()

remaining_days = (self.date_end - today).days

return(remaining_days)

​

​

​

def get_absolute_url(self):

return reverse('sub-detail', kwargs={'pk':self.id})

/r/django
https://redd.it/18eh2h9
What 12,500 Surveys and 6,300 Salaries Data Points Taught Us About Jobs in Germany & Switzerland?

Over the past 2 months, we've delved deep into the preferences of jobseekers and salaries in Germany (DE) and Switzerland (CH).

The results of over 6'300 salary data points and 12'500 survey answers are collected in the Transparent IT Job Market Reports. If you are interested in the findings, you can find direct links below (no paywalls, no gatekeeping, just raw PDFs):

https://static.swissdevjobs.ch/market-reports/IT-Market-Report-2023-SwissDevJobs.pdf

https://static.germantechjobs.de/market-reports/IT-Market-Report-2023-GermanTechJobs.pdf

/r/django
https://redd.it/18eldlp
Unable to connect to the local mysql database

I am trying to create a basic authentication framework for which I need to connect my flask app to a local mysql database, and my credentials seem to be correct as the pymsyql code below works and the localhost page renders the database contents correctly, however, the flasj_mysqldb code does not work and gives the error "error": "'NoneType' object has no attribute 'cursor'"
I have tried looking at different sources all of which say the database credentials might be a problem, but I know for sure that this is not the case. Any help is appreciated.

erroneous code:

from flask import Flask, jsonify
from flaskmysqldb import MySQL

server = Flask(name)
server.config["MYSQL
USER"] = "superuser"
server.config"MYSQL_PASSWORD" = "superpass"
server.config"MYSQL_HOST" = "localhost"
server.config"MYSQL_DB" = "auth"
mysql = MySQL(server)

@server.route("/")
def index():
try:
with mysql.connection.cursor() as cur:


/r/flask
https://redd.it/18ep76i
Django Messages Vs HttpResponse message for Forms

I understand that messages are used to display after a page refresh but let's say you're using HTMX so there isn't a page refresh, would it still be ok to use messages rather than a HttpResponse to show a message or is there some sort of disadvantage of doing so?

I find messages to be a little cleaner than a simple HttpResonse for this case.

Example:

messages.add_message(self.request, messages.SUCCESS, "Thank you! We will get back to you as soon as possible.")

vs

return HttpResponse('<p class="success">Thank you! We will get back to you as soon as possible.</p>')  

&#x200B;

/r/django
https://redd.it/18eq1ny
Django without using Models

I am pretty new to Django with 2-3 years of Python experience writing automation scripts for various tasks. I have read the documentation twice, but I am not sure if what I applied here is the best practice .

The use case is the following:

1. I want the user to be able to login-logout to my site
2. I have create a basic web navigation using html
3. I have created a django form that the user can supply 5 parameters and submit
4. I am creating an item in a directory of my current app (e.g ./myapp/my_directory)

Everything works fine while in development but I am just not sure if that is the best practice here. The worklfloaw on step 4 is that

1. I am creating a directory of let's say a car firm and then
2. subdirectories of their car models,
3. I save some pictures (.jpg) of each model
4. I zip the car firm's directory and delete the original directory
5. I provide a list of downloadable links for all the .zip files in that directory and my plan is to wipe the directory once per month so I doesn't occupy a

/r/django
https://redd.it/18en11d
No changes detected with MAKEMIGRATION command after moving to new DataBase

Hello! I am Trying to Learn Database Setup and migrations in different Scenarios.

So this is what I did
1. Connected to the POSTGRES database on railway.app.
2. Ran first migration command for Django (after initiating project)
3. Removed the Entire DataBase on Railway (to see how Django responds)
4. Created a New Database again on the railway.app
5. Updated the variables for new DB credentials in Django
6. After Running the DEVELOPMENT server, I Found the Session Table Missing Error
7. Tried MAKE MIGRATIONS command, result (No changes detected)


So how Do you Deal with this Scenario, considering I have backed up the Data and I no need to worry about losing Data. How do I restore or reperform Migrations as this is not for app but the migrations which Django needs to Run the entire Project.


&#x200B;

/r/django
https://redd.it/18evv2x
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/18eqnxv
I'm running Django through docker and I want to make it live-update when a change is made to the project (templates included). Is it possible?

A possible way I found was through volumes and docker-compose, but it didn't work for me and I didn't fully understand how it worked.

I also found something along the lines of watchdog, but I don't think it works for a docker context

Any help is appreciated!

/r/django
https://redd.it/18ehiz3
I made Arrest, a small utility to wrap your API calls from your Python application

Hey guys! I'm super excited to announce arrest. It is a small library that you can use to define the structure of the REST Apis your Python application will be interacting with. it provides a straightforward way to call the different routes in your API and additionally enriches them with Pydantic classes for data validation. And it is also backward compatible with pydantic@v1.10.13.

I would greatly appreciate your feedback and useful opinions/improvements on this. Here are the docs if you wanna check that out.

Thanks a lot!

/r/Python
https://redd.it/18eys56
Kanban in the CLI with kanban-python

HoHoHo again
After some great feedback and feature requests I present to you the new version of
kanban-python your kanban terminal app written in python:

Code here: https://github.com/Zaloog/kanban-python


Install with:
python -m pip install kanban-python


during the course of the last month the following features were added:
- moved to XDG Basedir Spec for config and data files
- Directory Scanner to automatically scan e.g. .py files for '# TODO' Patterns and generate tasks out of that.
- better options to change settings and show task details
- a new report function to generate an overall report (.md file) and
show a github-like contribution table

Thanks for your support so far, and I hope kanban-python helps you boost your productivity.
If you have feedback, feel free to reach out here, or create an issue.

Have a great day

/r/Python
https://redd.it/18es539
Livestream PS5 or PC Gameplay into OpenCV

I wrote this script after surprisingly finding very little existing code online about capturing windows.

This script can be used to capture PlayStation 5 gameplay in real time into OpenCV for further image processing, or capture a game window on PC.

Along the way I found out that graphics is more complicated than I thought. Windows does not make it particularly easy to capture windows that are hardware accelerated, and most existing libraries do not work when the window goes off screen or is obscured. My script works with both with good performance!

This could be used to analyse the video for some event (using image/text detection), send a message, record some score, or even act as a master for a microcontroller robot (Arduino etc) operating the controller!

https://github.com/lorcan2440/View-PS5-Screen-Remote-Play

The repo contains a guide for how to set it up. If you'd like to use it and are having trouble just leave a comment here or raise an issue there and I'll try to help. I've also made a C++ implementation since most of the relevant functions are just calling from Windows DLLs so the conversion was easy. C++ will have slightly better performance but you need to set up OpenCV for C++ by yourself

/r/Python
https://redd.it/18f5vyy
I like this docstring from django source code

If found this:

"""
This module collects helper functions and classes that "span" multiple levels
of MVC. In other words, these functions/classes introduce controlled coupling
for convenience's sake.
"""

So nice.

Especially this line:

In other words, these functions/classes introduce controlled coupling
for convenience's sake

controlled coupling

I like it.

/r/django
https://redd.it/18f6khm
SCRABBLE IN TERMINAL

Hey everyone, this is my first serious python project. I (hope) it works in terminal after cloning it and running rework file. All other info is in README so make sure you check how to play it before you do. Hope you all like it!

I'm planning to advance it and add some graphics. Any piece of advice would be appreciated!

Scrabble repository on github

In case you find any error or anything to improve you can fork it and make pull requests.

&#x200B;

Scrabble

/r/Python
https://redd.it/18f9tb6
Django HTML Formatting issue - DjHTML

Hey,


So prettier started working again after I fixed an issue with my extensions and it's doing 1 or 2 spaces indentation, I prefer 4. It also formats django template tags in a way I don't like. I seen people recommend DjHtml so I installed that but it doesn't seem to fix the Django template tags. I want it to format the below HTML so it looks better, what do I need to do? I'm a beginner. See how my initial templatetags are side by side, I rather them under each other.


HTML:

{% extends "base.html" %} {% load static %} {% block extracss %}
<link rel="stylesheet" href="{% static 'profiles/css/profile.css' %}" />
{% endblock %} {% block page
header %}
<div class="container header-container">
<div class="row">
<div class="col"></div>
</div>
</div>
{% endblock %} {% block content %}
<div class="overlay"></div>
<div class="container">


/r/django
https://redd.it/18f6cdu
Multiple apps for different roles

I'm planning for a Django project, and at the moment I have two apps, "base" and "users".

base app: contains all the common views, especially for anonymous users, like home, about, contact, etc...

users app: contains the auth functionality and views, like login, register, verification, logout, etc...

The authenticated users are separated into two roles, it's either "customer" or "administrator", and I have a model for each role, and groups for permissions as well.
Each role have different views, and there are only two or three common views, and they are not rendered the same either (few changes depends on the role, like in the views profile and settings).

Should I split the users app to three apps? users, customers, and administrators?

projectname/
├── projectname/
├── base/
├── users/
├── customers/
├── administrators/
├── manage.py

Or just to separate the views and the URLs to three different files?

projectname/
├── projectname/
├── base/
├── users/
├──── views/
├──────── usersviews.py
├──────── customersviews.py


/r/django
https://redd.it/18fc54y
sqlalchemy- processing the result set parallely- multiprocessing

Hey folks, what would be the best way to process a result set parallely? Lemme pain the picture of the current setup.

from settings import Session # this is basically the sessionmaker

def run_it():
// create session
session = Session()

// fetch first 100 rows which are basically the events stored
result_set = []

for event in result_set:
try:
// execute the event if its beyond expiry
finally:
session.commit()
session.close()

while True:


/r/Python
https://redd.it/18f8p9v