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
Made a watcher so I don't have to run my script manually when coding

What my project does:

This is a watcher that reruns scripts, executes tests, and runs lint after you change a directory or a file.

Target Audience:

If you, like me, hate swapping between windows or panes to rerun a Python script you are working with, this will be perfect for you.

Comparison:

I just wanted something easy to run and lean with no bloated dependencies. At this point, it has a single dependency, and it allows you to rerun scripts after any file is modified. It also allows you to run pytest and pylint on your repo after every modification, which is quite nice if you like working based on tests.

https://github.com/NathanGavenski/python-watcher

/r/Python
https://redd.it/1hnus8y
Best practice to save images in a django project?

Hello! I am working in a project where I need to save images and add new images everyday. Should I save the files in static and do a cron job to collect the staticfiles every single day or should I save the images as a BLOB (or something similar) in the db? I've never worked with images in django before, so I have no clue what the best practice is. The docs say that they should be in static files, but I don't know if that is going to be a pain point in the long run in production and want to read from your experience!

/r/django
https://redd.it/1hnq4n9
Best practice to Storage boto3 with AWS with regular updates

Hi to everyone, I build a project that users adds new images and also updates new ones. Users can delete images and add new ones.

I made this using a class model called Guide with attributes that have a many to many field with a class model TechnicalFile.

In this TechnicalFile, it has a FileField attribute.

My implementation flaws at this:
1. User deletes an image
2. User adds a new image.
Frontend downloads from aws S3 bucket the existed images for that Guide object. And adds the new ones to the payload.

Backend just delete all images and put all the payload images to my bucket.

My question is how do I delete and add operations on images with best practice or how should be done more efficiently.
Hope some help, please. Let me know if you have any questions.


/r/django
https://redd.it/1hnucua
Textual CSS Neovim Plugin - Syntax Highlighting, Indentation, Folding, etc.

Hello!!

For those who are familiar with Textual, I noticed there wasn't an extension for syntax highlighting, indentation, etc. for NeoVim users so I decided to make one!

Here's the repo

This is my first plugin so if you see an issue, you are more than welcome to submit a pull request. I am open to all feedback, and criticism.

Thanks so much! I know it's a super niche issue but I hope it's helpful to someone out there.

/r/Python
https://redd.it/1hnrxs8
How to read the documentation

Hello everyone I'm starting an important project for my school and I needed to use Django in order to achieve more points in the "backend development" part and I wanted to ask something really important from you guys:
How should I read the documentation?
Let me elaborate, practically I started reading the Django documentation, to be more precise the "getting started" part that would've introduce to a little development of something with the framework. But since I started studying I just used the "django-admin project start" command (or something like that) and I still have the default files that comes with the command, and that is because the getting started part keeps throwing at you a lot of concepts that you can't actually practice out properly, one example is the Middleware that now I know how it works but I'm still too novice to even try to create my own. How I know the Middleware? That's because during the getting started guide a lot of concepts are highlighted and if you click on it a full page will give you a lot of theory behind it, and since I'm "just" reading this days that I'm studying Django I was guessing if I'm

/r/django
https://redd.it/1hnlz5c
local_bgrem: YOLOv8 Segmentation based Photo Background Remover | Fast and Offline

**What My Project Does**

It is an attempt to create a locally runnable and fast photo background remover. The ultimate aim is to create a 1 click background remover functionality in various free or open source software such as GIMP and Paint.net.

**Target Audience**

Anyone who wants to quickly remove background from photos without setting and downloading huge libraries and run inference.

**Comparison**

No comparison. Just a hobby project. I just came across a project (mentioned in acknowledgement) that uses Yolov8 for segmentation but in ReactJS, so I thought of extending that into removing background by keeping the masked objects and remove everything else from the image. The **very similar approach Microsoft Paint uses**, that's why it is quick and offline. So I will now work on smoothening the jagged edges and identifying principal objects to make it more accurate if possible.

The code is available here: [https://github.com/Suleman-Elahi/local\_bgrem](https://github.com/Suleman-Elahi/local_bgrem)

/r/Python
https://redd.it/1ho1ukg
Euchre Simulation and Winning Chances

I tried posting this to r/euchre but it got removed immediately.

I’ve been working on a project that calculates the odds of winning a round of Euchre based on the hand you’re dealt. For example, I used the program to calculate this scenario:

If you in the first seat to the left of the dealer, a hand with the right and left bower, along with the three non-trump 9s wins results in a win 61% of the time. (Based on 1000 simulations)

For the euchre players here:

Would knowing the winning chances for specific hands change how you approach the game?
Could this kind of information improve strategy, or would it take away from the fun of figuring it out on the fly?
What other scenarios or patterns would you find valuable to analyze?
I’m excited about the potential applications of this, but I’d love to hear from any Euchre players. Do you think this kind of data would add to the game, or do you prefer to rely purely on instinct and experience? Here is the github link:

https://github.com/jamesterrell/Euchre_Calculator

/r/Python
https://redd.it/1hnof8x
VSCode non-Pylance Configuration

TL; DR: Jedi (base Python extension) + Pylint ("pylint.args:" "--disable=C,R", if you don't want Pylint to give convention and refactor related messages) gives a smooth experience using only open source extensions. Don't bother Flake8 cause Pyflakes (Flake8's error checking component) doesn't dig deeper into libraries to verify classes/functions in imports, and only checks overall syntax tree of a file individually. This is unlike how Pylance and Pylint works. Use MyPy for optional Type Checking to have full feature parity with Pylance.

Am currently switching from PyCharm to have more transparency in my IDE and found that Microsoft provides 4 Python "language server" components:-

1. Pylance: provides language server features as well as linting (including type checking). Only con is that it is closed source.
2. Pylint: general purpose linting including multi-file support, which means Pylint digs deep into your libraries to check if the imported libraries actually have the proper classes/functions
3. Flake8: only single file linting support, which means it does not check other files to verify classes/functions and stuff
4. MyPy: Mostly type checking
5. Jedi: fallback language server in absence of Pylance. However it provides zero to no error finding features.

So the main two choices for general purpose linting are Pylance and Pylint.

/r/Python
https://redd.it/1hnil16
How do i set up a SSL certificate on flask app with mod_wsgi inside a docker containter

I signed up on cloudflare and got a free SSL certificate and i have a .pem file and a .key file and here is the dockerfile i used for my image

# Start with a base Python image
FROM python:3.11

# Install necessary system packages
RUN apt-get update && \
    apt-get install -y \
    apache2 \
    apache2-dev \
    libapache2-mod-wsgi-py3 \
    locales \
    && rm -rf /var/lib/apt/lists/*

# Generate locale and set locale environment variables
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
    locale-gen && \
    update-locale LANG=en_US.UTF-8

# Create a non-root user and group
RUN groupadd -r mostafa && useradd -r -g mostafa mostafa

# Create a directory for your application
RUN mkdir /application

/r/flask
https://redd.it/1hnrmwm
first contribution

Hey all, I'm a data engineer with 4 years of experience who has done side projects with django for last 2 years.

To be honest even though I like my job, I'm in love with django. And for the first time I was able to contribute to one of the most known packages of it, django-allauth.

The contribution was the simplest possible, just a config change. But I feel just too happy.

I hope in the future I'll use the project more extensively and do more significant contributions.


I just wanted to share my thrill, love you guys.

/r/django
https://redd.it/1ho51of
Is SQLite enough for this"small" app and what kind of security measures must I consider?

I'm developing an application for a hospital I work for, a website for medical residents to register so that the teaching department has better control and access to their data. It's fairly simple, very lean, and the population of residents is about 1000 with around 85 speciality courses.

Users will be able to register and set their data and there's 4 roles, student, profesor, division chief and teaching staff, with increased permissions.

I expect users creating accounts only on the first month of their program, all of which start at the same time of the year.

Data edits would be rare I think.

And the app won't store images or any other kind of file from users.

The questions are:
1) is SQLite with WAL enabled going to be enough to handle the app? I'm not an experienced dev (in web, I actually work on research), and I don't want to have to set up and maintain a server DBMS like MySQL.
2) What kind of security details must I work on beyond what Django does out of the box? I'm using the default auth system. I'm even using the default user and expanding it with a 1to1 rel model.


/r/django
https://redd.it/1ho7uy6
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/1hoizxc
How to learn more django?

I just started by backend learning journey with django. I did a project which is basically a basic blog application. But I am not able to learn any further. I don't know how to continue learning and building more projects using django.

I check for project tutorials on YouTube but many from the discord community recommend me not to learn from them as they may contain bad practices.

I don't know how to proceed. Please guide me

/r/djangolearning
https://redd.it/1ho6gsl
Following along with a docker django deployment tutorial; however I am getting connection to db refused

I built a quick dummy (main project, 1 app named "home" with a HttpResponse). I created a .env with database creds; added them to settings.py but when I deploy to docker on my machine the log returns

2024-12-27 10:11:53 django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5435 failed: Connection refused
2024-12-27 10:11:53 Is the server running on that host and accepting TCP/IP connections?
2024-12-27 10:11:53 connection to server at "localhost" (127.0.0.1), port 5435 failed: Connection refused
2024-12-27 10:11:53 Is the server running on that host and accepting TCP/IP connections?

I have postgres running in docker on port 5435. I can connect to the DB in DBeaver and PGAdmin


I have tried using the docker postgres ip, the name

❯ docker network inspect local-dev-servicesdefault
[
{
"Name": "local-dev-services
default",
"Id": "7c41ef03af3ccf15edecd8XXXXXXXXXX648a571f23",
"Created": "2024-07-27T15:51:09.914911667Z",


/r/djangolearning
https://redd.it/1hnjxxu
I Made a Drop-In Wrapper For `argparse` That Automatically Creates a GUI Interface

## What My Project Does

Since I end up using Python 3's built-in `argparse` a lot in my projects and have received many requests from downstream users for GUI interfaces, I created a package that wraps an existing `Parser` and generates a terminal-based GUI for it.
If you include the `--gui` flag (by default), it opens an interface using [Textual](https://github.com/Textualize/textual) which includes mouse support (in all the terminals I've tested).
The best part is that you can still use the regular command line interface as usual if you'd prefer.

Using the large demo parser I typically use for testing, it looks like this:

https://github.com/Sorcerio/Argparse-Interface/blob/master/assets/ArgUIDemo_small.gif?raw=true

Currently, ArgUI supports:
- Text input (`str`, `int`, `float`).
- `nargs` arguments with styled list inputs.
- Booleans (with switches).
- Groups (exclusive and named).
- Subparsers.

Which, as far as I can tell, encompases the full suite of base-level `argparse` inputs.

## Target Audience

This project is designed for anyone who uses Python's `argparse` in their command-line applications and would like a more user-friendly terminal interface with mouse support.
It is good for developers who want to add a GUI to their existing CLI tools without losing the flexibility and power of the command line.

Right now, I would suggest using it for non-enterprise development until I can test the code

/r/Python
https://redd.it/1hojk2a
Created an open-source business management software using Django and HTMX

Hi everyone,

Over the past 2.5 years I've been learning Django (and Python). One of the main projects I started working on (quite naively I must say in hindsight) was creating business management software for a company I was interning at. Some two years and a lot of itterations later, I decided to open-source the project under the name **Bloomerp**.

The vision behind the project is to allow developers to build scalable business management software for companies **by just defining the Django models**, whilst maintaining the ability to add custom functionality that fits integrates within the project's UI.

Some out-of-the-box features that Bloomerp provides:

* Intuitive CRUD views with built-in access control
* Advanced list views offering powerful filtering
* A PDF generation system for documents based on objects (like contracts, using Employee objects)
* Customizable dashboards using SQL-based widgets
* An SQL query editor for advanced data analysis
* Automatic REST API generation for all models
* Bookmarking system
* Integration with an LLMs
* ...

It would be amazing to receive some well-needed feedback on the project, or even to get some contributors on board. You can check out the repo on Github at [DavidBloomer11/Bloomerp](https://github.com/DavidBloomer11/Bloomerp) or you can check out a live demo on [bloomerp.io](https://bloomerp.io/)

Feel free to ask me any questions!

Thanks

/r/django
https://redd.it/1hoh2hb
What Do Recruiters and Employers Look for in Junior Web Developers?

Hi everyone,

I’m a junior web developer, and I’ve been actively applying for jobs lately. I’m curious—what do recruiters and employers typically look for when hiring junior web devs? Are there specific skills, experiences, or qualities that stand out?

I’ve primarily been applying for remote positions outside my current country of residence, the Philippines. Could this impact the hiring process? I assume it varies by country, as hiring a foreign employee often involves additional scrutiny.

Here are the links to my resume and portfolio as reference:

[Resume link](https://docs.google.com/document/d/1PCKXsHPvmur7mJHSiufv_Gid5Axo4LAi/edit?usp=sharing&ouid=112487098966462460918&rtpof=true&sd=true)
Portfolio link

If you’re a recruiter, employer, or someone who’s landed a junior dev position, I’d love to hear your insights and advice.

Thanks in advance!

/r/django
https://redd.it/1hoq5fa
Not able to login in a user to my VueJS frontend which communicates with my Django backend

This is for those that are also familiar with VueJS and DRF. But I am trying to login as a user, with an email/password I just created on the Login Page. But when I click the 'Login' button nothing happens, it should log me in and redirect me to the 'Homeowner Dashboard' page. To clarify I got DRF set with up Django, that is I created the API calls that connect to my Django API views.


So I'm not exactly sure why this is happening, I don't know if this is strictly a VueJS, Django or DRF issue or all of them. Also when I inspect the page in the console, it just says 'API call successful:'. I have axios implemented in my VueJS project.


I'd share my code here, however I wouldn't even know where to begin. I'm simply testing my project from the frontend to the backend. I'm not sure if creating a user in Django Admin would help or not. Pretty sure this is easy fix somewhere. Please help me with this, my project repos are set to private but I can make them both public for you guys to see if that would

/r/django
https://redd.it/1hopbtj
ERROR ImproperlyConfigured: Error loading psycopg2 or psycopg module

I'm currently trying to update a Django rest api on AWS Lambda using the following command.

zappa update dev

However it gives me the following error

Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.

When I run the following

zappa tail

I see the error

ImproperlyConfigured: Error loading psycopg2 or psycopg module

Does anyone know how to fix this error? I check requirements.txt file and it has the latest version of both psycopg2 and psycopg2-binary (2.9.10). I don't know why I'm getting the error.

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