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
Best Approach to Styling Django Forms

I am always struggling to style Django forms(field, label, field/form errors), how are you guys dealing with this? What will you propose as the best approach(or library)?

/r/django
https://redd.it/1eiazvx
making a api endpoint start a routine that fetches from external API

Hello everyone,


So I'm trying to make this thing where when this api point is called i fetch data from another external API to save.

I think the process must be somehow asincronous, in the way that when I call it I shouldn't wait for the whole thing to process and have it "running in the background" (I plan even to give a get call so that I can see the progress of a given routine).


How can I achieve this?

/r/django
https://redd.it/1eiafpw
Inertia JS equivalent for Django

I found Inertia JS to be a handy tool for using Laravel at the backend and React / Vue at the frontend without the hassle of building API.

Do we have similar solution in Django world ?

The inertia website says that we can use it with Django but it is fine tuned for Laravel.



/r/django
https://redd.it/1eie1pa
Compress JSON: the missing Python utility to read and write compressed JSONs.

**What My Project Does**
I have always found working with compressed JSON files cumbersome, as for the life of me I cannot recall how to use Python's compression utilities. Plus, when you need to handle multiple possible formats, the code gets ugly quickly.

Compress-json abstracts away the complexities of handling different compression formats, allowing you to focus on writing clean and maintainable code.

**Installation**

You can install compress-json quickly using pip:

pip install compress_json

**Examples**

Here's how you can use compress-json to compress and decompress JSON files with minimal effort. Here it uses automatic detection of the compression type:

import compress_json

# Your JSON data
data = {
"A": {
"B": "C"
}
}

# Dumping data to various compressed files
compress_json.dump(data, "data.json.gz") # gzip compression
compress_json.dump(data, "data.json.bz") # bz2 compression
compress_json.dump(data, "data.json.lzma") # lzma compression



/r/Python
https://redd.it/1ei8vl9
Help in getting new project ideas, primarily backend based

I have created many app projects with django, DRF and channels, but I am sick of creating just basic CRUD/chat apps. Can you guys give me any ideas on more projects which are primarily backend based, can use different concepts, and domains/fields I can integrate them with ?

I don't want to create a Netflix or Amazon clone or something like that too. Please help me out here guys.

/r/django
https://redd.it/1eiid5m
What are popular sites that use Django template engine?

I know Pinterest used Django in backend but I haven't seen any popular company site that uses Django's built in html template engine. Do you know any?

/r/django
https://redd.it/1ei94m9
dir-assistant: Chat with your current directory's files using a local or API LLM.

# What my Project Does

Dir-assistant is a CLI LLM runner that chooses the best info from your current directory (recursively) to include with your prompt. It is designed to improve programmer efficiency by speeding research and automatically writing code. It has been tested on a repository with 900k lines of code, and it produced useful contextually aware code.

Demo gif (images are not allowed in r/Python)

Setup is quick:

pip install dir-assistant
dir-assistant models download-embed
dir-assistant models download-llm
cd directory/to/chat/with
dir-assistant

It works with almost all local and API LLMs.

Yesterday I released the first major release, 1.0.0, which added pip install support and many quality of life improvements. I am aiming to support more operating systems, so if you would like to help by testing, please submit a github issue with your results. Other contributions including PRs are welcome as well.

# Target Audience

Coders who want to improve productivity

# Comparison

Other LLM runners are not aware of your files, perform badly, or are designed for small snippets. Dir-assistant is the best solution currently available for large projects.

# GitHub

GitHub Link: https://github.com/curvedinf/dir-assistant/

/r/Python
https://redd.it/1eihaif
D Is the new norm for NLP papers "prompt engineering" papers?

So many papers seem to essentially be "how can we make LLM 1 do this without training?" I haven't published in a while and have been in industry for the past few years. I recently joined a new company in a slightly more research-y position and am working with research scientists and graduate interns. I've noticed that every single one of them is working on something that I would have been reprimanded by my PI for in graduate school. Basically, "how can we make LLMs do this really complicated task without doing any training?" And perhaps somewhat unsurprisingly, in many cases, you can't. I think that's why these days there are so many negative result papers in NLP.

Is this the new norm? It's become a pain to go through the CL section of arXiv. 98% of the papers are something like "how come LLaMA can't understand numbers?"

I'm wondering if I'm just being the senile old man in the corner of the bar or if everyone else feels the same.

/r/MachineLearning
https://redd.it/1ei9e3l
Which famous sites use Django's built-in template engine?

There are many famous companies that use Django as backend framework but I haven't seen companies that use Django's built-in template engine. Do you know any?

/r/djangolearning
https://redd.it/1eiekxe
completed 20mins long django tutorial and done with first project. what is next? can you share some other tutorials?

https://preview.redd.it/ute7x56e5cgd1.png?width=1848&format=png&auto=webp&s=4d20c68926d40a22dedfc777e28c8778f73311d1



/r/djangolearning
https://redd.it/1eiokqe
Django with ESP32

I am trying to connect my iot project with django development server as I have not deployed my system as if yet. The main problem lies in the server connection, I have to run all port server i.e. 000.0.0:8000 inorder to run my laptops ip server with my sensors url to post data via ESP32. Due to this setup it fails to connect with the server and does not post data untill it wishes to do so and with this my logic for the code gets messed up. I have done all experiments with the settings of cors & firewall. Once I am able to post data I can store the info easily, is there any alternative or correct path that I should follow to sort this out

/r/django
https://redd.it/1eiruln
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

/r/Python
https://redd.it/1eip7i1
socket POC where tasks are triggered by the client and responses are sent as pickled Python objects.

I made a POC of a socket client-server communication

what my project does?

it allows communication between client-server,

client gets to trigger tasks in the server and receive task response as an unpickled python object

target audience?

just for fun or for people to read as reference

comparison?

well its just a minified version of the FastAPI -> Redis -> Celery flow

workflow ?

* Client connects to the socket server.
* Server accepts the client connection and handles the connection in a separate thread.
* Client creates a payload using `._create_payload(b"EVENT", body)` and sends it using `.send_event(tag, args, kwargs)`.
* Server always attempts to read 13 bytes (value from :`struct.calcsize("!5sQ")`).
* The first 5 bytes represent the event scope, which is either `EVENT` or `RESLT`.
* The following 8 bytes represent an unsigned integer indicating the body's length.
* Server determines the event controller by tag.
* Server Pickles the controller response and creates a payload using `._create_payload(b"RESLT", body)`.
* Meanwhile, the client blocks execution until 13 bytes are received.
* Client determines the body length n, attempts to receive n bytes (body), and unpickles it.
* `.send_event(tag, args, kwargs)` returns the unpickled result.

here's the source code if anyone would like to code review it : [https://github.com/achaayb/Montagne](https://github.com/achaayb/Montagne)

/r/Python
https://redd.it/1eivr7n
What ORMs do you use and why?

Hello !
I am building a Flask application and up until now I've only used SQL queries.
But now I am building a larger application (a forum) and I am considering to use an ORM.
The biggest reason for this is to have a layer capable translating all my stuff to any relational DB.
Another thing is maintainability. It feels easier to implement models to be honest.
What ORMs do you use? I heard SQLAchemy is the most popular and the most "used in industry". But people call it off for being hard to use and having poor performance.
I found PonyORM and it looks like a great alternative. I love the syntax and how lightweight it is.
Also PeeWee seems interesting.
What ORMs do you use? And, why is SQLAchemy much more popular? Is it because of the name? What does SQLAchemy have that other ORMs don't have?

/r/flask
https://redd.it/1eiop9s
A script to batch convert media with ffmpeg

# What My Project Does

This is a Python script that batch-processes videos using ffmpeg. The script evaluates the list of input files and directories provided and converts all files to the specified output directory. The conversion is done with ffmpeg using the command line argument from one of the available presets.

It also provides a nice formatted output to the console with colors and progress bars.

# Target Audience

Myself and any other that has a bunch of media to transcode

# Comparison

Better than a batch file, there are colored progress bars to stare at for hours while the media is converted.

# GitHub

https://github.com/ts-manuel/ffmpeg-batch

/r/Python
https://redd.it/1eiywug
Flask to Quart

Migrated from Flask to Quart using the steps on this page: https://quart.palletsprojects.com/en/latest/how\_to\_guides/flask\_migration.html
Took about 15-20 minutes to get everything back up and running again. I had to use CoPilot to help fix a couple of glitches. Also, changed from gunicorn to uvicorn. Deployed and it seems to work. From what I read there is a 2-5 times performance improvement. I don't have metrics. But it "feels" faster and seems like an easy win. Want to hear what y'all have to say about this.

But question...what limitations and bugaboos have you run into with Quart in moving from Flask? Should I fully commit to Quart?

edit: Since both Flask and Quart are part of pallets project, they are not really "competing" frameworks. I mean, Quart may be where Flask is headed. Am I right?

/r/flask
https://redd.it/1eipr60
Pastebin Command Line App | PasteCMD

# What my Project Does?

PasteCDM makes using Pastebin much more simple, with a CLI app. As of now, you can:

1. Upload text sentences
2. Upload file contents

# Target Audience

Anyone who uses Pastebin service

# Comparison

N/A

# GitHub

GitHub Link: https://github.com/rohankishore/PasteCMD

/r/Python
https://redd.it/1eifw9u
Reasons why you love building with Django?

What are the reasons you love working with Django?

/r/django
https://redd.it/1ej59tz
How should I handle errors, aborts, logging and audits in my endpoint?

I have a login endpoint (api/auth.py) that receives the request, and uses an auth service (services/auth_service.py). Btw I'm using Flask for backend React for frontend.
I was handling things like this, for a clean endpoint, and letting auth_service to do the logic:

auth.py
@authbp.route("/login", methods=["POST"])
def login():
data = data.get
json()
response, status = AuthService.login(data)
return jsonify(response), status

authservice.py
class AuthService:
@staticmethod
def login(data):
email = data.get("email")
password = data.get("password")
if !validate
credentials(email, password):
abort(401, description="Email or password incorrect")

# Token creation here

return {"success": True, "accesstoken": accesstoken}, 200

So basically, anything other than a successful login triggers an abort. I had no problem with this,

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