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
How to make one instance of Flask app play a sound through another instance of the same app?

The idea is to have a simple Flask app that has a client page and a server page. I would have the client page open on my phone and the server page open on my computer. I click a button on my phone and a sound is played from my computer.

I know how to play a sound using Javascript, but I'm not sure how to play a sound with Javascript through the Flask app. Any ideas?

/r/flask
https://redd.it/1c5s83e
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/1c5vh3q
I made a step by step tutorial to show how to set up JWT Authentication and then consume it in a React app

Hello! 👋

A few months ago started making videos documenting my process as I code. I find that doing this helps me develop my skills and it really brings me so much joy to share my guides as every now and then they help someone and when that happens, I feel very very happy! 😀



Anyhow, my latest [video](https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3) is about one hour and twenty-six minutes long. We start the whole process from scratch, beginning with backend development and later moving on to frontend development. In the backend, we create a RESTful API using Django and Django Rest Framework, implementing features such as user registration, login, logout, and user information retrieval with JWT authentication. On the frontend, we build a simple React application with Vite as the build tool, and use Axios for making HTTP requests to the backend API.

**Dependencies:**

**Backend:**

* Django
* Django Rest Framework
* djangorestframework-simplejwt
* django-cors-headers

**Frontend:**

* React.js
* Vite (build tool)
* Axios

Link: [https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3](https://youtu.be/1pIrRTxGnJ4?si=52Nn3h4AjtXYDEn3)


If you watch the video, I would love to hear your thoughts!
Happy coding! 😊

/r/django
https://redd.it/1c5iczb
How to override behaviour of AddIndexConcurrently in Django?

The AddIndexConcurrently django class does the following SQL:

CREATE INDEX CONCURRENTLY <idx_name>


However, I have an application that requires something a bit more complex.
I.e., I need to do some checks on the table, and if those checks pass I need to run

CREATE INDEX CONCURRENTLY IF NOT EXISTS <idx_name>


Is there a way to do that so that I can just override AddIndexConcurrently with my own class and do what I need to do there?

/r/django
https://redd.it/1c5xvbf
Using external authentication provider

I’m new to Django and authentication, and am trying to determine the correct process for authentication (using Entra ID in my case). When a user tries to access a page, that will call a view, which will then attempt to get an access token. Does the app need to redirect to a Microsoft page, or can this all be achieved in a Django template? Also, once this access token is received where is it stored?

/r/django
https://redd.it/1c5x3qo
D Can GNNs be used as model for all types of data?

Since it seems like almost every dataset can be converted to a graph :

1. Tabular - Nodes as rows with no edges between them
2. Text and Audio - Nodes as words with directed edges between adjacent words
3. Time Series - Same as 2
4. Image - Nodes as pixels with undirected edges between adjacent pixels (including diagonal)

Even if GNNs can work on all types of data, I think it may be time and space intensive to covert them into graphs, especially in case of Images.

At the same time, GNNs can make some Tabular data based ML models even more accurate - for e.g. if we have a Tabular dataset on Apartment Pricing, we can add edges between apartments in the same neighborhood so that all their prices are dependent on one another, and this models real-life phenomenon of how apartments in the same neighborhood have codependent pricing based on state of the neighborhood (for e.g. if crimes increase in the neighborhood, all apartments have their prices go down)

/r/MachineLearning
https://redd.it/1c5olyc
Easily Manage Browser Cookies Across Chrome and Firefox with Python!

Hey, r/Python community!

I've developed a versatile Python script that extracts and converts cookies from **Google Chrome and Mozilla Firefox** into commonly used formats. This tool is useful for developers and sysadmins who need to manage cookies for automation tasks, testing, or migrations between different environments.

## **What My Project Does**

### **Functionalities of the Script**

1. **Extract Cookies** from the SQLite databases of Chrome and Firefox.
2. **Convert Cookies** to either Netscape or JavaScript formats.
3. **Combine Cookies** from both browsers into a single file when working with the Netscape format. This feature is particularly useful for tools like `curl`, `wget`, or `aria2` that may require a unified cookie file.

## **Target Audience**

This script is specifically designed for:
- **Developers** testing web applications with real user cookies.
- **Sysadmins** who manage user sessions across different systems.
- **Tech Enthusiasts** looking to automate or manipulate browser data.

## **Comparison**

### **Key Features:**

- **Support for Multiple Browsers**: Extract cookies from Chrome and Firefox.
- **Flexible Output Formats**: Convert cookies to Netscape or JavaScript formats, depending on your needs.
- **Combination Capability**: Allows cookies from multiple browsers to be combined into one file, simplifying the management of multiple browser environments.

## **Usage:**

Here’s how you can use this script effectively:

```bash
python3 cookie-converter.py -b <browser> -i <input_path> -o <output_path> -f

/r/Python
https://redd.it/1c63d5g
How to detrend oscillating data?



I'm currently doing my thesis and it requires data from accelerometers to be inputted onto the Artemis modal software for analysis. I have successfully obtained the acceleration data, but unfortunately some of the data collected shows a trend (either increasing or decreasing) when the data should be oscillating at around 0 (which is the case of any structure's vibrations). Is there a software that is capable of detrending these signals? Thanks

/r/Python
https://redd.it/1c6341a
Gunicorn and Nginx

i need to deploy a flask app and after a large search i reach that i need to deploy the app through nginx and gunicorn but the problem is i am not a programmer i am start learning programming and i found it so hard and every time i search for solution i found a huge amount of solution which is looks like different for me so the question is how i deploy the app using nginx and gunicorn ?

/r/django
https://redd.it/1c640rw
Through Model Migrations

So I made a through model for an m2m field, made a migration then it freaked out on migrate.

My understanding is that it tries to delete some pre-existing relationship table to accommodate the new custom one, for some reason.. It seems like the “easy fix” youtubers default to is deleting the database but that seems like a load of bs to me especially with valuable relationship data already there.

How am I supposed to remedy this change in production? Am i supposed to rollback migrations and do something fancy in the migration file to accommodate this? What is the process I should adhere to so I can accommodate these changes upon update in production? What is the order of operations here? Bc from time to time, yeah id like to change relationships like foreign key to m2m or add my own through model here and there..

/r/django
https://redd.it/1c66398
Question: Tool for editing figures in Python

So I'm trying to switch from MATLAB to Python for my numerical simulations.

One of the things I like about MATLAB is the ability to edit figures by adding stuff (eg arrows, lines, text ... ) to the figure within the software itself. This is what I mean. It's a very handy tool in my line of work and I use it often.

I was wondering if there's any similar tool for Python. I use matplotlib and seaborn. Any suggestions would be great. Thanks guys!

/r/Python
https://redd.it/1c5ixdz
ScrumMD: A CLI Scrum tool written in Python

I got grumpy with our Scrum process, and I thought about what kinda tool I'd love to work with... so I started making it in my beloved Python. I think it's mature enough I'd like to start giving it to other people.

It's called ScrumMD. It's open source, and you can already install it with pip (pip install scrummd) if you've got Python 3.10+. Documented, with tutorials on https://scrummd.readthedocs.io/en/stable/ and source on https://github.com/lkingsford/scrummd

What my project does

Short version is that it's some tools to support you storing all of your Scrum cards (or, I guess, other cards - tickets perhaps?) in markdown format on a local machine. There's intentionally a lot of flexibility - so, every card needs a summary, but everything else is fair game. You can configure to require fields for some collections (like needing status in stories), or limit fields (like requiring status be 'Done' or 'In Progress').

Target Audience

Limited, but public. It's chief audience is software engineers who work in self-organising teams. It's for teams who use processes like Scrum, but don't need the bureaucracy layers.

Honestly - I know it's niche. Heck, I won't even be using it at work myself. But, if I could, I would - because

/r/Python
https://redd.it/1c69jns
Django PyCryptodome AES decryption - ValueError: Padding is incorrect

I am trying to encrypt incoming files and than decrypt them later. I was following the [documentation](https://www.pycryptodome.org/src/cipher/classic#cbc-mode) for how to use AES with CBC mode for decryption and encryption.

My view for uploading and encrypting file:

@router.post("/upload_files")
def upload_files(request, file: UploadedFile = File(...)):
save_file = operations.aes_encryption(user_id=request.auth.id,file=request.FILES.get('file'))

def aes_encryption(self,user_id,file):
user = UserQueries.get_user(id=user_id)
key: bytes = bytes(user.key, "utf-8")
path: str = user.path

save_file = self._encrypt_file(file,key,path,user)

return save_file

def _encrypt_file(self,file,key,path,user):
file_content = file.read()

cipher = AES.new(key, AES.MODE_CBC)


/r/django
https://redd.it/1c6cewm
Using multiple apps in a project

Hey everyone, django/backend dev beginner here, have what might be a newbie question and i suppose it might lead to more of a design discussion than a one size fits all answer...

&#x200B;

Essentially wondering when I should be using multiple apps in a project?

&#x200B;

For context, im working on a patient portal type of application in a health care context. Essentially the purpose is to visualize data from sensors.

&#x200B;

Key objects include patients, sensors, and clinics (treatment sites)....in addition there will be different User types that need to be implemented.

&#x200B;

So i'm wondering how I should go about structuring the project? Should every item needing CRUD operations be its own separate app, or should eeeevrrything be in one models.py file? What are the things I should be thinking about to answer these questions?

&#x200B;

/r/django
https://redd.it/1c6fhs8
Can't use div styles

/r/flask
https://redd.it/1c6em16
Deploying Multi-Module Python Applications on GCP: Service Recommendations?

I'm working on a project involving a Python application with multiple interacting modules and am looking for some advice on deploying it efficiently on Google Cloud Platform. Here's a brief overview of what the application entails:


Functionality Overview:
Data Fetching: One module fetches data from external websites.
Data Extraction: Another module extracts data from another GCP project.
Data Processing: Variables are processed across various modules.
CSV Output: The app generates and stores CSV files.
Scheduled Running: The application should run automatically once daily.


I would greatly appreciate your insights on the following questions:
1. What are the best GCP services to use for this type of application?
2. Recommended Python libraries for handling web data retrieval in this case?
3. How to proceed step by step? I intend to first deploy my Python application using placeholder inputs and simple printed outputs. Then, I plan to integrate the data fetching component and implement the creation and storage of CSV files. Does this strategy seem logical to you?


Currently, I only tried to deploy my Python code using Google Cloud Functions, but I find this method impractical because I must deploy each module separately.

/r/Python
https://redd.it/1c6b77i
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

# Weekly Thread: Professional Use, Jobs, and Education 🏢

Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.

---

## How it Works:

1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.

---

## Guidelines:

- This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
- Keep discussions relevant to Python in the professional and educational context.

---

## Example Topics:

1. Career Paths: What kinds of roles are out there for Python developers?
2. Certifications: Are Python certifications worth it?
3. Course Recommendations: Any good advanced Python courses to recommend?
4. Workplace Tools: What Python libraries are indispensable in your professional work?
5. Interview Tips: What types of Python questions are commonly asked in interviews?

---

Let's help each other grow in our careers and education. Happy discussing! 🌟

/r/Python
https://redd.it/1c6pauh
Monitoring asyncio ready queue in python

I'm optimizing the performance of a Python application that includes many non-blocking I/O operations, some of which involve making HTTP API calls. We use an asynchronous client for all I/O operations, including database and Redis access. During load testing with concurrent users, we've noticed that processing times significantly increase with the number of users. How can we determine if this slowdown is due to delays in API calls or if there is a significant delay in the event loop picking up tasks that have been resolved and added to the ready queue?
I have tried setting up an async task which runs continuously with an asyncio.sleep(2) and measures the time difference between the actual time and 2 seconds, thus giving me a proxy of what is the delay at that moment. This worked fine even though with some overhead of running a task every 2 seconds and it's still a proxy. Instead, I'm looking for ways to monitor this on explicit async tasks.

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