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
Help needed with Gunicorn config

I basically have the following gunicorn command:

gunicorn -k gevent -w 4 -b myapp:app0.0.0.0:8000

Now the thing is sometimes the DB calls take 10 sec to execute or 1 sec when the load increases/decreases. Most of the times I get this error:

https://preview.redd.it/13x9vvwfs6hd1.png?width=1284&format=png&auto=webp&s=281e81a40ceaa03d8e304a613434171ca0c57d43

Why do I get this? I also have set my connection pool to 10 and i mean, the site gets started loading slow after I hit refresh 6 times then it is suddenly slow like a turtle with workers crashing. Why? What am I doing wrong?

I need to know why my workers are getting exhausted? Even the data I am giving is paginated too so I did not understand...

/r/flask
https://redd.it/1em4utq
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/1enldf3
Need help with flask @login_required redirection

In my account route, I have a \`login\_required\` decorator. But when I log in, it doesn't redirect back to the account page; instead, it redirects the user back to the home page.

@app.route("/login", methods=['POST', 'GET'])
def login():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            # Correct handling of the next page parameter
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for('home'))
        else:
           

/r/flask
https://redd.it/1em9a5h
emval: validating email addresses at 1000x the speed.

What My Project Does: Python Email Validation at turbo speeds.

Target Audience: Developers

Comparison: emval largely draws it's inspiration from python-email-validator. They key difference is performance. emval validates emails at 1000x the speed.

Over the course of a year, I've become obsessed with speeding up all things python. Drawing inspiration from authors of UV, Pydantic, Polars I set out to build an amazingly fast email validator. Let me know what you think!

https://github.com/bnkc/emval

/r/Python
https://redd.it/1enbm7r
D FlexAttention: Flexibility of PyTorch with Performance of FlashAttention

https://pytorch.org/blog/flexattention/


/r/MachineLearning
https://redd.it/1en6h4b
Not understanding topics while self teaching.

I am teaching myself Python using online resources. After learning a topic, I sometimes feel like I only retained like 60% of it. Has anyone else felt like that when learning ?

/r/Python
https://redd.it/1ensz5h
Spotify batch import script

Hello all. Sharing this script for batch uploading files to spotify. Couldnt find any free services and figured this would be a fairly easy automation task. All contributions welcome, enjoy! [https://github.com/SlideeScherz/spotify-batcher](https://github.com/SlideeScherz/spotify-batcher)

**What My Project Does**

* **given a text file of songs, add all to Spotify library or user playlist**

**Target Audience** (e.g., Is it meant for production, just a toy project, etc.)

* Spotify users, Automation lovers

**Comparison** (A brief comparison explaining how it differs from existing alternatives.)

* free, open source

/r/Python
https://redd.it/1enp91w
Any startup or small / fast-moving teams using TDD with Django?

I am contemplating the idea of moving towards TDD when using Django. I've noticed that I spend a lot of time writing temporary scripts or playing around with the django shell when working on a specific piece of code. It feels fast enough and intuitive, but I feel like all this parallel work could be used to also have tests beside my code, and benefit from it a few months down the line.

I was scared of over engineering things or do too much at the same time, so haven't put too much effort in testing for my current project. My intuition was that, in order to be fast and simple for a first prototype / MVP, it was better to put TDD on the side. But things get complex fast and a couple months are enough to forget about certain pieces of my codebase.

I was wondering if some people are consistent in using TDD from the very start, even for small projects or prototypes that require fast delivery? Or if on the other hand some people have tried and concluded it was too much overhead?

Thank you!

/r/django
https://redd.it/1enwvfi
Add examples to Sphinx docs automatically

You have developer a package with an examples folder containing several examples of how to use your package and you would like to include them into your sphinx docs.

screenshot

We expect that you are familiar with Sphinx (a tool that automatically generate the documentation for your package).

How to include code examples into Sphinx docs?

1. Manually. You can write the rst files yourself and then add them manually into the the index.rst.
2. Automatically. Use the package to generate the rst files for each of your examples (and generate a toc file for them).

What do you need?

A folder containing your python examples.

How to use the package?

1. Install the package.
2. Generate your documentations using Sphinx (e.g., make html).
3. Use the package to generate the examples rst files and the examples toc file.
4. Regenerate the documentation (e.g., make html).

Example of how to add examples to index.rst

.. toctree::

:maxdepth: 3

:caption: Contents:

modules

examples



Here is the project repo on GitHub: https://github.com/ahmad88me/sphinx\_example\_includer

/r/Python
https://redd.it/1eo0yie
Unable to resolve 404 Not Found Error

I have a functioning HTML page with the following 'Accept' anchor button inside a table.

<td><a href="{{ url_for('accept_req', ad_id = ele[0].ad_id) }}" class="btn btn-outline-success">Accept</a></td>

Now I know for sure that ele[0].ad_id isnt causing the problem. Because the link is being generated.

But somehow the control is not reaching to the function definition:

@app.route('/edittable/acceptreq/<int:adid>', methods = 'GET', 'POST')
def acceptreq(adid):
#--------func definitions----
     
return
(rendertemplate("successpage.html"))



I am convinced that there is no similar named function or similar address (tried changing the route address but same result) function in my file.
-------------------------------------------------

Please guide me where am i going wrong?



/r/flask
https://redd.it/1em8c6b
Crawling Pages with Infinite Scroll using Scrapy and Playwright

Starting to document parts of my recent crawling journey in some blog posts. The first was navigating infinite scroll pages with inconsistent behaviors.

Crawling Pages with Infinite Scroll using Scrapy and Playwright





/r/Python
https://redd.it/1eo2yry
How to convert ipynb to pdf inside Jupyter notebook? I came across a solution stating we need to install pandoc but the official pandoc redirects us to the GitHub files which one to download now ??




/r/IPython
https://redd.it/1eo5ipp
LLM Aided OCR (Correcting Tesseract OCR Errors with LLMs with Python)

Code: https://github.com/Dicklesworthstone/llm\_aided\_ocr

# What My Project Does

Almost exactly 1 year ago, I made a little project using Llama2 (which had just come out) to improve the output of Tesseract OCR by correcting obvious OCR errors. That was exciting at the time because OpenAI's API calls were still quite expensive for GPT4, and the cost of running it on a book-length PDF would just be prohibitive. In contrast, you could run Llama2 locally on a machine with just a CPU, and it would be extremely slow, but "free" if you had a spare machine lying around.

Well, it's amazing how things have changed since then. Not only have models gotten a lot better, but the latest "low tier" offerings from OpenAI (GPT4o-mini) and Anthropic (Claude3-Haiku) are incredibly cheap and incredibly fast. So cheap and fast, in fact, that you can now break the document up into little chunks and submit them to the API concurrently (where each chunk can go through a multi-stage process, in which the output of the first stage is passed into another prompt for the next stage) and assemble it all in a shockingly short amount of time, and for basically a rounding error in terms of cost.

My original

/r/Python
https://redd.it/1eo6dxz
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/1eof43a
How to go from intermediate to advanced in Django & HTMX? Seeking Guidance on Django & HTMX Best Practices

Dear Django Community,

Like many of you, I've fully embraced the HTMX hype and have been developing an application as part of my job (1-2 days per week) for the past two years. Working solo, I've made stellar progress and implemented an astonishing amount of features given my limited time. However, now that the codebase is growing, I'm running into challenges with architectural decisions and could really use some expert advice on how to improve further. Here are a few of the issues I've been struggling with lately:

1. Front-end Code Organization:

I have numerous partials that get swapped in and out, and it’s becoming increasingly difficult to manage. My code is not very DRY; I find myself repeatedly implementing similar HTML swaps across the codebase. However, I’m also uncertain about reusing the same HTML code block in multiple locations. I’m unsure how to test such html blocks for proper swap-ins, and tracking dependencies reliably seems daunting. How do experts organize their front-end codebases to avoid such issues?

2. Dynamic Forms:

Initially, I implemented everything in pure HTML with HTMX, but the number of endpoints and swaps quickly spiraled out of control. Now, I use crispy_forms and submit the form on each change and then

/r/django
https://redd.it/1eoahao
Fits2db -Tool to load fits file tables into a sql database



What My Project Does:
fits2db is an open-source tool designed to convert FITS files (commonly used in astronomy) into SQL databases. This makes it easier to handle, query, and analyze the large datasets typically stored in FITS files.

Target Audience:
This tool is perfect for astronomers, data scientists, and anyone who regularly works with FITS files and needs an efficient way to manage and query their data.

Comparison:
Compared to existing tools, fits2db focuses specifically on seamless conversion to SQL databases, allowing for more flexible and powerful data manipulation than basic FITS file readers or converters that may not support complex queries.

I’m looking for feedback, feature suggestions, and potential contributors. Please check it out and share your thoughts!

GitHub: fits2db



/r/Python
https://redd.it/1eoa7ir
Flake8 Import Guard: Automate Import Restriction Checks in Python Projects

# What My Project Does?

Flake8 Import Guard is a Flake8 plugin that automates the enforcement of import restrictions in Python projects. It detects forbidden imports in new and modified files, focusing on newly added imports in Git-versioned files.

The plugin is highly configurable through `.flake8` or `pyproject.toml` files, allowing teams to tailor import restrictions to their specific needs.

# Target Audience

* Python developers working on medium to large-scale projects
* Development teams looking to enforce coding standards
* Open-source maintainers wanting to control library usage
* Anyone looking to gradually phase out deprecated modules or prevent the use of certain libraries
* Teams aiming to streamline their code review process

# Comparison

While there are several Flake8 plugins that handle various aspects of import checking(While plugins like `flake8-forbidden-imports`, or `flake8-tidy-imports` offer some similar functionalities), Flake8 Import Guard offers a unique combination of features not found in other plugins:

* Git-aware checking
* Unlike other plugins, it only flags newly added imports by considering Git change history. This makes it ideal for introducing to existing projects without causing immediate disruption.
* Flexible configuration
* Offers easy setup through `.flake8` or `pyproject.toml` files, allowing teams to tailor import restrictions to their specific needs. Seamless integration with existing Flake8

/r/Python
https://redd.it/1eoip79
A Slick n Lightweight screen recorder for linux! With some cool features :]


What My Project Does:

Slick Recorder is a lightweight and stylish recording application designed specifically for Linux. It offers a sleek user interface and powerful features to make your recording experience seamless and enjoyable.

Target Audience :

Linux Users

Comparison :

Noise Reduction: Automatically reduces background noise for clear audio recordings.
Easy to install just run 'pip install SlickRecorder'
Keyboard Input Display: Show your keyboard inputs in the recordings.
Subtitle Generation: Generate subtitles for your recordings effortlessly.
Lightweight GUI: A cool and minimalistic graphical interface to manage all your recording tasks.
Custom Cursors: Personalize your recording experience with custom cursor options.

Github : https://github.com/merwin-asm/SlickRecorder

/r/Python
https://redd.it/1eoptj5
Website to app

I have a functional website with frontend react and backend django. Now, i want to make a mobile application for the same+ i am a beginner. I want to know how can i create a mobile app using the same django backend. Should i use flutter or react native.

Please give any advice u have

/r/django
https://redd.it/1eoo6nv