TG Telegram Group Link
Channel: Python Daily
Back to Bottom
New book! The Quick Python Book, Fourth Edition by Naomi Ceder

Hello everybody,

Thank you for having us here, and a huge "Thank you" to the moderators for letting us post.

We have just released the latest edition of The Quick Python Book by the one-and-only Naomi Ceder, and I wanted to share that news with the community.

Many of you are already familiar with Naomi's work and her massive contributions to the world of Python programming language.

The Quick Python Book has aided over 100,000 developers in mastering Python. The Fourth Edition of the book has been revised to include the latest features, control structures, and libraries of Python, along with new coverage of working with AI-generated Python code. Naomi, the author, has beautifully balanced the details of the language with the insights and advice required to accomplish any task. Her personal touch has made learning Python an enjoyable experience for countless developers.

📚 You can find the book here: https://mng.bz/aEQj

📖 Get into the liveBook: https://mng.bz/gvee

And last but not the least, get 46% off with code: receder46

Hope you find the book helpful.

Thank you.

Cheers,



/r/Python
https://redd.it/1cj8zp2
I've started writing Python bindings for lexertl

See https://github.com/BenHanson/pylexertl

I will see about registering as an official library when I am happy I have completed all the bindings. I added all the missing functions for the rules objects today, so things are in reasonable shape already.

My python experience has been limited up until now, but it is big for my new role.

I have a runtime parser generator https://github.com/BenHanson/parsertl17 which I also plan to add bindings for.

I hope this is of interest to somebody!

What My Project Does

Allows you to build lexical analysers at runtime and use them to lex text (in this case utf-8)

Target Audience

The C++ library has been used in production for over 10 years.

Comparison

I'm not aware of any competing library.

/r/Python
https://redd.it/1clpq5l
is gunicorn slow for you? Try with -k 'gevent'

Gunicorn --bind 0.0.0.0:8000 app.wsgi was so slow on vps, like 30s waiting for response, while python manage.py runserver took 500ms.

Try this:

pip install gevent

Gunicorn --bind 0.0.0.0:8000 -k 'gevent' app.wsgi


I don't see this one in tutorials that's why I am putting here for future google searchers

/r/django
https://redd.it/1cltda2
relax-py - Web framework for htmx with hot module replacement

Excited to finally showcase this!

It's still pretty rough around the edges, but I'm finally happy enough with the feature set and curious to see what the community thinks about a framework like this.

Code: [github.com/crpier/relax-py](http://github.com/crpier/relax-py)

Documentation: [crpier.github.io/relax-py](http://crpier.github.io/relax-py)

**What My Project Does**

`relax-py` is a Python framework for building full-stack applications with `htmx`

It provides tools for writing HTML in a manner similar to [simple\_html](https://github.com/keithasaurus/simple_html) (which also inspired the decision to use standard Python to write HTML, rather than use `Jinja2` or to make something like [templ](https://github.com/a-h/templ) work in Python)

It has:

* Hot Module Replacement (meaning, when you update the code that generates HTML templates, the browser also updates instantly) - see the video in the documentation for a quick demo of this
* URL resolution with type hinting - you can get the URL of an endpoint to use in your templates by using the function that handles that URL, and get help from static typing (for example, for putting path parameters in the URL)
* Helpers for dependency injection

In essence, this framework is just a bunch of decorators and functions over [starlette](https://www.starlette.io/), meaning everything that starlette has can be used alongside the framework.

**Target Audience**

Developers interested in building web applications with `htmx` that like new shiny things

/r/Python
https://redd.it/1clrnce
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/1cly3uc
D Kolmogorov-Arnold Network is just an MLP

It turns out, that you can write Kolmogorov-Arnold Network as an MLP, with some repeats and shift before ReLU.

https://colab.research.google.com/drive/1v3AHz5J3gk-vu4biESubJdOsUheycJNz

/r/MachineLearning
https://redd.it/1clcu5i
Pip 24.1 beta released, and it's a big one

I'd like to call attention to pip 24.1 beta asit is unusual for the pip team to release betas:

https://pip.pypa.io/en/latest/news/#b1-2024-05-06
https://pypi.org/project/pip/24.1b1/

You can install with:

python -m pip install pip==24.1b1

In particular they have upgraded their vendored version of packaging from 21.3 to 24.0, this was a big effort and fixed many bugs, included significant performance improvements, and will allow pip to support free threaded packages. However, it also means legacy versions and specifiers are no longer compatible with pip.

Because this was such a big land the pip maintainers have released a beta in the hopes people will test their workflows, and if something fails in an expected way report their steps as best as possible back to pip: https://github.com/pypa/pip/issues

I've been testing, and contributing a little bit, to the improved performance in this release, it is most noticeable on large dependency trees or long backtracking. For example, a dry run of "apache-airflowall" using cached packages on my machine goes from ~418 seconds to ~185 seconds.

/r/Python
https://redd.it/1clx454
How Python Asyncio Works: Recreating it from Scratch

Do you understand how asyncio works behind the scenes? Read this article and see how you can use Python generators to create your own version of asyncio, and then use the __await__ dunder method to use the async/await keywords to come full circle!



https://jacobpadilla.com/articles/recreating-asyncio

/r/Python
https://redd.it/1clz4dy
python-oracledb 2.2 and the VECTOR type in Oracle Database 23ai

python-oracledb 2.2, the Oracle Database driver, has been released with support for Oracle Database 23ai features such as the VECTOR and BOOLEAN data types, Implicit Connection Pooling, and improved connection performance. See the release announcement.

/r/Python
https://redd.it/1cm3j4q
Python script to convert Spotify Artists to Playlists

I've made my first bit of useful software and I wanted to share it here. I'd love some feedback (and it would be amazing to hear if someone has used it!)

What My Project Does:

Using the third party requests package, the script interacts with the Spotify web API to request all albums from the given Artist, then all the tracks from all of those albums. It then goes through the list to remove any duplicates and also tries to remove any unwanted versions (only done by examining the name of the track, since Spotify does not attribute a version type to its tracks). Once that's done a playlist is then created on your Spotify account with the name of the Artist and all the tracks are posted there in chronological (essentially per album) order.

Target Audience:

Anyone who struggles like me when they find a new Artist and they want to listen to every conceivable song from them!

Link to GitHub: https://github.com/RJW20/spotify-artist-to-playlist

/r/Python
https://redd.it/1cm8s6f
I've built a fully functional web application with Django + htmx + Alpine.js

# About the stack

I often see questions on how feasible it is to build a modern platform with Django, htmx and alpine.js. However, it's hard to find examples that work. I've built this song suggestion platform for DJs with this stack. Very little jasvascript was written and everything else is just Django templates. I also use django channels for websockets and celery for tasks.

# What happens in the platform

When I have DJ gigs the worst part is people interrupting asking for songs. Especially when they are drunk. This platform solves the problem:
- Guests scan the QR code
- They can search for any song and listen to a short preview
- They can make song suggestions and add an email address if they want to be notified when the song is playing
- The DJ can track this requests in an easy to use page, without the need to play any of them. If the do play a song, they can simple mark it as played on the platform and the guests that added the email address will be notified
- The DJ now has some good insights about their audience: What are the most requested tracks? What about artists?

Try the demo here

The idea

/r/django
https://redd.it/1cmao82
Invalid HTTPHOST header from Random domains

I have deployed this Django webapp in digital ocean droplet. I have deployed the app nginx, gunicorn, postgress way. I just added Admin mail in my production setting to get error mail, and noticed this error with different random domain request. To be honest I have little bit of experience with Django but very little knowledge about the production. I am getting multiple errors per minute with random unknown domains. Can somebody help?



Invalid HTTP\
HOST header: 'www.earsoccerfusion. org'. You may need to add 'www.earsoccerfusion. org' to ALLOWED_HOSTS.

DisallowedHost at /
Invalid HTTP_HOST header: 'www.earsoccerfusion. org'. You may need to add 'www.earsoccerfusion. org' to ALLOWED_HOSTS.

/r/django
https://redd.it/1cmhcmz
Has anyone made a flask application (and deployed it for free) that deals with ML models?

I want to hear some thoughts on it since I am having trouble finding a free hosting server for a flask application that can deal with h5 files (model files).

/r/flask
https://redd.it/1cmiuya
Rethinking String Encoding: a 37.5% space efficient string encoding than UTF-8 in Apache Fury

In rpc/serialization systems, we often need to send namespace/path/filename/fieldName/packageName/moduleName/className/enumValue string between processes.
Those strings are mostly ascii strings. In order to transfer between processes, we encode such strings using utf-8 encodings. Such encoding will take one byte for every char, which is not space efficient actually.
If we take a deeper look, we will found that most chars are lowercase chars, ., $ and _, which can be expressed in a much smaller range 0\~32. But one byte can represent range 0\~255, the significant bits are wasted, and this cost is not ignorable. In a dynamic serialization framework, such meta will take considerable cost compared to actual data.
So we proposed a new string encoding which we called meta string encoding in Fury. It will encode most chars using 5 bits instead of 8 bits in utf-8 encoding, which can bring 37.5% space cost savings compared to utf-8 encoding.
For string can't be represented by 5 bits, we also proposed encoding using 6 bits which can bring 25% space cost savings

More details can be found our blog https://fury.apache.org/blog/fury_meta_string_37_5_percent_space_efficient_encoding_than_utf8

/r/Python
https://redd.it/1cmcy3y
List of Sites that Packages Need to Connect to?

I'm doing most of my work behind a government firewall, and I'm having trouble connecting to certain sites. I can do the usual "pip" installs just fine, but I'm talking about packages that need to download data to do their job. An example is the NLTK (Natural Language Toolkit) package, which downloads dictionaries, lookup tables for sentiment analysis, and so on. I know what sites to open up for that particular problem (pastebin.com and nltk.org), but I wonder if anybody's made a list of such sites for different packages.

I can ask for the two sites I know about to be opened up, but I'd like to have a more comprehensive list so I don't have to go through the red tape multiple times.

/r/Python
https://redd.it/1cmdfvy
Web App Deployment

I am trying to deploy a full web app, postgres database, Python middleware, react. I made it for my company I wanted to dockerize and deploy using AWS Rws and app runner, my company wants me to use rstudio connect and said this is their “server” what is rstudio connect? Can I accomplish a full deployment using rstudio connect? To me it seems like a server manager and sounds like it will add pointless extra weight.

/r/Python
https://redd.it/1cmmgu9
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/1cmqqgn
Slow App, Cache it?

I made a flask app that’s kinda slow because it does complex database operations. It is what it is. The data doesn’t change all that much, daily fidelity is plenty.

Could I cache return render template somehow as static html for each of the slow routes? Would be much faster to read the data from disk thank dynamically query it

What I am thinking is to maybe have a cronjob to write static html files using a background flask worker and then return literally just the muliline string as response? Hacky approach but should work, no?

Maybe there’s a better way?

/r/flask
https://redd.it/1cmqpc8
HTML Embed Code:
2024/05/08 09:47:41
Back to Top