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
Saleor vs Oscar Ecommerce

Hi,

I am currently assessing refactoring a custom lightweight marketplace app built with Nuxt to a proper backend (read Django) to address some of the core pain points usually faced with JS applications (incompatibility between packages, lack of included "batteries", time intensive development etc.)
Saleor and Oscar are the most popular options in the Django ecosystem and I was wondering if people had any experience using one or the other? And what was the overall guideline regarding their usage?
Cheers

/r/django
https://redd.it/1ekklgc
AI research in medicine R

I'm interested in AI in medicine and want to dive deeper into AI research in this field. Are there any platforms, researchers, or YouTubers you'd recommend who explore this topic in depth, especially those who discuss and analyze research papers?

/r/MachineLearning
https://redd.it/1ekjkw1
PyAwaitable: An ideal way to define asynchronous logic in C extensions

I've put this idea through a number of discussions (namely, this one and this one) about adding capability to the C API directly to call asynchronous Python code, and I'm officially releasing my reference implementation as a library, per request from the core devs!

## What My Project Does

Put simply, PyAwaitable lets you write and run asynchronous Python functions, from pure C code!

## Target Audience

This project is intended towards those who care a lot about Python performance, or develop C extensions.

## Comparison

As of writing, there are no other libraries that do this. The answer for asynchronous C code has always been: you can't (without a lot of effort, at least -- too much effort for it to be effective).

Most people will defer async logic to a non-async function (think loop.run_until_complete, and friends), and then call that from C.

## Installation

I've developed a stable version, which you can either install off PyPI, or vendor into your project off the releases page: https://github.com/ZeroIntensity/pyawaitable

Feedback, positive or negative, would be appreciated!



/r/Python
https://redd.it/1ekpk4c
Node Demonstrator - tool to create graphs and show standard algorithms

What my project does

I've been working on a module (largely for myself to use in school) to demonstrate to students, and then for themselves to be able to explore, how graph algorithms work step by step.

It's got to a point where I'm happy enough to share with people, is anyone's interested... I've published it on PyPI here (and it's on GitHub, naturally) so feel free to check it out.

Target Audience

Honestly, this is just a toy project aimed at educational use by A-level teachers (UK), and students

Comparison

It was as much about me building the project and proving that I could use Tkinter (well, ultimately CustomTkinter) and particularly the Canvas to create a drag/drop area for the graph. Haven't really looked at alternatives.

/r/Python
https://redd.it/1ekyqvz
I made a quick-start template for Flask apps called Create Flask App

Hey everyone!

I made this project called Create Flask App to help you quickly set up and scale your Flask applications. It comes with user authentication (register, login, logout), profile management, and a basic admin page, all styled with Bootstrap 5.3.3. By default, it uses SQLite3, but you can easily configure it to use your preferred database.

Check it out, give it a star if you like it, and let me know what features you'd love to see next and/or feel free to contribute. Your feedback and suggestions would be awesome!

I will keep working on it, adding new features and improvements.



👉 Create Flask App on GitHub

Thanks for checking it out!

/r/flask
https://redd.it/1ekjvap
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/1el3al8
Tool: quickly find the strptime/strftime format code for your date

I appreciate the various strftime cheat sheets floating around online but I've been wanting a tool that'll do the datetime format string construction automatically for a given date/datetime.

So I made a tool to do this: https://pym.dev/strptime

It has a few not-so-obvious features as well. More details in this post, if you're curious.

/r/Python
https://redd.it/1ekv35s
I am getting an error in forms.py specifically the function in functions.py. Put simply the login function form query for the username and email both return None. How do I fix the code?

I am getting an error that no matter how hard I try I can’t solve it. I have located what is causing the error. It is caused by the code in forms.py specifically the function in functions.py. For some reason the query’s are returning None even though in the /register route I added the username and email and password to the db. I am using the same email for the username form and email form before adding them to the db but I don’t think that should make a difference. How do I fix the code?





I think it was working before. Also I plan to pytest the code where the username form and email form are equal then adding them to the db but I decided to post this in case that doesn’t make a difference.

Also I was looking in dbeaver, a database manager, and the columns username and email exists. So I am very confused. I didn’t include all the function but like stated I included the function that is causing the error. Also in the /register route just assume for simplicity I redirected to the /login route instead of where I redirect.





auth/models.py

https://pastebin.com/K5nE4yVr



auth/routes.py

https://pastebin.com/j0fEg9Hy





auth/functions.py

https://pastebin.com/CnCkkLGT



auth/forms.py

https://pastebin.com/DLBr86uN



Here is the output.

https://imgur.com/a/Pdg7gEk

/r/flask
https://redd.it/1el5vba
Are there patterns for receiveing emails within app?

I have no intention of sending emails on my own, I use SES for that, but sometimes it would be convenient if my app could receive emails, e.g. users could reply to messages by replying to email instead of going to app to write message, etc.

So, are there any ways to implement receiving emails using pure python in my flask app? Maybe some type of webhook solution?

I don't want to deal with Postfix or the likes, nor do i want to integrate with an external email provider, so with these reqiurements maybe the answer is no, not possible.

/r/flask
https://redd.it/1eknuqj
Inventory Management for an Antiques Company with Django and Shopify Integration

Hey everyone!

I'm thrilled to share my experience with my 5th Django project for a real client. This time, I worked with an antiques company to build a robust inventory management system integrated with Shopify.

The project revolved around using webhooks from Shopify to keep the inventory up-to-date and QR codes for quick verification of product locations in the warehouse. One of the key challenges was managing products without bin locations. Initially, products without a specified bin location caused inventory discrepancies. To address this, I adjusted the data queries to handle blank spaces and cleaned the data when importing from CSVs to ensure accurate registration of all products.

Another challenge was seamlessly integrating with Shopify's API and implementing QR code functionality. Shopify's API was quite flexible, which made the integration smoother. I used a Python library to generate and read QR codes, allowing for fast and accurate product verification. This significantly reduced human errors and saved a lot of time.

The app's interface was optimized for use on tablets, enabling employees to move freely around the warehouse while checking inventory. This mobility greatly enhanced the efficiency and accuracy of inventory management.

Working on this real project for a real client was incredibly rewarding. Each project

/r/django
https://redd.it/1ekxpcl
I wrote this simple script to analyze python files.

### What my project does

It's a simple utility script which allows you to analyze your python file. It provides simple detailed insights into the structure and composition of Python code, including information about functions, classes, imports, variables, and function calls.

### Target Audience

Honestly, this is just a fun project

### Comparison

N/A


#### Link to the project

/r/Python
https://redd.it/1el7xyf
How would you implement a "10% off for first-time customers" coupon?

I need to create a coupon that shouldn't be able to be reused.

I've thought of cookies, IP, emails/authentication, fingerprinting, etc., but nothing is really bulletproof.

How would you approach this?

Edit: This is for an ecommerce platform, so assume no user database since guest checkouts are a must.

/r/django
https://redd.it/1ekxcom
Database suggestion

For a machine learning project I am looking into different database backends to store my data. The data is a sparse time series matrix (example at the end). Also, the sensor names are dynamic and could change in the future

Further, FastAPI is used for the backend.

What database like TimescaleDB or InfluxDB do you have experience with and which one do you recommend?



data = {
    "entry_id": "61da2b48-7526-418b-b4d2-0c87a9fb7237",
    "data": {
        "2024-08-01 00:00:00": {
            "sensor_1": 0.0,
            "sensor_2": 10.0
        },
        "2024-08-01 01:00:00": {
            "sensor_1": 1.0
        },
        "2024-08-01 02:00:00": {
            "sensor_1": 1.0,
            "sensor_2": 11.0,
            "sensor_3": 30.0
     

/r/Python
https://redd.it/1elctrz
A Simple sync FastAPI Boilerplate with minimal overhead

Why? To keep myself building the same thing again and again. Lot of great boilerplate projects already out there but many a times they have certain extra features, atleast for me, or use some other 3rd party packages which are not needed by all the projects.

If it helps anyone else too to get the ground running - https://github.com/keshavagrawal89/fastapi\_boilerplate
Quick README: https://github.com/keshavagrawal89/fastapi\_boilerplate/blob/main/README.md

There are so many things which could have been added here but were intentionally left out because sometimes adding features to simple boilerplate kind of defeats the concept of boilerplate. If anyone wants to contribute or fork it out to add any required features - they are welcome to do so.

Although nginx, celery scope is also added in docker-compose but not necessary.
Supabase is used for authentication and Postgres as Database. Should be enough for most of the applications.

/r/Python
https://redd.it/1eldpb3
New Tool Easily Convert YouTube Videos to MP!

Hey everyone!

I’m super excited to share a new tool I’ve been working on: YouTube to MP Converter! This little app makes it super easy to turn your favorite YouTube videos into MP3 files. Whether you want to jam out to your favorite songs offline or save some educational videos as files, this tool has you covered.

# What My Project Does?

The YouTube to MP Converter is a simple, user-friendly application that allows you to convert YouTube videos into high-quality MP files. It supports various MP formats and lets you choose where to save the files on your computer. Plus, it comes with some cool customization options to tweak the user interface according to your preferences.

# Target Audience

This tool is perfect for anyone who:

Loves listening to music or podcasts from YouTube offline.
Wants an easy way to save educational videos as files.
Prefers a customizable user interface to suit their style.
Is looking for a straightforward, reliable way to convert YouTube videos to MP3.

# Comparison

Compared to other YouTube to MP converters, my tool stands out because of its:

Customization Options: Personalize the user interface to make the app look just how you like it.
Simplicity and Ease of Use: The intuitive

/r/Python
https://redd.it/1elh7nr
[P] Grounded SAM 2: Ground and Track Anything

https://preview.redd.it/13854j03q2hd1.jpg?width=1280&format=pjpg&auto=webp&s=0735848ae40c2591111fa4ed91d2c28ea829c0ac

With the release of SAM 2, we have taken the opportunity to update our Grounded SAM algorithm. The biggest improvement in SAM 2 compared to SAM is the expansion of its segmentation capabilities to video, allowing users to interactively segment any object and track it in video. However, the main issue with SAM 2 is that the segmented and tracked objects do not contain semantic information. To address this, we have continued the approach of Grounded SAM by **incorporating an open-set detection model**, Grounding DINO. This enables us to extend 2D open-set detection to video object segmentation and tracking.

We have release our code in

[https://github.com/IDEA-Research/Grounded-SAM-2](https://github.com/IDEA-Research/Grounded-SAM-2)

with **very easy implementations**, which is convenient for users.

Project Highlights:

In this repo, we've supported the following demo with **simple implementations**:

* **Ground and Segment Anything** with Grounding DINO, Grounding DINO 1.5 & 1.6 and SAM 2
* **Ground and Track Anything** with Grounding DINO, Grounding DINO 1.5 & 1.6 and SAM 2
* **Detect, Segment and Track Visualization** based on the powerful [https://github.com/roboflow/supervision](https://github.com/roboflow/supervision) library.

And we will continue update our code to make it easier for users.

/r/MachineLearning
https://redd.it/1elmxnq
What do you guys think of how I'm handling this endpoint?

I'm wondering if maybe I can handle this differently, it really seems very repetitive.

Also what else can I add to the custom exceptions, right now they are just helping me handle separate errors appropriately, but I think I'm missing a way of getting more out of them.
Would adding the status code to them be a good idea?

I also read something about f strings when using logging and how it can impact the log message. The proper way is using this `logger.info("Text %s", data)` right?

try:
    response, status = auth_service.login(data)
    logger.info(f"Login Successful: {data['email']}")
    create_audit_log(data["user_id"], "Login", "Login Attempt Successful")
    return jsonify(response), status

except InvalidCredentials as e:
    logger.warning(f"Login Attempt Failed: {data['email']} - Invalid Credentials")
create_audit_log(data["user_id"], "Login", "Login Attempt Failed: Invalid Credentials")
    abort(401, description="Email Or Password Is Incorrect")

except DatabaseQueryError as e:
    logger.error(f"Login Attempt Failed: {data['email']} - {traceback.format_exc()}")
 

/r/flask
https://redd.it/1elnply
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/1elxc34