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
PEP 802 – Display Syntax for the Empty Set

PEP 802 – Display Syntax for the Empty Set
https://peps.python.org/pep-0802/

# Abstract

We propose a new notation, {/}, to construct and represent the empty set. This is modelled after the corresponding mathematical symbol ‘∅’.

This complements the existing notation for empty tuples, lists, and dictionaries, which use ()[], and {} respectively.

>>> type({/})
<class 'set'>
>>> {/} == set()
True

# Motivation

Sets are currently the only built-in collection type that have a display syntax, but no notation to express an empty collection. The Python Language Reference notes this, stating:

>An empty set cannot be constructed with {}; this literal constructs an empty dictionary.

This can be confusing for beginners, especially those coming to the language from a scientific or mathematical background, where sets may be in more common use than dictionaries or maps.

A syntax notation for the empty set has the important benefit of not requiring a name lookup (unlike set()). {/} will always have a consistent meaning, improving teachability of core concepts to beginners. For example, users must be careful not to use set as a local variable name, as doing so prevents constructing new sets. This can be frustrating as beginners may not know how to recover the `set` type if they have overriden the name.

/r/Python
https://redd.it/1mnuan1
I built a tiny tool to convert Pydantic models to TypeScript. What do you think?

At work we use FastAPI and Next.js, and I often need to turn Pydantic models into TypeScript for the frontend. Doing it by hand every time was boring, slow, and easy to mess up so I built a small app to do it for me.

* Paste your Pydantic models/enums, get clean TypeScript interfaces/types instantly.
* Runs 100% in your browser (no server, no data saved)
* One-click copy or download a .ts file

# What My Project Does

My project is a simple website that converts your Python Pydantic models into clean TypeScript code. You just paste your Pydantic code, and it instantly gives you the TypeScript version. It all happens right in your browser, so your code is safe and never saved. This saves you from having to manually type out all the interfaces, which is boring and easy to mess up.

# Target Audience

This is for developers who use FastAPI on the backend and TypeScript (with frameworks like Next.js or React) on the frontend. It's a professional tool meant to be used in real projects to keep the backend and frontend in sync.

# Comparison

There are other tools out there, but they usually require you to install them and use your computer's command line. My tool is different because it's

/r/Python
https://redd.it/1mo20uc
🚀 Introducing Beautypy – Open-Source Django UI Component Library

Hey Django devs! 👋

I’ve been working on an open-source project called Beautypy — a Django UI component library designed to help developers quickly add beautiful, reusable, and customizable UI elements without wasting hours on CSS and HTML.

# 📌 What is Beautypy?

Beautypy is:

A growing collection of ready-to-use Django template components
Styled with modern design principles out of the box (now using Bootstrap for compatibility)
Includes reusable template tags like:
{% Button label="Submit" type="submit" %} {% Alert type="success" message="Form submitted successfully!" %} {% ContactForm %}
Focused on developer speed and clean UI

# 💡 Why Use Beautypy?

Saves time – No need to hand-code repetitive HTML + CSS
Pre-styled components – Works instantly with Bootstrap’s responsive grid
Easier maintainability – Centralized templates make UI changes site-wide in seconds
Consistency – Every button, form, and alert matches your site’s style
Customizable – Override templates or styles to fit your brand easily
Zero JavaScript dependency for basics – Just Django templates and Bootstrap

# 📦 Installation

Install Beautypy from PyPI:

pip install beautypy


📄 Docs: [
https://pypi.org/project/beautypy/](https://pypi.org/project/beautypy/)

# 🌐 Live Demo

Want to see Beautypy in action?
🔗 Official Demo Website: [
beautypy.pythonanywhere.com](https://beautypy.pythonanywhere.com)

# 🤝 How You Can Help

Test it in

/r/django
https://redd.it/1mo3i47
Type hints for variable first mentions - yes/no/sometimes(when?)?

I'm new to python from a java background. Python is so easy when you are writing new code or are reading code you wrote in the last hour (e.g. during an interview).

Reading some code I wrote last week in a Colab notebook for a class notebook using some API that I'm learning (e.g. Word2Vec), it's not so easy. I don't know what operations I can perform on this variable I added but didn't name with enough information to trivially determine its type.

Java is so explicit with type declarations it makes you cry, but I'm seeing the dark side of dynamic typing.

One possible solution is to use type hints anywhere the type info is welcome (subjective I know). But is there any kind of best practice which maybe says that you should not do it to the point it just crowds your code and makes you hate yourself the way Java does?

(EDIT: yes I know modern java has var but the reality is it's in very few codebases because of version fatigue. Same reason we don't see much C23 or C++23)

/r/Python
https://redd.it/1mntk24
structlog-journald, attach extra info to jogs and filter logs by it

- What my project does: In a multi-tenant system, logs from various tenants are often mixed, making difficult to debug. This library bridges structlog and journald, to allow to attach extra info (like tenant ID) when writing logs. When we view logs via journalctl, we can filter by that tenant ID.
- Target audience: Python developers who often debug a system of many concurent operations running.
- Source code: https://github.com/hongquan/structlog-journald
- Manual: https://structlog-journald.readthedocs.io/en/latest/advanced.html

/r/Python
https://redd.it/1mo8ypj
Guidance on improving the reconstruction results of my VAE Project

Hi all! I was trying to build a VAE with an LSTM to reconstruct particle trajectories by basing off my model on the paper "Modeling Trajectories with Neural Ordinary Differential Equations". However, despite my loss plots showing a downward trend, my predictions are linear.

I have applied KL annealing and learning rate scheduler - and yet, the model doesn't seem to be learning the non-linear dynamics. The input features are x and z positions, velocity, acceleration, and displacement. I used a combination of ELBO and DCT for my reconstruction loss. The results were quite bad with MinMax scaling, so I switched to z-score normalization, which helped improve the scales. I used the Euler method with torchdiffeq.odeint.

Would it be possible for any of you to guide me on what I might be doing wrong? I’m happy to share my implementation if it helps. I appreciate and am grateful for any suggestions (and sorry about missing out on the labeling the axes - they are x and z)

https://preview.redd.it/veskdk7p7nif1.png?width=529&format=png&auto=webp&s=0938c4dd588961f94eba40a0e20d81008bc131f0

https://preview.redd.it/ddubae7p7nif1.png?width=529&format=png&auto=webp&s=15a24e197e6fd331d92175d1327fb2b482aaa2cc

/r/MachineLearning
https://redd.it/1moj422
Weird Flask bug: MySQL time not showing in HTML

Title:
Weird Flask/MySQL bug: start_time won’t show in <input type="time">, but end_time does

Body:
I’m running into a strange issue in my Flask app with MySQL TIME columns.

Table snippet:

mysql> desc tests;
+-------------+-------+
| Field | Type |
+-------------+-------+
| starttime | time |
| end
time | time |
+-------------+-------+


Python code:

if testData:
print("DEBUG-----------------------", test
Data9)
print("DEBUG-----------------------", testData[10])
test
Data = {
'testid': testData0,
'testname': testData3,
'teststarttime': testData[9],
'test
endtime': testData10
}


Debug output:

DEBUG----------------------- 8:30:00
DEBUG----------------------- 12:30:00


/r/flask
https://redd.it/1mobprf
Bug in Python 3.13 wave module? getnchannels() error on cleanup.

Hey everyone,

I ran into a really strange error today while working with the built-in wave module in Python 3.13 and thought I'd share in case anyone else encounters this or has some insight.

I was trying to do something very basic: generate a simple sine wave and save it as a WAV file using the standard library. My code was the textbook example, using wave.open() inside a with statement to handle the file.

The weird part is that my script runs, but then throws this error right at the end, seemingly during the internal cleanup process after the with block closes the file:

wave.Error: # channels not specified

My code to set the channels (wav_file.setnchannels(1)) is definitely there and in the correct order before writing the frames, so it doesn't seem to be a problem with my script's logic. It feels like the library is failing internally when the file object is being destroyed.

Has anyone else seen this with Python 3.13? Is this a known bug in the new version?

Thanks!

/r/Python
https://redd.it/1modnfw
Does creating a new CMS system based on django make sense?

Hi everyone, I have used wordpress for long time in my career, but security point of view always eats my brain. with lot of plugins comes lots of security holes.

Since django being best in industry for security. can make sense to bring it as alternative to wordpress.

Need your perspective.

/r/djangolearning
https://redd.it/1mn2hqt
I created a wrapper for google drive, google calendars, google tasks and gmail

GitHub: https://github.com/dsmolla/google-api-client-wrapper

PyPI: https://pypi.org/project/google-api-client-wrapper/

What my project does:

Hey, I made a simple, and easy to use API wrapper for some of Google's services. I'm working on a project where I need to use google's apis and I ended up building this wrapper around it and wanted to share it here in case anyone is in the same boat and don't want to spend time trying to figure out the official API.

Target Audience

This is for developers who are working on a project that uses Google's APIs and are looking for easy to understand wrappers

Comparison

Data Models like EmailMessage, Event, DriveFolder, Task vs. Raw API responses
Helper Methods
Built-in support for multiple accounts
Query builders vs. Manually writing raw queries
Clear documentation and Easy to navigate
Similar patterns in all services


I will add async support soon especially for batch operations

/r/Python
https://redd.it/1movsu6