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
Text to Video Model Implementation Step by Step

# What My Project Does

I've been working on a text-to-video model from scratch using PyTorch and wanted to share it with the community! This project is designed for those interested in diffusion models.

# Target audience

For students and researchers exploring generative AI.

# Comparison

While not aiming for state of the art results, this serves as a great way to understand the fundamentals of text-to-video models.

# GitHub

Code, documentation, and example can all be found on GitHub:

https://github.com/FareedKhan-dev/text2video-from-scratch

/r/Python
https://redd.it/1iggbcu
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/1ih454j
[D] BERT Embeddings using HuggingFace question(s)

I am trying to find BERT embeddings of disassembled files with opcodes. Example of a disassembled file:
```
add
move
sub
... (and so on)
```

The file will contain several lines of opcodes. My goal is to find a embedding vector that represents the WHOLE file (for downstream tasks such as classification/clustering).

With BERT, there are two main things: the tokenizer and the actual BERT model. I am confused whether the context size of 512 is for the tokenizer or the actual model. The reason I am asking is, can I feed all the opcodes to the tokenizer (which could be thousands of opcodes), THEN separate them in chunks (with some overlap if needed), and then feed each chunk to the BERT model to find that chunk's embedding*? Or should I first split the opcodes into chunks THEN tokenize them?

This is the code I have so far:
```py
def tokenize_and_chunk(opcodes, tokenizer, max_length=512, overlap_percent=0.1):
"""
Tokenize all opcodes into subwords first, then split into chunks with overlap

Args:
opcodes (list): List of opcode strings
tokenizer: Hugging Face tokenizer


/r/MachineLearning
https://redd.it/1ih2ywl
From Django to FastAPI: Building a Warehouse Bin Location with Raspberry Pi / Shopify

Hey Reddit! I recently developed a warehouse management bin location tool for a company and wanted to share the process. The goal was simple: create a system where warehouse staff could scan a product’s SKU and instantly see its location, product details, and an image. But behind that simplicity was a fun technical journey.

I started with Django because it’s great for rapid prototyping. However, as the project evolved, I realized we needed something more lightweight for handling real-time API calls to Shopify. That’s when I switched to FastAPI. The async capabilities made a huge difference when querying Shopify’s GraphQL API, especially during peak hours. Plus, the automatic OpenAPI docs were a bonus for testing and debugging.

https://preview.redd.it/n2jvnf2yszge1.png?width=1918&format=png&auto=webp&s=5ffadee065996c307a9b8ec4e15cfdb06aab95c5

The hardware setup is where things got interesting. The system runs on a Raspberry Pi 4 connected to a 7-inch touchscreen and a USB numeric keypad (no full keyboard needed—just quick SKU entry). The Pi acts as both server and client, hosting a FastAPI backend and serving a minimalist Vue.js frontend. The interface is optimized for speed: workers scan a SKU, and the screen immediately displays the bin location and product image.

https://preview.redd.it/tviudj5sszge1.jpg?width=4032&format=pjpg&auto=webp&s=94b6c9d7ce130f57a4a6582198f8f6e263d8a35c

One big challenge was handling Shopify’s metafields. Products and variants store their

/r/django
https://redd.it/1ih0z8n
pytest-mock : Mocking in pytest - Test & Code

https://testandcode.com/episodes/pytest-mock

pytest-mock is currently the #3 pytest plugin.

- Why the pytest-mock plugin is awesome
- What is mocking, patching, and monkey patching
- What, if any, is the difference between mock, fake, spy, stub.
- Why we might need these in testing
- Some history of mock in Python and how mock became unittest.mock
- Using mocker.patch, mocker.spy, and mocker.stub
- Why pytest-mock is awesome and why you might want to use it over straight unittest.mock

/r/Python
https://redd.it/1ih5238
Introducing ElixirDB - Simplified SQLAlchemy Engine management - with extras.

Hello,

I'm building libraries (the previous one was similar to this) to get criticism to improve my code and logic because even as a professional developer, I've never had a senior engineer/dev. I took in some feedback from the previous library to make something potentially useful this time.

This is a pre-release, so there are some things I'm ironing out. Let me know what you guys think. Always looking for criticism.

Github: https://github.com/hotnsoursoup/elixirdb

Pypi: https://pypi.org/project/elixirdb/

What My Project Does:
ElixirDB simplifies interaction with SQLAlchemy, providing streamlined database operations, enhanced configuration management, and improved developer experience.

Target Audience:
Anyone that wants to stand up a quick database connection or may want the flexibility of switching engines from a central class. Perhaps you don't like the way sqlalchemy binds engines.

Comparison:
Not sure, I couldn't really find anything out there. I did try googling quite a bit and even asked 3 different AI models to find me one, but it didn't come up with anything. I'd love for any references.

# Key Features (Reduced, more on github/pypi)

* **Automatic loading:** Define an **elixir**.yaml file in your project, and it will be automatically loaded into the ElixirDB instance.
* **Pydantic Integration:** Define and validate database configurations using Pydantic models
* **Multi-Engine Support:** Seamlessly manage multiple database engines through

/r/Python
https://redd.it/1ih6bo6
R reasoning models are indecisive parrots

R1 , o1, and gemini 2.0 flash were put to the test on 27 different puzzles.

the models still default to familiar solutions rather than adapting to new contexts - they even impose nonexistent constraints, waste tokens, and arrive at the wrong answer. Examples:

Example 1

Question: A group of four people needs to cross a bridge at night. The bridge is very old and rickety. They have only one torch, and because it's nighttime, the torch is necessary to cross the bridge. Each person walks at a different speed:A takes 1 minute to cross,B takes 2 minutes,C takes 5 minutes, andD takes 10 minutes.What is the fastest time they can all get across the bridge?

Answer: 10 minutes, the speed of the slowest person as they cross the bridge together.

DeekSeek-R1: "...First, the constraints: the bridge can only hold two people at a time, and the torch is needed each time someone crosses. So, if two people go over together, one has to come back with the torch."

Example 2

Question: Suppose you're on a game show,

/r/MachineLearning
https://redd.it/1iheszs
Kindly give me an advice on seeking a job.

Hi,

I started learning coding on my own and worked as a freelancer developing static websites. Later, I picked up Python-Django and took a job as a Junior Software Developer on April 15, 2024.

On August 19, both of my parents were involved in a serious accident, and my father had to undergo multiple surgeries, with his last operation taking place on December 31. Since the company did not offer me a work-from-home option despite my repeated requests, they closed my file.

Now that I have fulfilled my responsibilities in taking care of my parents, I am actively looking for a job, but finding one has been challenging.

The skills I have developed include Python, Django Framework, REST APIs, SQL, MySQL, AWS, HTML, CSS, and Git.

Please provide me with advice on how to proceed.

/r/django
https://redd.it/1ihdx90
Optimizing data storage in the database

Hi All!


My Django apps pulls data from an external API and stores it in the app database. The data changes over time (as it can be updated on the platform I am pulling from) but for various reasons let's assume that I have to retain my own "synced" copy.

What is the best practice to compare the data I got from the API to the one that I have saved? is there a package that helps do that optimally? I have written some code (quick and dirty) that does create or update, but I feel it is not very efficient or optimal.


Will appreciate any advice.




/r/django
https://redd.it/1ihiz3m
A really specific situation with a page redirecting to itself in another language.

My website is available in english and pt-br, for that, I'm using the django.template.context_processors.i18ndjango.

My settings look like this:

LANGUAGE_CODE = 'en-us'
LANGUAGES = [ ('en', 'English'), ('pt-br', 'Português'), ]
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True
USE_TZ = True
LOCALE_PATHS = [BASE_DIR / 'locale']

Everything works correctly, but I need the option for the user to switch languages and stay on the same page.

What I implemented is this form:
<form action="{% url 'set_language' %}" method="post" class="sub-menu-content flow">

{% csrf_token %}

<fieldset onchange="this.form.submit()">

<label for="en-language-input">English</label>

<input type="radio" id="en-language-input" name="language" value="en" {% if LANGUAGE_CODE == 'en' %}checked{% endif %}>



<label for="pt-br-language-input">Português Brasileiro</label>

<input type="radio" id="pt-br-language-input" name="language" value="pt-br" {% if LANGUAGE_CODE == 'pt-br' %}checked{% endif %}>

</fieldset>

</form>

It also works fine, except when you access the website with an /en/ language prefix.
I tested it with brazilians and non-brazilians,

\- if you open the website without a language prefix, it will switch to default (en, or pt-br depending where you live) and the translation switch will work.
\- if you open the website with an /pt-br/ prefix, it will also work
\- if

/r/django
https://redd.it/1iheltr
D Why mamba disappeared?

I remember seeing mamba when it first came out and there was alot of hype around it because it was cheaper to compute than transformers and better performance

So why it disappeared like that ???

/r/MachineLearning
https://redd.it/1ihen9v
Tach - A Python tool to enforce dependencies

Source: https://github.com/gauge-sh/tach

Python allows you to import and use anything, anywhere. Over time, this results in modules that were intended to be separate getting tightly coupled together, and domain boundaries breaking down.

We experienced this first-hand at a unicorn startup, where the entire engineering team paused development for over a year in an attempt to split up tightly coupled packages into independent microservices. This ultimately failed, and resulted in the CTO getting fired.

This problem occurs because:

It's much easier to add to an existing package rather than create a new one
Junior devs have a limited understanding of the existing architecture
External pressure leading to shortcuts and overlooking best practices

Attempts we've seen to fix this problem always came up short. A patchwork of solutions would attempt to solve this from different angles, such as developer education, CODEOWNERs, standard guides, refactors, and more. However, none of these addressed the root cause.

# What My Project Does

With [Tach](
https://github.com/gauge-sh/tach), you can:

1. Declare your modules ([`tach mod`](
https://docs.gauge.sh/usage/commands#tach-mod))
2. Automatically declare dependencies ([`tach sync`](
https://docs.gauge.sh/usage/commands#tach-sync))
3. Enforce those dependencies ([`tach check`](
https://docs.gauge.sh/usage/commands#tach-check))
4. Visualize those dependencies ([`tach show`](
https://docs.gauge.sh/usage/commands#tach-show) and [`tach report`](https://docs.gauge.sh/usage/commands#tach-report))

You can also enforce a [public interface](
https://docs.gauge.sh/usage/interfaces) for each module, and [deprecate dependencies](https://docs.gauge.sh/usage/deprecate) over time.


# Target Audience

Developers working on large Python monoliths

# Comparison



/r/Python
https://redd.it/1ihl5fy
Django Template LSP – For those not using PyCharm

For everyone not using PyCharm, I’ve built an LSP server for Django templates! After using it for a few months, I’m happy to release v1.0.0, and I think it works pretty well.

🔹 Autocomplete for {% load %}, {% static %}, {% url %}, custom tags/filters and context variables.
🔹 Go-to definition for templates, views, and context variables.
🔹 Hover docs for {% url %} and template tags/filters.
🔹 Works with Neovim, Helix, VS Code and others that support lsp's.

Check it out here: https://github.com/fourdigits/django-template-lsp Any feedback or suggestions? Open an issue on GitHub!

/r/django
https://redd.it/1igy8y3
Need Suggestions

I have created a django-react app where user can read novels, bookmark etc(still not finished to me), already on a hackathon where developing a web app using django. Now my question is that To apply as a backend role what projects do I need more? Or is this enough?
What Do i need to showcase?

/r/djangolearning
https://redd.it/1igtt3x
D Warning about Vultr Coupons

Heads up for anyone thinking about using Vultr with promotional credits—your experience might not be as smooth as expected.

I had $300 in promotional credits plus $5 I personally deposited (which I assumed was for identity verification), but I wasn’t able to use any of it.

First, they asked me to verify my profile, which I did. Then, out of nowhere, they demanded that I deposit another $50 just to access the funds I already had—effectively making my $300 in credits unusable. This requirement isn’t mentioned upfront, which is frustrating. If you're already committed to using Vultr, this might not be an issue, but if you just want to test the service, it feels weird.

To make things worse, you won’t necessarily be able to deploy your instances instantly. In many cases, you’ll need to open a support ticket and manually request access.

Their promotional credits and deposit policies are misleading, and once your money is in, you may not get it back. They don’t issue refunds. I couldn’t find any refund button on their website, and when I tried to request a refund through PayPal, they suspended my account immediately.

/r/MachineLearning
https://redd.it/1ihpz4k
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/1ihwk3k
Corey Schafer's Django Blog Tutorial

Hey guys! I was just reaching out to see if anyone else has completed finishing this series. I'm looking to get some help because on video 13, right before deploying, I had issues setting up my aws S3. I ran a test script to see if sending a file locally would work and it worked. However, if I run my blog locally and update a profile picture, a new image would be added in my local media folder but not in S3. I made sure to set up my environment variables correctly and to set up my aws stuff according to the video. Anything helps! I also know this is very vague so please feel free to ask what i've tried so far. Thank you!

/r/django
https://redd.it/1ihw1ga
Which hosting for a simple application?

I'm looking for hosting for an amateur project developed with Python3 + Flask. It's a simple application that will generate almost no traffic for most of the year, but on specific dates, it will be used by up to a few hundred people to access a page with data updated via WebSocket.


So, I'm looking for a provider that offers scalability when needed. I've already used AWS, but it might be "too much" for my needs.

/r/flask
https://redd.it/1ihhkgq
Are all inputs for "filter" method safe from sql injection?

Hi.
i'm making a simple online store app for learning purposes. For item properties, i've used a json field to store properties like size, color and .... . I've considered using database relations but i figured this would be simpler. the item properties are stored in db like this: {"size": "XL", "color": "red"}
I'm implementing a simple search functionality and since there are many properties, i'm wondering if it's safe to get property names from users.

was using json field a bad choice? what would a be good replacement?

this is my code for search view:

def search_items(request):
    q = request.GET.get('q')
    filters = request.GET.get('filters')
    items = Item.objects.filter(name__icontains=q)
    if filters:
        options = {}
        filters_list = json.loads(filters)
        for f in filters_list:
            options[f"properties__{f[0]}__icontains"] = f[1]
        items = items.filter(**options)


    return

/r/djangolearning
https://redd.it/1icran1