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
Looking for a ‘flask’ consultant

Hi all,

I have a flask app deployed on my current server (business hosting shared) and it works great when only one user is using it but it seems like when multiple people are using the app it surpasses my servers resources.

It does not seem like scaling the server is feasible and i want to scale the app.

The context of the app is simple, it’s taking data from my data base and rendering images. The app then takes the rendered images and spits out pixel data in json format.

I don’t have a ton of experience in this realm of things - hoping to meet someone who does and pay you for your time.

please Dm me or post here!

/r/flask
https://redd.it/1c4sdvs
Announcing pixi-kernel - Jupyter kernels using Pixi for reproducible notebooks

Hello everyone,

I'm proud to announce a brand-new Python library named pixi-kernel. Feedback and suggestions are welcome.

https://github.com/renan-r-santos/pixi-kernel

Also, if you haven't heard of the Pixi package manager, check it out at https://pixi.sh/latest/.

It supports conda and PyPI (through uv) packages, pyproject.toml config, git, path and editable installs and it is really fast.

/r/IPython
https://redd.it/1c4l2k2
Some days I really love python...

I have a problem that I was terrible at listening to new music, everything I listen to is from around 2000 - 2010.

There is a radio station here in the UK called BBC 6 music that has a decent playlist but since I only really listen in the car its not always appropriate to note the track names down - and my memory is terrible so I always forget by the time I get home.

Luckily they put the playlist online but it's just text links so I can't add it to my music service of choice - YouTube Music.

Thankfully the page is pretty simple so I wrote a basic ass scraper that will grab the HTML, parse through the tracks with beautful soup, then use the ytmusicapi package to remove the old tracks from my playlist and recreate it with the freshly scraped data, railway then makes it dead easy to deploy and schedule it to run once a day.

This thing took me probably less than an hour and a half to create and will hopefully open me up to some quality new tunes!

/r/Python
https://redd.it/1c4wsmn
Diffusion versus Auto-regressive models for image generation. Which is better? D R

Hello all,

I am new to this field of image generation using transformer models. I am curious about the above two mentioned approaches. Particularly in light of this paper "Visual Autoregressive Modeling: Scalable Image Generation via Next-Scale Prediction" (results). It looks like these AR (auto-regressive) models seem to be better especially when scaled up compared to DiTs (Diffusion Transformers). Their main inference benefits seem to come from the low sampling efficiency of DiT.

However, I have my doubts regarding this. Apart from the fact that major AI powerhouses have adopted diffusion models, there is a solid theory backing diffusion models being capable of generating any image distribution. Apart from that, there are no results of the above VAR paper for small models (something I am also interested in).

So here are my questions:

1. Are there any DiT distillation papers which improve the sampling efficiency? I could not find any transformer ones, all were U-Net based.
2. Is there any theory backing AR transformer models for image generation (or for any generative task for that matter)?
3. Is this VAR paper better purely because people haven't yet explored DiT well enough? Or AR model supremacy is what is expected?
4. If you were to pick between the

/r/MachineLearning
https://redd.it/1c53pc5
django-ninja vs ninja extra

As the title says I need quick inputs with Django Ninja Extra or other options out of Ninja inspired.
Since we switch between FASTAPI and Django, moving to Ninja over DRF for new projects seemed to be a good move, and so far enjoying it. Discovered Ninja extra, and seems to be cool with Class Views. But is it stable? Need to take a quick call for a project starting in 2-3 days whether we should consider it over Ninja.


Many views hit Redis instead of traditional Django ORM in our applications, for speed and simplicity. Otherwise these are regular CRUD applications. Do advise. Thanks


/r/django
https://redd.it/1c4s832
Deploying a Flask Web App on Second-Level Domain

Hello everyone,
This topic might be discussed, but I haven't found anything specific about it.I recently started programming in Python as a hobby and developed my first web app using Flask.

I want it to be accessible via a second-level domain, and this is where the complications start. During the COVID pandemic, I created a landing page with a portfolio and CV. I used a template, customized it a bit, and uploaded it to WordPress.I bought a domain and hosting on ovhcloud.

Does anyone have experience with this hosting service?
I contacted support and they told me Python is supported, but I can't figure out how to access the server and install the libraries.
The documentation says to access via SSH, but I only have the FTP and SFTP addresses.I'm not sure if this is feasible. Forgive me if I've written nonsense.

TL;DR would like to upload a Flask web app to a second-level domain on ovhcloud hosting. First-level domain with WordPress.

/r/flask
https://redd.it/1c4ui6o
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions 🐍

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/1c51rs9
Serve static NextJS files with Flask?

I have been able to do this with a React frontend, but haven't figured it out for NextJS frontend yet and another developer is blocking my testing of this at the moment so forgive me for asking a more "will this likely work" question rather than "here's the error I'm having, how do I fix it" question.

My `next.config.mjs` (the `distDir` property renames the normal `/out` export directory to `/build`):

/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
distDir: 'build'
};

export default nextConfig;

I then move the `build` folder that gets created to the root of the application so the folder structure looks something like this:

MyApplication/
├── backend (flask)
└── build (static html/js/css)

In `backend/__init__.py` I have this setup, which is what I have used to deploy ReactJS static files before:

def create_app():
app = Flask(__name__, static_folder="../build", static_url_path="/")

@app.route("/")


/r/flask
https://redd.it/1c4u4om
float('inf') is bad practice

I don't know why float('inf') was chosen as the way the language accesses infinity since this is using a magic string. Why couldn't it just be float.inf? That way magic string is avoided. Feels too basic of a best practice to be simply passed up. Anyone know the reason behind this?

/r/Python
https://redd.it/1c4x7b7
Should I make a React/Django boilerplate?

I’m thinking of making the code I use to get SaaS projects up and running available as a paid boilerplate. This is the stack I use:

- Frontend: React, Tailwind CSS, Netlify
- Backend: Django, Postgres (RDS), Stripe
- DevOps: CircleCI, EC2
- Storage/Caching: S3, CloudFront

The frontend and backend will be on separate subdomains i.e., api.yourdomain.com and app.yourdomain.com and also be in separate repos.

The boilerplate will come with all basic SaaS functionality i.e., user accounts, teams, subscriptions etc. so you’ll only have to code the business logic specific to your app. Would anyone be interested in something like this?

/r/django
https://redd.it/1c5cm0r
Using Pandas 2 and different datetime erros

Hey Folks,

I am working on a project that uses a bit old pandas version (1.5.3). I am trying to update it and use a more recent version (2.2.2). Its the first time I use pandas 2 btw. I simply ran all my unit tests and got multiple and different errors all concerning some datetime aspects. I tried troubleshooting by searching the errors and look in pandas release note but I find really complicated. It feels like the documentation is really exhaustive but I could really use a note on principal errors one can get switching to pandas 2.

Does anyone have any handy blogpost, article, documentation that specifies this ? My focus is mainly on datetime errors when differences computed or comparaisons

​

Thanks

/r/Python
https://redd.it/1c5b5ky
i want to save the changes but it creates a new record in django

I am having this problem i don't know why

when i try to save the data it creates a new record instead of updating it

here is my view function for adding and editing

def add_contact(request, contact_id=None):
# If contact_id is provided, it means we are editing an existing contact
if contact_id:
contact = InfoModel.objects.get(rollnumber=contact_id)
else:
contact = None
if request.method == 'POST':
# Extract form data
number = request.POST.get('number')
name = request.POST.get('name')
email = request.POST.get('email')
phone = request.POST.get('phone')

# Handle dynamic fields
dynamic_fields = request.POST.getlist('new_field[]')
dynamic_data = {f'field_{i}': value for i, value in enumerate(dynamic_fields, start=0)}
if contact:
contact = InfoModel.objects.get(rollnumber=contact_id)
# If editing an existing contact, update the contact object
contact.rollnumber = number
`contact.name` = name
`contact.email` = email
`contact.phone` = phone
for key, value in dynamic_data.items():
setattr(contact, key, value)
contact.save()
else:
# If adding a new contact, create a new Contact object
contact = InfoModel.objects.create(rollnumber=number, name=name, email=email, phone=phone, extra_data=dynamic_data)

return redirect('/')  # Redirect to the contact list page after adding/editing a contact
else:
return render(request, 'contact_form.html', {'contact': contact})

/r/djangolearning
https://redd.it/1c5f2p6
Post: Crafting A Bash Script with Tmux

Hi there,

I've written a blog post sharing my tmux script for my Django development environment.

Feel free to check it out!

Crafting a bash script with TMUX

​

/r/djangolearning
https://redd.it/1c55e7a
Big O Cheat Sheet: the time complexities of operations Python's data structures

I made a cheat sheet of all common operations on Python's many data structures. This include both the built-in data structures and all common standard library data structures.

The time complexities of different data structures in Python

If you're unfamiliar with time complexity and Big O notation, be sure to read the first section and the last two sections. I also recommend Ned Batchelder's talk/article that explains this topic more deeply.

/r/Python
https://redd.it/1c5l9px
bridge — automatic infrastructure for Django

https://github.com/Never-Over/bridge

# The Problem
We built bridge to solve the most frustrating part of any new project — infrastructure. Whenever you spin up a new Django project, you usually have to manually configure Postgres, background workers, a task queue, and more. The problem is amplified when you go to deploy your application — hosting providers don’t understand anything about what you’ve configured already, so you have to run through an even more complicated process to set up the same infrastructure in a deployed environment.

# What My Project Does
bridge is a pip-installable package that spins up all of the infrastructure you need, and automatically connects it to your Django project. By adding a single line to your Django project's settings.py file, bridge configures everything for you — this means you don’t need to mess with DATABASES, BROKER_URL, or other environment variables to connect to these services.

bridge also gives you the access you need to manage these services, including a database and Redis shell, as well as a Flower instance for monitoring background tasks.

When you’re ready to deploy, bridge can handle that as well. By running bridge init render, bridge will write all of the configuration necessary to deploy your application on Render, including

/r/Python
https://redd.it/1c5lw83
UXsim 1.1.1 released: Significantly increased performance for the network traffic flow simulator

[Version 1.1.1](https://github.com/toruseo/UXsim/releases/tag/v1.1.1) of UXsim is released, which improves performance significantly.

**Main Changes in 1.1.1**

* Add setting to adjust vehicle logging time interval via World.vehicle\_logging\_timestep\_interval
* By lowering the interval (e.g., World.vehicle\_logging\_timestep\_interval=2), the simulation time can be reduced (\~20% speed up), and we can obtain vehicle trajectory data with slightly less accuracy.
* The logging setting does not affect the internal simulation accuracy. Only the outputted trajectories are affected.
* By setting World.vehicle\_logging\_timestep\_interval=-1, the record\_log is turned off, and the simulation time can be significantly reduced (\~40% speed up).
* This addresses Issue #58
* Correct route choice behavior
* Vehicle.links\_prefer and Vehicle.links\_avoid work correctly now.

**UXsim**

UXsim is a free, open-source macroscopic and mesoscopic network traffic flow simulator written in Python. It simulates the movements of car travelers and traffic congestion in road networks. It is suitable for simulating large-scale (e.g., city-scale) traffic phenomena. UXsim is especially useful for scientific and educational purposes because of its simple, lightweight, and customizable features, but users are free to use UXsim for any purpose.

/r/Python
https://redd.it/1c5q36n
bridge — automatic infrastructure for Django

https://github.com/Never-Over/bridge

# The Problem

We built bridge to solve the most frustrating part of any new project — infrastructure. Whenever you spin up a new Django project, you usually have to manually configure Postgres, background workers, a task queue, and more. The problem is amplified when you go to deploy your application — hosting providers don’t understand anything about what you’ve configured already, so you have to run through an even more complicated process to set up the same infrastructure in a deployed environment.

# The Fix

bridge is a pip-installable package that spins up all of the infrastructure you need, and automatically connects it to your Django project. By adding a single line to your Django project's settings.py file, bridge configures everything for you — this means you don’t need to mess with DATABASES, BROKER_URL, or other environment variables to connect to these services.

bridge also gives you the access you need to manage these services, including a database and Redis shell, as well as a Flower instance for monitoring background tasks.

When you’re ready to deploy, bridge can handle that as well. By running bridge init render, bridge will write all of the configuration necessary to deploy your application on Render, including a button

/r/django
https://redd.it/1c5lc9j
How to make one instance of Flask app play a sound through another instance of the same app?

The idea is to have a simple Flask app that has a client page and a server page. I would have the client page open on my phone and the server page open on my computer. I click a button on my phone and a sound is played from my computer.

I know how to play a sound using Javascript, but I'm not sure how to play a sound with Javascript through the Flask app. Any ideas?

/r/flask
https://redd.it/1c5s83e
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/1c5vh3q