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
Extract text color from ocr

Im currently working on a project, requiring to perform ocr on images , extract texts and do some processing, and sticht it back again

Using keras ocr / easy ocr ive successfully did that now challenge is to make look & feel in original state ,

Im redrawing text using pillow , where u can supply font and color

Ive tried , doin cv2. Kmeans to get dominant color from roi of text im replacing , but due to less dpi and pixelated quality , dominant color is not actual font color

Is there a way to get text color from ocr ??

/r/Python
https://redd.it/1cv8ueo
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/1cvay3b
Picodi - Simplifying Dependency Injection in Python

# What My Project Does

[Picodi](https://github.com/yakimka/picodi) is a lightweight and easy-to-use Dependency Injection ([DI](https://en.wikipedia.org/wiki/Dependency_injection)) library for Python. Picodi supports both synchronous and asynchronous contexts and offers features like resource lifecycle management. Think about Picodi as a decorator that helps you manage your dependencies without the need for a full-blown DI container.

# Key Features

* 🌟 Simple and lightweight
* 📦 Zero dependencies
* ⏱️ Supports both sync and async contexts
* 🔄 Resource lifecycle management
* 🔍 Type hints support
* 🐍 Python & PyPy 3.10+ support

# Quick Start

Here’s a quick example of how Picodi works:

import asyncio
from collections.abc import Callable
from datetime import date
from typing import Any
import httpx
from picodi import Provide, init_resources, inject, resource, shutdown_resources
from picodi.helpers import get_value


def get_settings() -> dict:
return {
"nasa_api": {
"api_key": "DEMO_KEY",


/r/Python
https://redd.it/1cuz4kw
FastAPI Backend Template for SaaS products

Hello there, I just created a template for creating a backend for your SaaS products.

What my project does: It is a FastAPI project/template for creating SaaS backends and admin dashboards.

Comparison: 
Out of the box, it supports
1) Licence key generation and validation.
2) OAuth 2 authentication with scopes.
3) Endpoints with pagination and filters to easily integrate with an admin dashboard.
4) Passwords are securely stored using hashing.
5) used PostgreSQL for database

Target Audience: Production

Check it here!

/r/Python
https://redd.it/1cuxatg
Would this work?

I’ve never developed or even tried proton native, but could you use proton native as a front end and then Django as a backend?

I’m curious because I would prefer this to PyQT or Tkinter.

/r/Python
https://redd.it/1cvgnut
How to display some extra information while using the CheckboxSelectMultiple widget?

I have a User model that has a ManyToManyField to an EmailCategory model -

class User(models.Model):
email_categories = models.ManyToManyField(EmailCategory)

class EmailCategory(models.Model):
name = models.CharField(max_length=20)
description = models.CharField(max_length=500)
def __str__(self):
return self.name


I am using the `CheckboxSelectMultiple` widget to render the user's `email_categories` field. It works correctly, but it only shows the name of the email category. I also want to show the user the description of the email category. How can I achieve that?

This is the form I am using -

class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
fields = ['email_categories']
widgets = {


/r/django
https://redd.it/1cvfs3v
Flask for SaaS product and microservice arhitecture


I am currently given task to work on system design for MVP application for SaaS solution selling microproducts.

Users will pay for lets say notifications, specific data, and different type of things in application.

My idea is: Next.js for frontend, Auth0, API gateway and flask microservices.

From your expirience, what is the benefit of flask compared to Django or FastAPI for this kind of project that will potentially have thousands of active users?

Should API gateway be responsible for authorization based on what microservices user bought or better to keep it in code/microservices?


Any insight/doucmentation and experience is greatley appreciated :)


/r/django
https://redd.it/1cvcvvp
Unable to insert data

https://preview.redd.it/9bucc97m9c1d1.png?width=1484&format=png&auto=webp&s=573ce66c416157d8124d60ce0cb1fc55c102d97b

I have deployed my django project in vecel but I'm getting
`django.db.utils.OperationalError: attempt to write a readonly database`
while trying to add data to db. any idea to fix it?

/r/django
https://redd.it/1cvj4o3
Can you use Django-ninja and Django-Admin UI in parallel

I’m interested in using Ninja for API backend but would also like to use the Django-Admin as an interface for Human CRUD operations. Is there any gotchas that I need to be aware of?

/r/django
https://redd.it/1cvjtsm
Easiest and good-looking frontend framework

Hi everyone!
I am a Data Scientist exploring the world of software engineering, particularly working with Django.

I have very little experience with frontend development (only with HTML, CSS, some frameworks like Bootstrap and Tailwind, and a bit of JS), and I don't know more powerful "tools" like React or others.

What is the best approach for a complete beginner who wants to create a professional looking app in a not too complex way?

I have also experimented with using templates and REST APIs: personally, I believe that APIs give you more flexibility, but on the other hand, I find them very complex to implement (it's probably just my fault): what do you suggest?

Thanks in advance!


EDIT: What if I want to create a fully functional web app' with payments, and a free (trial) mode? So, Is it possible to create a SaaS?

Apologies for the dumb questions

/r/django
https://redd.it/1cvnciq
You should only use licensed version of python

I’m an intern in a company and I automated some processes using python. My company’s IT wing said that as long as it is a licensed software you can use it in our company.

In my mind I was like where the f I’m going to get a license for an open source software.

Note : They mention that another team has been using licensed python. I thought either IT is so stupid or that team is so smart that they brought license for pycharm or anaconda (claim that it is a Python license) and fooled IT.

If I am wrong then tell me where I can get that license.

And I am also looking for job in data analyst.

/r/Python
https://redd.it/1cvhi1m
Setting image back to default image

I have a quick question pertaining to setting image back to default image. I have a user profile model:

from django.contrib.auth import get_user_model
User = get_user_model()

class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="user_images/default.png",
upload_to="user_images", null=True, blank=True)
email = models.EmailField(null=True, blank=True)
following = models.ManyToManyField(User, blank=True, related_name='children')

My question is why doesn't the default image get applied to the image field when an user updates the profile after deleting his or her profile image? I fixed the issue by overriding the save() method, but I would like to understand why. Can someone explain it? Thank you very much.

def save(self, *args, **kwargs):
if not self.image:
self.image = 'user_images/default.png'
super(Profile, self).save(*args, **kwargs)

/r/djangolearning
https://redd.it/1cvs2li
Flask for SaaS product and microservice arhitecture

I am currently given task to work on system design for MVP application for SaaS solution selling microproducts.

Users will pay for lets say notifications, specific data, and different type of things in application.

My idea is: Next.js for frontend, Auth0, API gateway and flask microservices.

From your expirience, what is the benefit of flask compared to Django or FastAPI for this kind of project that will potentially have thousands of active users?

Should API gateway be responsible for authorization based on what microservices user bought or better to keep it in code/microservices?


Any insight/doucmentation and experience is greatley appreciated :)


/r/flask
https://redd.it/1cvcupl
Django prerequisite other than python

I know understanding basic python code is enough to start, but what do I need to know to actually know how django works ? I have only built basic php/html web before.

/r/django
https://redd.it/1cvvrvb
Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

/r/Python
https://redd.it/1cw25ip
Best way to store Discount Code used in a purchase when codes are allow to change over time

Let's say you have the following models:

class Product(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=6, decimal_places=2)

class Purchase(models.Model):
customer = models.ForeignKey(User, on_delete=models.CASCADE)
total = models.DecimalField(max_digits=8, decimal_places=2)

class PurchaseItem(models.Model):
purchase = models.ForeignKey(Purchase, related_name='items', on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.IntegerField(default=1)
price = models.DecimalField(max_digits=6, decimal_places=2)

class Discount(models.Model):
vendor = models.ForeignKey(Vendor, on_delete=models.CASCADE)
code = models.CharField(max_length=50, unique=True)
discount_percent = models.IntegerField()



If I want to store which discount code was used for a purchase I can do something like this:

class PurchaseItem(models.Model):


/r/django
https://redd.it/1cw9iw7
ML Flask app deployed to AWS

So, for the past weekend I’ve been attempting to launch a small one endpoint Flask App that has a couple libraries like open cv, pandas, scikit and a specific library called Qreader that are all a little bit heavy, which made me move away from using something like AWS Chalice that was a quick deploy to lambdas.

I am fairly new to all cloud technologies, I’ve deployed some stuff here or there on AWS and azure but nothing has given me the trouble this has lol.

Any tutorial or advice? Mostly where I fall apart comes when I have gunicorn up but then when I try to setup logs or have it run in the background something like that it all blows up and can’t get it back up running. How do you even automate this to a pipeline CI/CD setup if it takes so many commands and setup to just get it up the first time. Again, I’m newish to this so if I’m saying something dumb call me out on it I’m trying to learn! Not sure if that makes a lot of sense? Any help is appreciated.

/r/flask
https://redd.it/1cw7l19
Looking for suggestions on a good tutorial or material to understand django dataset queries

Hello,


I've been working on a project that has an 'estimate' template, view, model, form, and I would like the dropdown menu on the left side which has clients from a model called ClientRecords as well as the the dropdown menu on the right which has employees from a model called EmployeeRecords. I would like to be able to select a person from either menu and have the data like names and phone numbers populate. It would be really cool if it could do that with just the selection of the dropdown.


I'm looking for some guidance because I don't really know what the word is for what I am looking for. Maybe from the description and the picture someone can point me in the right direction.


Thank you!

current template look




/r/djangolearning
https://redd.it/1cw6dio
Allauth + DRF

Hello guys 👋

As we know allauth dropped headless support and wanna use that with drf + vue.js and I kinda stuck here during auth and secure api endpoints, so do you guys have any public project available with these technologies so that I can have a look at the code? Something like a boilerplate.

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