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
Django Background task library comparison

How does the following Background task queue library compare? I am looking at background/asynchronous task queue, orchestration of tasks ( kind of DAG, but not too complicated) and scheduling functionality. Monitoring would be nice, but not at the expense of running another service.

1. Celery based task queue with Flower monitoring, or Django built-in
2. django-q2 - It doesn't require another broker and uses django-ORM.
3. prefect - Originally written as ETL platform. But, it seems to work just fine for background tasks as well.
4. DEP 0014 proposed as one of the battery in Django, not released yet. Use django-tasks instead in the meanwhile
5. dramatiq

Does anyone has experience, It would be quite a task to try these out and write a Pro/Con so seeking community experience.

/r/django
https://redd.it/1ivu6ep
Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

/r/Python
https://redd.it/1ivwtvk
I wrote a faster alternative to autoenv

I got issues with autoenv that was too slow on my system so I wrote autoenv-rs

# What My Project Does

It works mostly like autoenv: overrides cd so that scripts stored in .env files are automatically sourced when moving through the file tree.

While it's a flexible tool, I mainly use it to activate and deactivate python virtualenvs.

# Target Audience

For bash shell users only.
If autoenv is too slow and you've been using it without configuration, you might like this.
It should run fine in your dev environement but don't use it in a production environment, it is not safe.

# Comparison

- faster than autoenv
- drop in replacement as long as you did change autoenv configuration
- adds cd -v argument to show which environments are sourced
- fixes some autoenv issues when sourcing environments of parent folders
- only supports bash, while autoenv supports multiple shells
- no authorization is asked to source .env files contrary to autoenv (might be dangerous)

/r/Python
https://redd.it/1iw14i7
Very small web server: SQLite or PostgreSQL?

Hi devs! :) I am trying to build a simple license server in Django with 2 goals: 1. create and manage license keys, 2. verify license keys of client apps. The project currently has 0 customers and will have max 50-100 customers (client apps) needing verification in \~2 years. The client app will verify license at a few points during its run (start of client app, random check or maybe when user will use an expensive feature like object detection task in my client app). My biggest challenge is not over-engineering things to keep it light, simple but production-ready (meaning actually using the system to verify user license info with basic security in mind).

In this case, would you recommend using SQLite or PostgreSQL? What would you say are the pros and cons?

More context: I am a beginner at Django. I have several years of data science experience in python. I have the client built in PySide6. I am planning to host the server on an affordable place. This is a fun project I do on the side, not my main job.

/r/django
https://redd.it/1ivvs5k
I made a Python app that turns your Figma design into code

🔗 Link — https://github.com/axorax/tkforge

# What My Project Does

TkForge is a Python app that allows you to turn your Figma design into Python tkinter code. So, you can make a GUI design in Figma and use specific names like "textbox", "circle", "image" and more for interactable elements then use TkForge to get the code for a fully functional working GUI app from your design.

And it's free, open-source and regularly maintained!

# Target Audience

TkForge is made for anyone who wants to make a GUI with Python easily and efficiently. It's fast and you can make some really complex and beautiful GUI's with it.

# Comparison

There's another project similar to TkForge called Tkinter Designer. Personally without being biased, I think TkForge is better. TkForge supports everything Tkinter Designer does and more. TkForge generates better code, supports more elements, allows you to add placeholder text (which you can't by default in tkinter), automatically sets foreground color and a lot more! Placeholder text and foreground color generation is a bit buggy though. I use TkForge for most of my tkinter projects. You can get help in the Discord server.

# Updates

I updated the app to support multiple frames, fixed a lot of previous bugs and added checks

/r/Python
https://redd.it/1iw3lnu
Are DataLemur Python Problems Enough for Data Science Interviews?

Hey everyone,

I recently started using DataLemur to learn SQL, and I have to say, it’s a great place for practicing! But I have a question regarding their Python problems—are they enough to prepare for a Data Science interview?

Or are there other good platforms where I can practice Python specifically for Data Science?

P.S. Please don’t mention LeetCode 😅

/r/Python
https://redd.it/1iw6ks8
Facing problem with sending JWT cookie to frontend

So, I have this login view,

     


@apiview(['POST'])
def login(request):
    username = request.data.get('username')
    password = request.data.get('password')


    user = authenticate(username=username, password=password)


    if user is not None:
        refresh = RefreshToken.for
user(user)


        response = Response({
            "user": {
                "id": user.id,
                "username": user.username,
                "email": user.email,
                "name": user.name  # Assuming your User model has 'name'
            },
            "success":

/r/django
https://redd.it/1iw7t5y
Learn concepts and ideas easily with my new web app

Hi guys,


Feel free to take a look at my new web app that is designed to help people quickly and easily understand concepts or terms that they hear.


Check it out at https://teachmelikefive.com/

thanks

/r/flask
https://redd.it/1iw8gds
I Built an Open-Source Algo Trading Framework for Instant Backtests & Live Deployment

Github : https://github.com/himanshu2406/Algo.Py

# What My Project Does

So I've been working on a framework made in Python that makes live trading incredibly easy, and even almost no-code !

It seamlessly integrates with any preset backtesting strategy, allowing you to take them straight to live trading with minimal effort.

Dashboard Overview : https://youtu.be/OmlaBnGcUi4?si=e1aizaIaYpRNMHFd

One-Click Backtest Deployment Overview : https://youtu.be/T\_otTHdLCCY?si=A7ujRzV6I5ESfgEQ

It's still in very early beta, but I’ve packed in as many functional features as possible, including:

# Key Features

Intuitive Dashboard
Easily backtest, view results, save and deploy in a single click.
Auto-Detects Your Strategy – If your function generates valid entry/exit signals, the framework will automatically detect and integrate it.
Scheduler for Automation – Run your entire pipeline at custom fixed intervals or specific times
Custom Data Layer (Finstore):
Stores and streams data using a Parquet-based data lake, making it much faster than traditional databases.
Multi-Broker Support – Execute across multiple brokers with real-time debug logs via Telegram.
End-to-End Pipelines – Effortlessly fetch, store, and stream data for crypto, equities, and more.
Multi-Asset Backtests :
Backtest a strategy across an entire market across hundreds of symbols and thousands of data

/r/Python
https://redd.it/1iwccvr
The pitfalls of benchmarking your package like numpy does

Recently I decided to use [asv (Airspeed Velocity)](https://asv.readthedocs.io/en/latest/) for benchmarking performance of [django-components](https://django-components.github.io/django-components) (we want to be faster than Django templates). asv is used by numpy, scipy, or astropy.

With asv, we are able benchmark render time and memory consumption.

There was a lot of pitfalls and even a couple of bugs I had to fix to get things working. I've documented them all in [this PR](https://github.com/django-components/django-components/pull/999) (also contains screenshots).

The PR covers these use cases:

* Performance report on pull requests.
* Benchmarking the package across releases.
* Displaying performance results on a website.

I'm not big on writing blogs and tutorials (at least not by myself), so I hope to share resources at least this way. The PR is still very informative if you want to introduce benchmarking to your project.

If you find this useful and you'd want to make this into a more human-digestible format, send me a message!

/r/Python
https://redd.it/1iw96ed
Made a Python library for simulating the combined effect of different time-series patterns

GitHub: https://github.com/TimoKats/pylan

PyPi: https://pypi.org/project/pylan-lib/

# What My Project Does

Python library that can be used to simulate the combined effect of financial patterns (e.g. salary, inflation, investment gains, etc) over time so you can plan your finances better.

# Target Audience

Personal usage for now.

# Comparison

\- SaaS financial planning tools (like ProjectionLab) work through a webUI, whereas here you have access to all the Python magic in the same place as you do your simulation.

\- Excel....

\- Write your own code for this is not super difficult, but this library does provide a good framework of dealing with various schedule types (some of which cron doesn't support) to get to your analysis more quickly.

/r/Python
https://redd.it/1iwk95c
Flask partitioned cookies problems

I am working on a flask backend and I have a problem with the cookies, specifically with the partitioned cookies.When I config the session cookie here:

def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'chamba machamba'
# Configure session cookies for local development
# Make sure that domains are the same (for example localhost)
app.config['SESSION_COOKIE_SAMESITE'] = None # Allow cross-site cookies
app.config['SESSION_COOKIE_SECURE'] = True
app.config['SESSION_COOKIE_PARTITIONED'] = True
app.config.update()

I get the error:

`Cookie “session” has been rejected because it is foreign and does not have the “Partitioned“ attribute`

So I did a little digging and tried to add the cookies when I log in / sign up. So I deleted this part and added this to my sign up and log in:

response = make_response(jsonify({'message': 'User created successfully'}))

response.headers.add('session',

/r/flask
https://redd.it/1iw8vkb
Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

/r/Python
https://redd.it/1iwogfe
Django app deletion from a django project

I need to remove a Django app from my project. This app has ForeignKey relationships with models in other apps. Several migrations involving this app have already been applied to the database. I'm concerned about data loss in the related models of other apps if I simply delete the app.
- What's the safest and most recommended way to remove an app, considering the existing ForeignKey relationships and migrations?
- What are the best practices, and what should I avoid doing to prevent data corruption or loss?
- Is it possible to keep the old data of deleted models?

---


I have tried these steps but face some dependency issues which need manual intervention. I want to know the recommended ways.

1. Delete dependent migrations for dependent_app
`rm -rf dependent_app/migrations`

2. Make necessary changes for the models of dependent_app
3. Recreate migrations
`python manage.py makemigrations dependent_app`

4. Delete all migrations for the my_app
`rm -rf my_app/migrations`


5. Apply fresh migrations
`python manage.py migrate --fake`


6. Remove imports, urls and other associations

7. Remove from INSTALLED_APPS

```
INSTALLED_APPS = [
#Other apps
'my_app', # Remove this line
]
```


/r/djangolearning
https://redd.it/1iw2ned
D.O. litespeed droplet with django

Hello I just fired up a droplet with openlitespeed and django. So it comes preinstalled with an app and a project right? So I put in my model into models.py and receive this error when trying to migrate:
from django.core.management import execute_from_command_line

ModuleNotFoundError: No module named 'django'



The above exception was the direct cause of the following exception:



Traceback (most recent call last):

File "/usr/local/lsws/Example/html/demo/manage.py", line 22, in <module>

main()

File "/usr/local/lsws/Example/html/demo/manage.py", line 13, in main

raise ImportError(

This is prebuilt image with django i suppose. Ihave the virtualenvironment activated. Why is this error coming out ? Thanks to those who can help



/r/djangolearning
https://redd.it/1ivlyg5
How can I retain django form data after a user is redirected

I am trying to create a complicated form set up that has the user authenticate with google as part of the steps to the form.

I'm currently using django-formtools library and what I want is:

1. User fills out data in form 1
2. Based on data filled in form 1, have them authenticate with google on step 2.
3. Once authentication is done, redirect them back to the form, but on to the next step.

I'm currently using the SessionWizardView, but what is happening is that after Google auth is done, it redirects back to the form page but its back on Step 1 of the form, and not the correct 3rd step that I would want it to be on, and it doesn't seem to have record of what the user has already submitted.

Is there a better way to do this without using the django-formtools library? Seemed like a match for the workflow I want, but I need a way to get back in the form flow after the redirect is done.













/r/django
https://redd.it/1iwm4jc
D Simple Questions Thread

Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!

Thread will stay alive until next one so keep posting after the date in the title.

Thanks to everyone for answering questions in the previous thread!

/r/MachineLearning
https://redd.it/1iwdbgs
Shareable product or platform to demonstrate coding project skills?

Does anyone have any recommendations for a platform or product (paid or free) that lets you record yourself coding on a moderately complex project?

Basically, I'm aiming for something that would obsolete doing toy exercises for every employer you interview with. Something you could slap on your resume and they just navigate to a link to view it. Ideally it includes AI completions or is compatible enough you could use an IDE with them.

By moderately complex I mean going many steps above LeetCode type problems. You would need to demonstrate that you can use tools to quickly navigate and understand a decent size codebase. It would need to be something you couldn't memorize.

/r/Python
https://redd.it/1iwwcjk
Open-Source MICT AI Ethics Toolkit: Practical Examples for Mitigating Bias and Hallucinations

Hey r/python,

I'm excited to share an open-source project I've been working on with the Boredbrains Consortium: the **MICT AI Ethics Toolkit**. It's designed to help developers build more responsible and trustworthy AI systems by providing practical tools and examples for addressing ethical concerns. The toolkit is built on the **Mobius Inspired Cyclical Transformation (MICT)** framework, which provides a structured, iterative process for integrating ethical considerations *throughout* the AI development lifecycle.

**What My Project Does:**

The MICT AI Ethics Toolkit provides reusable Python (and JavaScript) functions, classes, and example implementations for addressing common ethical challenges in AI development. It's *not* a standalone framework; it's a set of tools designed to be integrated *into* existing projects, using the MICT framework for a structured approach. Currently, the toolkit includes:

* **Bias Detection:** Functions to calculate disparate impact ratios for binary classification models, helping you identify and mitigate potential biases in your datasets and models.
* **Hallucination Detection:** Functions for detecting potential hallucinations in large language model outputs, using simple string-matching against a knowledge base. (More sophisticated methods to come!)
* **Example Implementations:** Runnable examples demonstrating how to use these tools within a MICT cycle

/r/Python
https://redd.it/1iwunjl
Should I use Flask or React

I currently have access to a server which provides API endpoints which I cannot modify. I want to create a UI for it. Should I go for using Flask to fetch the data from the API using the routes, or just go straight to React?

My biggest problem is that this server only accepts basic authentication. If I use flask, I can have a login page where I ask the user for a username and password, I then query my API endpoint to see if I have the correct combination of username and password, and then save this username and password in a database (in hashed format). If I use React, I need to ask the username and password from the user and I have to either store this locally or in cache. I am assuming that if I do this, it will be stored in plain text.

My questions are:

1. Which implementation would provide more security and convenience? Flask or React?
2. Is it even stupid of me to think of using Flask instead of React?

P.S. First time asking here, and I am at my wits end trying to figure out which of the two I should use.

/r/flask
https://redd.it/1iwtroa