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
Project to quantize/perfect/vectorize loose scribbles

Any points on how I would go about doing that in python? So a loose, sloppy oval straightens out into a perfect oval estimated into the orientation size that the more sloppy version seemed intent to be, and the same thing with lines, circles, squares, trianges, etc.
I think it'd be a path for a program, perhaps Kivy -> iPad, something like that. Any thoughts? Or is there something notable out there that does this?

/r/Python
https://redd.it/1b3s3ti
Python Flask code improvement - ChatGPT prompt

I'm wondering if folks here have good prompts specifically for Python Flask, or if I can improve mine. Note - some instructions are specific for VSCode / pylint.
Here is my prompt in a GPT:
https://chat.openai.com/g/g-6b2rOEWL7-python-flask-code-optimizer

The prompt used::
Objective: Enhance the quality of Python code for applications utilizing Flask, SQLAlchemy ORM, and WTF forms. The goal is to ensure the code is production-ready, adhering to high-quality standards, including PEP 8 compliance, with an emphasis on robust error handling, readability, and efficiency.

Requirements:
\- Code Quality: Optimize code to be clean, efficient, and maintainable. Ensure adherence to PEP 8 guidelines for Python code styling and format.
\- Error Handling: Implement comprehensive error handling mechanisms to manage and mitigate potential runtime errors effectively.
\- Readability: Improve code readability through clear naming conventions, succinct but informative docstrings, and logical structuring.
\- Type Annotations: Apply precise type annotations to functions and variables to enhance code clarity and predictability.
\- Documentation: Include detailed, succinct docstrings for all functions and classes, providing a clear explanation of their purpose, parameters, and return types.
\- Logging: Adopt lazy % formatting in logging functions to optimize performance and

/r/flask
https://redd.it/1b43i3z
Real-time ingestion pipeline for RAG app in Python

Hi, I am working on a stream processing framework called Bytewax and I recently gave a talk where I read live data from HackerNews API, cleaned it with unstructured.io, created embeddings with a hugging face model, and stored everything in Milvus.

I find a lot of devs are struggling with real-time streaming. The steps are easy to follow, and it is an end-to-end Python: https://github.com/bytewax/real-time-milvus
I also added diagrams and summarized it in a blog https://bytewax.io/blog/stream-process-embed-repeat

/r/Python
https://redd.it/1b3dit2
How to translate consumers?

I have text I want to translate in my consumers. Unfortunately, the translation doesn't seem to take effect.

I'm able to mark the strings I want to translate for translation, translate them in the .po file and compile it but if I choose the language I translated thoses strings in my website, those strings aren't translated and still appear in the language they were written in.

Maybe I need to use gettext_lazy? In that case, how to I send the text marked with gettext_lazy to the WebSocket? it makes the text non json serializable.

How to I translate text that is in a consumer file?

/r/django
https://redd.it/1b4bj5n
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/1b49uzk
Django, Bootstrap and CSS doubts

Hi, I'm new to Django, learning how to make backend mostly, but I want to make some projects and use some CSS in them. I already seem some things related, but I have a few questions.

Is Bootstrap the standard for fronted Django? Is it the only way to edit forms with CSS? If I don't use Bootstrap how can I edit forms with CSS? I now that for the most part you won't be using Django as a fronted framework, but I still have this questions

/r/django
https://redd.it/1b4fgt0
What are downside of django-watson

django-watson provides full text search system that is great but in my knowledge, if watson regularly reorganizes search index, it might cause db overhead isnt it?

Before adopting the new package, I want to know what are some of downside of watson? I feel afraid it might cause db overhead or dropping django performance

/r/django
https://redd.it/1b4ikpy
Valid uses of eval()?

I’m wondering if anyone has ever seen a case of code using eval() and thought to themselves “yeah actually that’s probably the right way to do it”?

My understanding has always been that it’s a huge security risk and generally a recipe for disaster.

But I was just working on a task where I couldn’t really figure out any other way to achieve the dynamic functionality I was looking for, so I wrote code that assembles a string to do what I need, and then runs eval() on that string. Pretty sure this is the first time I’ve ever used eval() at all.

It’s a low-stakes proof of concept for a totally internal tool, so I’m not hugely worried about security at the moment, but it just feels so icky to do something like that. I’m curious if in others’ experience there’s always a better way than using eval(), or if sometimes it’s legit.


/r/Python
https://redd.it/1b49p6d
spellcheck multilingual

hi everyone, for one of my projects, I have to develop a spell checker in practically all the languages ​​supported by OPENAI, and I thought why not share it with everyone!
so here it is:

https://github.com/loictonneau75/spellcheck

There is certainly still a lot of functionality to be developed so be free to suggest your ideas

/r/Python
https://redd.it/1b4kzxu
IS HTML Semantics Supported by all Browsers?

As part of a final exam project, I'm expected to include accessibility features to my website. Can I use HTML Semantic tags? Some websites state that it should be used to support users with disability. Other websites say that some browsers do not support it.

I'm confused now. Please advise.

I' also considering Flask Mobility for mobile friendly websites

/r/flask
https://redd.it/1b4p4ae
How do you manage your Django project versioning?

I am using poetry with package-mode disabled to manage the virtual environment for my Django project. How can I implement semantic versioning releases with poetry and GitHub Action for my Django project?

/r/django
https://redd.it/1b4o37r
Where to learn Django like Flask Mega-Tutorial from Miguel Grinberg?

I learned how to use Flask by following Miguel Grinberg's Flask Mega tutorial, which was great. I learned how to build and deploy a Flask microservice web app and what it looks like to write clean and effective code for the app which makes me (a beginner) feel like he writing an industry-standard code layout. Is there any tutorial or book similar to this in Django?

/r/flask
https://redd.it/1b4s3fs
How to manage vercel deployment?

Currently I am using vercel to deploy a django app for a project I maintain but one of the difficulties I've encountered is that it doesn't look like there's a way access the shell (so I can't run manage.py commands to do things like create a superuser). One of the ideas I had was to automatically create a supper user through secrets on deploy, but I haven't fully investigated it yet.

I am mainly using vercel so I can use its free tier to very the software / provide instructions to the person on the team who will be paying for the real deployment once we officially release. If there's a better alternative for this (I am using Vercel + Vercel Postgres + Vercel Blob right now) please let me know.

One of the dumber ideas I thought of was temporarily adding an endpoint to inject in the user creation and then close it up after I was done.

Also one of the things I'd like to do is run custom management commands (basically for DB management/pruning/exporting). Are there any integrations for Django Admin that allow for this?

/r/django
https://redd.it/1b4q8x7
An extremely modern and configurable Python project template

# What My Project Does

Rob's Awesome Python Template is a cookiecutter template meant to bootstrap python projects using modern best practices.

At the very basic level it includes:

- Modern pyproject.toml without any legacy files (no setup.py or setup.cfg).
- Development Management using Makefiles.
- Configuration Management with Pydantic.
- PyPI Publishing from Git Tags using setuptools-scm.
- Formatting and Linting with Ruff.
- Typing with mypy.
- Lockfiles (requirements.txt, requirements-dev.txt) with uv.
- Testing with pytest.
- CI/CD using Github Actions.
- Precommit Hooks using the precommit framework.

It also has a ton of optional features:

- Github Actions for CI
- Cross Platform (arm, arm64, amd64) Docker containers using the Multi-Py project.
- Optionally use any combination of FastAPI, Click/Typer, Celery, and Sqlalchemy.

I've used this template for a number of projects- QuasiQueue, Paracelsus, and Fedimapper being some nice examples. If you want to see exactly what the project would generate today you can review the examples repository which builds a few projects using different options to give people a feel for what things can look like.

# Target Audience

Any developer looking to bootstrap their projects can use this! What makes it really helpful is that you get a modern, high quality project with tools already configured before you even write a single line of

/r/Python
https://redd.it/1b4qwds
Created a Django react template and deployed it

/r/djangolearning
https://redd.it/1b4ufbv
Class properties and methods?

Hi,

I am working in a django repo where the views and the forms and the all the things inherit and inherit some more.

How do you guys manage to get an understanding of what the actual resulting methods and properties of any given class is? Do you lean into the ide capabilities (which? how??) or do you guys have a protocol?

​

thx S

/r/django
https://redd.it/1b4y1kg
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/1b52uds
Text-to-speech with python

Greetings pythonistas,

I'm thrilled to share with you my latest article which delves into the amazing python package, pyttsx3. Explore the capabilities and how interesting the Text-to-Speech(TTS) package is

Read the full blog post here:
https://jeffmint.hashnode.dev/code-that-speaks-a-beginners-guide-to-pyttsx3-text-to-speech-tts-in-python

If you find the content intriguing and would like to actively contribute to its development, I'm excited to announce that it's an open-source initiative! Feel free to explore the repository, and let's join forces to enhance and elevate the usage of the package together. Your collaboration and ideas are invaluable in making it even more remarkable.
https://github.com/Minty-cyber/CodeThatSpeaks

Cheers to building something great together! 🚀

/r/Python
https://redd.it/1b51w2t
When exactly should you use .js when using a flask db

Hi all, I'm trying to figure something out. Since I started writing my website, anything that involved modifying my database I would do an onclick call to a .js routine. But as I've gotten further and seen other peoples code I'm seeing that is not necessary as it can simply be done through routing and forms. I was doing it simply because the original tutorial I followed used .js. Is there some reason I'm not seeing? And generally speaking when is it a good idea to start mixing .js in?

/r/flask
https://redd.it/1b56ksn
Flask Admin does not hash the User password

The code encrypts from the registration page but does not encrypt from Flask Admin. I have read examples online and written this code. I think the values for target, oldvalue and initiator are incorrect. I did not understand what they should be initialised with.


class User(db.Model, UserMixin):
__tablename__ = "user"
user_id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
firstname = db.Column(db.String(20), nullable=False)
lastname = db.Column(db.String(20), nullable=False)
email = db.Column(db.String(80), unique=True, nullable=False)
password = db.Column(db.String(80), nullable=False)
agreed_terms = db.Column(db.String(80), nullable=False)
reg_datetime = db.Column(db.DateTime, default=dt.now)
role = db.Column(db.String(20), nullable=False)

def __str__(self):
return self.username

@event.listens_for(User.password, 'set', retval=True)
def hash_user_password(target, password, oldvalue,

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