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
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/189wh8y
Use cases of Django

Hello guys. I have a little IT business, we create different web applications. I'm also a CTO in this firm, so I understand something in programming. We write frontend on Vue, backend on Asp.net/spring/fastapi. Also we use some clean architecture patterns. We use c#/java for big, complex applications and fastapi for e-commerce.
I discovered Django, and it's possibilities look interesting for short time to market, compared to other frameworks. What best use cases can Django offer in context of my organization? Share your experience please

/r/django
https://redd.it/18b6n21
DataStack: The Fastest way to build apps in python



Hey Python devs,

Excited to share my latest creation – **DataStack**! 🎉 It's a new open-source, event-driven Python web app framework that's here to streamline your development process.

**Key Differentiator:** Unlike Streamlit, DataStack doesn't run your entire Python script on every change. It's designed to be lightning-fast and efficient, responding only to the events that matter. Say goodbye to unnecessary processing!

**Why DataStack?**

* 🌐 **Event-Driven:** Enjoy a responsive and dynamic web app experience.
* 🚀 **Lightning-Fast Updates:** Only processes what's needed, making it super quick.
* 💻 **Minimal Syntax:** Simple, intuitive code for maximum impact.
* 🎨 **Customization:** Tailor your apps exactly the way you want.
* 🔓 **Open Source:** Contribute, customize, and use it freely in your projects.

Github : [https://github.com/data-stack-hub/DataStack](https://github.com/data-stack-hub/DataStack)

Pypi: [https://pypi.org/project/pydatastack/](https://pypi.org/project/pydatastack/)

Share your view on DataStack

/r/Python
https://redd.it/18b5qle
How will you use the new Django 5.0 GeneratedField?

I'm pretty exciting by this new feature and I was wondering how I could benefit from it.

My first question: are properties still relevant?

For example, something like:

@property
def full_name(self) -> str:
return f"{self.first_name} {self.last_name}"


could be easily replaced by a generated field. However, as it's not a CPU intensive task, I'm not sure I'd benefit from it.

Then I was thinking of annotations. In some cases, they can be a little painful to write, and I always have to remember if my queryset is contains the annotation or not. However, what if I replace annotation by a generated field, will it create an overhead, in a sense that it will compute stuff when I may not require it. Maybe the persist_db is the answer to this question?

I'd be glad to know how are you going to use this welcome feature.

/r/django
https://redd.it/18b8pk6
Flask for Video Site

I have this collection of short mp4 video clips (ranging from 30s-2min) coupled with images of explanations of the videos.

The files all organised pretty well, using a letter for categories and an integer for the video number (A1-A52, B1-B40 etc) then the corresponding images use the same format with .png instead of mp4.

Obviously S3 is the place for these.

I've been working on a flask app that runs locally it consists of a index home page with menus/submenus to select the video category which takes you to a new page and displays the videos in a menu which you can hover to display a gif of the video and click to expand the video and play it.

I'm wondering what the best way to implement this using Flask:

* On the front-end side too, is there any tools that make developing this type of site easier? I'm bashing away at CSS and JS to glue the video player and display a button to show the explanation of the clip.

Is **Flask** the best tool to use for this HTML/CSS/JS site or should I be using something else?

I would also like to implement a 'test' scenario that would run through 20 clips and have you

/r/flask
https://redd.it/18bao77
Passing Python Array to Javascript

I have been struggling trying to pass a python array to javascript. Does anyone know how to do this?

/r/flask
https://redd.it/18b7br0
Looking for some freelance hours

Hello everyone,

Currently looking to do some freelance hours.

Experience with:

Django
MySQL/PostgreSQL
Celery
Docker
Kubernetes
Cloud Deployment (GCP, AWS)

Also, experience with FastAPI, Javascript, PHP.

With Django, I've built multiple systems mainly serving as APIs to Web Apps (React, etc) or Mobile Apps.

I'm working as a CTO full time but looking to fill some free hours. PM me if you want more details.

Thank you

/r/django
https://redd.it/18b9wo4
Help regarding hosting a Flask API

So I made a flask API for a grocery store and using a SQLITE3 database at the moment, this application also has scheduled task with celery and caching both using redis as a cache manager base.
Now I want to host this API for learning purpose as being a student ( There also exists a VUE3 JS frontend application communicating with this API )
So can anyone tell me any good free or cheap hostings servers and also things which I should do to make the hosting hassle-free for me.

/r/flask
https://redd.it/183c4vt
It's Christmas day. You wake up, run to the tree, tear open the largest package with your name on it... FastAPI has added _____?

Long time FastAPI user, I have a lot of free time this Christmas and January and would love to make some contributions to it.


What are some things that the community / project would really benefit from. I would really like to give back to a project that has given me so much.

​

/r/Python
https://redd.it/18bkywh
D Needle in a haystack experiment: Assistants API RAG beats GPT 4-Turbo & Llama Index at 4% of the cost

Ran an experiment comparing information retrieval performance between Open AI's Assistants API's RAG, GPT-4 Turbo (with context window stuffing) and Llama Index with GPT4.

I recently added a new document-oriented react hook to CopilotKit, made specifically to accommodate (potentially long-form) documents and wanted to get the best performance.

Got pretty striking results: The assistant's API beats Llama index in a big way in performance and is 25x cheaper than context window stuffing with GPT-4 Turbo.

​

accuracy performance

​

costs

Big takeaway when it comes to building with AI. Almost no one should be using context-window stuffing and Llama Index has a lot of catching up to do when it comes to RAG performance. Whatever OpenAI is using under the hood for RAG, has great performance.

The full article:

https://ai88.substack.com/p/rag-vs-context-window-in-gpt4-accuracy-cost

/r/MachineLearning
https://redd.it/18bivxa
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

/r/Python
https://redd.it/18bqi1q
How would you handle this model? Room with multiple beds but limit how many people can be assigned to room based to total beds.

I am creating an application to manage a barracks room. However, some rooms have 2 - 3 beds inside the 1 room. If I want to assign an occupant to each room, would it be best to create more than 1 room with the same room number? Currently I have it set so one room shows Bed Count, in hopes I could limit how many people can be assigned to a room. Now I am thinking of creating more than 1 room to total the number of beds.

​

Currently,

Room 123A has 3 beds.
In the DB I have 1 123A with a bed count of 3.

Thinking:

Room 123A has 3 beds
In the DB create 123A x 3.

​

/r/djangolearning
https://redd.it/18blnk9
I was curious how django keeps track of all my model classes...

Ever wondered what happens under the hood when you run python manage.py makemigrations in Django? I recently asked this to myself and went through the rabbit hole of reading the Django code base.

I wrote a short blog post with a short deep dive into the model detection mechanism. No magic wands, just a bit of metaclasses, the new method, and a dash of django.setup().

If you're curious but not looking for an epic saga, check out the post https://svemaraju.github.io/django-model-detection.html

/r/django
https://redd.it/18bmnzw
sqlglot - Amazing SQL parsing library

Wanted to give sqlglot a shoutout as it saved me a ton of time.

I had a task that involved building a dependency graph by statically analyzing the relationship of MySQL views. Initially, I was using sqlparse to extract the dependencies from the SQL statements, but it required me to create an increasingly hacky recursive function. I kept encountering examples in our codebase that required more test cases and further updating.

Then I stumbled upon sqlglot, and the code reduced to just a few lines, working immediately. It was barely more complex than this:

from sqlglot import parseone, exp

for table in parse
one(sqlstatement).findall(exp.Table):
print(table.name)

I'm surprised I hadn't heard of it before.

/r/Python
https://redd.it/18bprha
Pytest over Unittest

Hi all ,

I'd like to hear your opinions over when you have decided to use Pytest over Unittest as your testing framework for your projects and why.

I've personally never used Pytest but recently found it on a project I started to work on and I've been finding it interesting.

/r/Python
https://redd.it/18bjv0y
Introducing Great Tables

Great Tables is a *great* new Python package that simplifies the process of making tabular data presentable for any sort of publication task. With Great Tables, you can easily use data from a Pandas or Polars DataFrame and turn it into a beautiful table that can be included in a notebook, a Quarto document, or exported as HTML.


We've been working hard on making this package as useful as possible, and we're excited to share it with you. The package (v0.1.0) is available on PyPI and can be installed with:


pip install great_tables


The documentation site at https://posit-dev.github.io/great-tables/articles/intro.html has a *Get Started* tutorial that will walk you through the basics of using the package. The API documentation is also available on the site and it is chock full of examples that'll show you how to use the various features of the package.


We want Great Tables to be really useful for your work and so we really value any and all feedback. Send us a note in https://github.com/posit-dev/great-tables/issues or https://github.com/posit-dev/great-tables/discussions anytime you like!

​

https://preview.redd.it/vwuu06h5ui4c1.png?width=988&format=png&auto=webp&s=50e381e692bc16775eb1f6a4f6de309d75048139

\-------

This was originally posted by Rich Iannone over at LinkedIn. He asked me to post this here.

/r/Python
https://redd.it/18biyrh
Can python/ipython be used to replace Bash?

I am a heavy Bash user, and curiosity has me trying to see if it's feasible to move completely to Python.

chsh -s $(which ipython3)
exec ipython3

I'm just taking my first baby steps, but how much can I expect it to act like a normal shell like in /etc/shells?

(I did manually add ipython3 there, but unsure if that did anything.)

Since .bashrc is no longer being read, I probably need a .ipythonrc or something, to setup my environment, but I don't know how to make sure it's read when a new terminal opens. Is there a Python equivalent to /etc/profile, /etc/rc.local etc... ?

If I try to put !ipython3 --profile=pagefault into ~/.ipython/profile_default/startup/startup_default.py I get:

TerminalIPythonApp WARNING | Unknown error in handling startup files:
File ~/.ipython/profiledefault/startup/startuppagefault.py:6
!ipython3 --profile pagefault
^
SyntaxError: invalid syntax

What is the proper way to ensure my custom profile gets loaded by default?

Finally, I'm having a lot of trouble with my custom layout. Would some of you mind helping me cheat my way through by sharing your custom ipython_config.py scripts?

/r/IPython
https://redd.it/18bniyw