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
Flask-Tenants: Contributors and testers wanted

Hello all!

Flask-Tenants is a subdomain-based event-driven multitenancy module that allows for custom tenant-scoped models, automatic schema switching, and more. The project is mostly functional with some small bugs here and there that are in the process of being patched. There are probably features that would be nice that I haven't thought of either.

You can access the GitHub here: https://github.com/Flask-Tenants/flask-tenants

There is a demo application to help you get started here: https://github.com/Flask-Tenants/demo\_app

If you don't want to help with writing code, there are many other ways you can contribute as well: testing, ideas, and documentation all come to mind, but there is probably more.

All help is appreciated for what is sure to be a popular module in the near future :).

/r/flask
https://redd.it/1dupjwa
Current practices for static(ish) high-traffic parts of django projects?

Hi, it's been many years since I did a lot of django, so excuse the ignorance. I am launching a site soon though, with a backend on Django (using the Pegasus SaaS boilerplate to be specific), and it has a reasonable chance of getting mentioned on high traffic channels, which could lead to bursts of drive-by traffic. I anticipate a lot of folks checking out the landing pages, watching the first minute of videos (hosted on youtube) and moving on. Some tiny percentage will actually sign up and use the app, moving into normal dynamic app territory.

Sooo... I'm wondering what the smart thing is these days to make the largely static pages as light as possible on the server. I could load balance to a static server, but I'd really prefer not to have to figure out some static site builder system in addition to Django. Maybe caching is enough? Maybe there is a way to render django pages to static content so I can reuse my templates?

For what it is worth, the current deployment plan is that the site runs from docker images on a VPS.

Any pointers to resources much appreciated! thanks

/r/django
https://redd.it/1duqbo2
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

# Weekly Thread: Professional Use, Jobs, and Education 🏒

Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.

---

## How it Works:

1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.

---

## Guidelines:

- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.

---

## Example Topics:

1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?

---

Let's help each other grow in our careers and education. Happy discussing! 🌟

/r/Python
https://redd.it/1dut3lp
Need help with s3 and django-storages

Hello everyone, this is my first time working with any cloud storage. I am following this tutorial here from Michael Herman, and there were a few discrepancies right from the beginning.

First, when I tried running the collectstatic command, I got this error:

botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied

I looked up a bit, and apparently you have to set AWS_DEFAULT_ACL = None and doing that fixed it.

So now my static files were being uploaded to the s3 bucket when I ran collectstatic.

But when I visited the webpages, the static images and stylesheets were not getting fetched as expected.

I tried many different things at this point, but none of them worked. I typed the s3 object url in the browser and this was the error I was getting:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>419CX01JK1CAKYCS</RequestId>
<HostId>
rB7y8qLl5a5G0I1LVx2lexUbJpcvnrdKIMZ3AVq69C81B3j4BRWZwLq5THNLINwSv6q5HFSAednN1yq2tRCQ6THuxEn+S/Kj
</HostId>
</Error>

Now the next logical thing I did was to make all the bucket objects as public. The tutorial doesn't do this and I'm not sure if its a bad thing or not? Anyone

/r/djangolearning
https://redd.it/1dtndpn
Question on how to avoid heavy queries

I’m building a Django app which is database intensive, I’d like to have reports (data similar to a database view) to avoid database load. What are the best practices ? Use Postgres views ? Create the report as a Django model ?

Pls guide me

/r/django
https://redd.it/1duuibx
Django + react , not integrating

Hey folks , i am making a web app using django and react . I have very well knowledge of django but not much in react . So i need a help of someone who has skills and experience in full stack of django and react .
Pls dm i am unable to integrate django and react , and deadline of project os near

/r/django
https://redd.it/1dv0kvc
How to create thousands of records with factory boy?

# Issue

Let's say I'm running tests where I need to generate lots of data using factory\_boy and django orm like so:

class CompanyFactory(factory.Factory):
class Meta:
model = Company

name = factory.Faker('company')
email = factory.Faker('ascii_safe_email')
date_joined = factory.LazyFunction(datetime.datetime.now)

CompanyFacotry.create_batch(size=100_000)

**And this takes a lot of time to process.**

In the [factory\_boy docs](https://factoryboy.readthedocs.io/en/stable/reference.html#factory.CREATE_STRATEGY) it says, that \`create\_batch\` is using "create" strategy
I assume that it creates a bunch of save queries for each Company instance which impacts the performance.

# Solutions

* I found this factory\_boy [PR](https://github.com/FactoryBoy/factory_boy/pull/925) to implement a "true" bulk create. It has a lot of history and useful info on the subject but it seems to be stuck for now.
* There is [this article](https://www.rover.com/blog/engineering/post/speeding-django-test-runs-optimizing-factory-boy/) describing the solution which improves the performance but looks kinda hacky
* Also [this article](https://paul-grillenberger.de/2020/06/21/creating-test-data-with-faker-and-factory-boy/) besides describing basic faker/factory boy usage mentions this :

>The following method is appropriate for generating small- to medium-sized test

/r/django
https://redd.it/1dv0ubu
Built with Flask

Hello developers πŸ‘‹πŸ‘‹


I built scenestamps.com and readtxt.in with flask. You can check it out and share your feedback on it.

TechStack :

- for scenestamps.com : flask, sqlite, html,css, js, bootstrap, NGINX

- for readtxt.in : flask,html,css, bootstrap, NGINX

Both deployed on digital ocean droplet(OS : Ubuntu).

This pretty much became my go to stack for prototyping & deployment. Quite simple and efficient, nothing fancy.

Hope this serves as one among many real world apps built using Flask. Flask just works.

Have a nice day.

/r/flask
https://redd.it/1dv16gz
I am trying to create an email that when clicked on and the token is filled in the form turns `registration_confirmation_email` to True from the default to False. Also I noticed the token is always the same.

I am testing the code when I click the resent token button. The error is located below.

I am trying to create an email that when clicked on and the token is filled in the form turns `registration_confirmation_email` to `True` from the default to `False`. Also I noticed the token is always the same value
I am testing the code when I click the resent token button. The error is located below.

The error is https://pastebin.com/bG6SYJUp or put simply itsdangerous.exc.BadSignature: No b'.' found in value. How do I solve the same exact token in every email and the error?


Here is the code.


**registration_verification_code.html** (uses bootstrap)


`{% if user_db.emal_token == None %}`, should be `{% if user_db.emal_token != None %}`
https://pastebin.com/5QH3ab39



**_renderform.html** (uses bootstrap)**
https://pastebin.com/U4uruBAV



**models.py**
https://pastebin.com/2k0dsyjC




**routes.py**
https://pastebin.com/VLnAVP5B



I even created this images which run through some of what can go right and wrong when I click resend email button.
https://imgur.com/a/uuDXZ7b

Thank you to whoever helps in advance for the help.

/r/flask
https://redd.it/1duxze9
Which Python GUI Framework do you prefer?

I want to develop a desktop application. Since I want to use Python directly for many functions, I am looking for a good Python GUI framework. Please recommend the Python GUI framework you are using and why you recommend it.


* Tkinter

* PyQt/PySide

* Kivy

* wxPython

* Dear PyGui

* PyGTK

/r/Python
https://redd.it/1duzrky
how much python is too much python?

Context:
In my company I have a lot of freedom in how I use my time.
We're not a software company, but I care for all things IT among other things.
Whenver I have free time I get to automate other tasks I have, and I do this pretty much only with python, cause it's convenient and familiar. (I worked with RPA in the past, but that rquires a whole environment of course)

We have entire workflows syhcning databases from different systems that I put together with python, maybe something else would have been more efficient.

Yesterday I had to make some stupid graphs, and after fighting with excel for about 15 minutes I said "fuck it" and picked up matplotlib, which at face values sounds like shooting a fly with a cannon


don't really know where I'm going with this, but it did prompt the question:
how much python is too much python?

/r/Python
https://redd.it/1dv18ew
Exception handling approach

Which is better?

Approach 1:

def fun1():
if ...:
raise Exception()
return ...

def fun2():
fun1()

def main():
try:
fun2()
except Exception as error:
...

if __name__ == "__main__":
main()

Approach 2:

def fun1():
if ...:
raise Exception()
return ...

def fun2():
try:
fun1()
except Exception as error:
...

def main():
fun2()

if __name__ == "__main__":
main()

/r/Python
https://redd.it/1dv6p1c
Implementing MultiModal RAG Projects for PDFs with Critical Information in Tables

A common use-case of Python projects in production is for RAG applications. RAG deals with retrieval of relevant information from external data sources (often large in size) and combining them with user prompts to refine LLM responses.

Traditional RAG systems primarily use and parse text. But they often struggle with important details within tables. This hampers their utility in use-cases which demand reliability and accuracy such as RAG with Financial Documents. This is addressed with models like GPT-4o, Claude-3.5 Sonnet, LLaVA, which understand both text and images.

# Improving RAG accuracy for data in tables

Here we extract tables as images during the parsing process using GPT-4o, our choice of model for this blog with code. GPT-4o explains the content of the table in detail. Later it saves the table content with the document chunk into the index, making it easily searchable. The Pathway pipeline used here is scalable and great at incremental indexing – i.e. it becomes useful when there are any changes expected in the data stored within PDFs or tables.

# Architecture Used for Multimodal RAG for PDFs

This architecture must efficiently manage data ingestion, processing, and querying, while providing accurate and timely responses to user queries. Key components include

/r/Python
https://redd.it/1dv7quy
Module import error on PythonAnywhere

Server runs fine locally.

Uploaded app.py to /mysite

Created a virtual env and installed all dependencies using
pip install Flask geopy openai Pillow python-dotenv rembg requests

pip list suggests they installed just fine

updated /.virtualenvs/your-virtualenv-name under Web tab
running the file and getting ModuleNotFoundError: No module named 'dotenv'

when running the server from the bash console it runs fine

tried different combos of python versions but no luck

have been trying to work this out for hours and no luck


any ideas?

/r/flask
https://redd.it/1dvdwkb
flpc: Probably the fastest regex library for Python. Made with Rust πŸ¦€ and PyO3

With version 2 onwards, it introduces caching which boosted from 143x (no cache before v2) to \~5932.69x [max recorded performance on *my machine (not a NASA PC okay) a randomized string ASCII + number string\] (cached - lazystatic, sometimes \~1300x on first try) faster than the re-module on average. The time is calculated in milliseconds. If you find any ambiguity or bug in the code, Feel free to make a PR. I will review it. You will get max performance via installing via pip

There are some things to be considered:

1. The project is not written with a complete drop-in replacement for the re-module. However, it follows the same naming system or API similar to re.
2. The project may contain bugs especially the benchmark script which I haven't gone through properly.
3. If your project is limited to resources (maybe running on Vercel Serverless API), then it's not for you. The wheel file is around 700KB to 1.1 MB and the source distribution is 11.7KB

https://github.com/itsmeadarsh2008/flpc
*Python3

/r/Python
https://redd.it/1dv811q
Help with SQLAlchemy

Hi everyone,

I am new o flask and I would like some help to make this sql to work on Flask.

When I run this on mysql I got the results I want:

select t.date, t.name from capacitydata.allflash_dev t
inner join (
select name, max(date) as MaxDate
from capacitydata.allflash_dev group by name)
tm on t.name = tm.name and t.date = tm.MaxDate;




this is my code thats is working but showing all the lines.

# Creating Models
class Block(db.Model):
    tablename = "allflashdev"
 
    index = db.Column(db.Date, nullable=False, unique=True, primary
key=True)
    date = db.Column(db.Date, nullable=False)
    name = db.Column(db.String(45), nullable=False)
    raw = db.Column(db.String(45), nullable=False)
    free = db.Column(db.String(45), nullable=False)
    frep = db.Column(db.String(45), nullable=False)
    util = db.Column(db.String(45), nullable=False)
    utip = db.Column(db.String(45), nullable=False)

def

/r/flask
https://redd.it/1dvd2aj
D Gave ML Framework Codesignal Test and beyond devastated!

I just gave the CodeSignal ML framework test after a lot of preparation, and it felt like I was trying way too hard to write ML algorithm code that I'm well versed with. I know the concepts in detail for all the algorithms, but writing two algorithms from scratch in 70 minutes, including one more coding task plus 6 MCQ questions and one output, is tough.

I'm not sure if it's just me facing this challenge or if it's common. It was very hard to recall all the functions (the logic is easy) to write the code in that stressful, proctored environment. How can I get better at this? I know practice, practice, practice, but even that didn't seem to help here. And I didn't find any practice materials to stimulate the same environment. If you know something please share.

Isn't this too much of an expectation? I'm just getting done with my PhD and at times, I feel like looking for a job is more stressful than it ever was (I have 5 years of experience). The expectations are too high. How are you all coping with such a rat race?

/r/MachineLearning
https://redd.it/1dvhwk3
Need a buddy / mentor to work with and become good in django

Hello there. I'm a 3rd yr engineering student. I'm quite decent in python (i started off before my first year). later near the end of 1st year i picked up django, got grasp of the basics from YT.

At the start of 2nd year i picked up the book Django for Beginners By William vincent and got halfway through it but had to focus on academics to had to put it aside a bit. by the end of 2nd year i finished the book and got familiar with all the things like CRUD, Forms, User accounts, Password change/reset etc (although i'd need a quick recap cause its been a month or two since then). i did manually code side by side all the apps in the book and have it on my github so i have quite a good idea about how it works. but i think you cant really get the actual grasp of it unless you work on some real projects. Read that book like 2 times though

So i'm looking for someone who is good in django or is working on a project and is willing to mentor me while letting me help with the project too.

Hope you're

/r/django
https://redd.it/1dva7ng
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/1dvkvjp