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
Changing flask session in a middleware

Hi,

I would like to change the flask session to set a default value whenever the user is authenticated and if there isn't a value yet:

class VersionSessionMiddleware:
    def init(self, app):
        = app
       
    def call(self, environ, startresponse):
        if not constants.SESSION
VERSIONNAME in session:
            session[constants.SESSION
VERSIONNAME] = constants.DEFAULTVERSION

        return self.app(environ, startresponse)self.app

This fails with `RuntimeError: Working outside of request context`. And I can access to current\
user from Flask-Login, it is None.

From these results, I think a middleware is not the solution I'm looking for. What tool can I use to do that?

Thanks.

/r/flask
https://redd.it/1crq4wu
Flask MySQL database session best practice – resolve Broken Pipe Error

My question for this post: Is my approach for using and relying before\_request and after\_request to handle opening and closing database sessions ok or just a mess?

# Background

I have a Python Flask Website, a different Flask app that is the API, and a service Python app that the API can call when needed that connect to the same MySQL database. They all use SQLAlchemy to communicate with the same MySQL database.

Every morning, I find a similar Broken Pipe Error which prevents the first user for the day from logging in right away. They will need to try a few times to rollback and close the session. This is the problem I am ultimately trying to resolve.

My approach has been, instead of trying to find the loose end database session, I thought I could cut off an expiring database session by using the before_request decorator to instantiate a db session. Then after_request decorator to close the session after each request.

This doesn’t seem to be working. I have not prevented Broken Pipe errors.

Should I just create a database session when I need it and close it? Then if I find Broken Pipe error try to find the source of the problem.

Diagram of

/r/flask
[https://redd.it/1cqus6q
Why isn't IPython more popular?

In the past years, I've had a lot of frustration with the python console:

- pasting multiline is complicated

- editing is impossible

- no syntax highligthing etc


Now I discover the IPython console...


It's wonderful... I use it all the time to try snippets, which I used to run in colab or in yupyter.

Why isn't this shell more used and more known?



/r/IPython
https://redd.it/1crp70l
D How do you get better at reading proof in the ML papers, with background in CS only?

Hi everyone, as the title, how do you get better at reading proof in the ML papers? The ML papers I mentioned are those in adversarial ML, e.g. Certified Adversarial Robustness via Randomized Smoothing. For context, I have basic knowledge of calculus, linear algebra, but most of the time when reading the proof, sometime I feel that one line just come out of nowhere, and I can't reason why or how they do it. Maybe because my background is CS, with focus on software, so I'm lacking of the rigorous proof-based math stuff. Please help!!

/r/MachineLearning
https://redd.it/1crr0fa
Is PyGame still alive?

So it was a long time ago in the good old Python 2.x days (circa 2010 probably) that I had learned PyGame with some tutorials at my former work place. But nowadays since I mostly freelance with business apps, I never felt the need for it.

But since such a game development project is on the horizon after all these years, I was wondering if PyGame can still be up for the task with Python 3.x? Or is there a better Python library available these days?

I don't need any advanced gaming features of modern day VFX or anything, all I need is some basic Mario/Luigi style graphics, that's all!

/r/Python
https://redd.it/1crsktg
Framework to use for backend

Hello guys

I recently decided to move from nodejs(expressjs) to python for general purposes but mostly for backend.
I have couple of questions.

1. Will i regret my migration to python? :)

2. Which framework you suggest for backend solo dev?

And what tips are you suggesting me in general to get used to python.


/r/Python
https://redd.it/1croj1r
OAuth flow for API integrations

Hey guys,


I want to start planning out a system so our multi-tenant application can connect to customer's CRM API via OAuth.

We'd be connecting to more than one CRM(obviously) and I'm trying to make the OAuth process as generalized as possible. Does anyone have any good references or tutorials I can follow?


Thanks a lot



/r/flask
https://redd.it/1crvelc
Declarative GUI Slint v1.6 released with Design Mode (WYSIWYG) Improvements

https://slint.dev/blog/slint-1.6-released

Slint is a declarative GUI toolkit to build native user interfaces for desktop and embedded applications. Find more information at https://slint.dev/ or check out the source code at https://github.com/slint-ui/slint.

EDIT: The Python APIs are currently in alpha. More info -- https://github.com/slint-ui/slint/tree/master/api/python

/r/Python
https://redd.it/1crsmbe
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/1cs75gc
How can I do an auth?

I'm starting with django, and I understand that its architecture is loosely coupled, however I don't know where to put the authentication app, that is, I know that django gives it to me, but I must always put the logic in an app, whether in the inventory app, which requires login to access it, or in some other app. Where do you put the authentication logic? I understand that you cannot make an authentication app in the traditional way (python manage.py startapp auth) since it throws an error.

I would appreciate any advice :)

/r/djangolearning
https://redd.it/1cry3zx
Lost my job today to an agency

*May come off as a rant, I'm sorry

So my employer hired an agency a few days ago and I got notice today that I'm being let go (I'm the only dev/seo/graphic designer/marketing/network admin).

I'm kind of lost for words right now because they're asking me to help them convert the current state to WordPress, which is what they were using before I built a completely new website.

I've worked for them for 4 months now, and I built a static 70 page website from the ground up. This includes all graphic designs, graphic animations, modals, and the hundreds of design changes because they couldn't tell me what they wanted, without me having to make it first. This includes 30 unique service area pages tailored to those areas and are all ranking decently well in a highly competitive service oriented space.

About 3 weeks ago, I converted the entire website to django (I have nightmares of changing hard-coded urls)

I built a complete admin dashboard, customer & employee portal. I built forms for blog posts and rss feeds that also post to social media. I integrated CMS's, multiple api's; I made analytics dashboards, custom on-site user tracking, automated geofencing campaigns, and more (not trying to

/r/django
https://redd.it/1crwucx
I made a python bot that plays minesweeper

Hello,

I made this Minesweeper bot that I wanted to share with you all.

What My Project Does \-

The bot takes a screenshot of the board and runs a classification algorithm to extract the contents of the board. It then analyzes the board, finds as many mines as it can, and sends clicks. If it cannot find any mines then it guesses the most probable position of a mine.

Target Audience \-

It's a toy project for anyone interested in algorithms or problem-solving.

Comparison \-

This is just my attempt at making a minesweeper bot. I'm sure there are many bots out there that are much more efficient than this.

do let me know, if you feel anything can be done better :)

​

/r/Python
https://redd.it/1csd77f
django-allauth 0.63.0 is out, featuring headless (API) support
https://docs.allauth.org/en/latest/headless/openapi-specification/

/r/django
https://redd.it/1crxo3y
Help me pls 😭, js file not connecting to flask

Okay, so I am making a website by using Flask.I was building an authorization system for the website by using Firebase. And, I was trying to connect the auth.js file(which contains firebase) to the HTML file(login.html). But, for some reason, it is not being connected. I think the issue is in auth.js.
been scratching my head around this for the last 5 hours. some help would be appreciated πŸ˜­πŸ™πŸ½
github link: https://github.com/Parth1304/career-website



/r/flask
https://redd.it/1csdesi
Does anyone know what "excess events" mean for Sentry?

I got a message in my sentry dashboard "You have exceeded your performance unit limit. We are dropping any excess events". Could someone tell me what this means? Will I still get any exceptions logged, or will I have to upgrade to have this feature? What does excess events mean? Thanks in advance!

/r/django
https://redd.it/1csegt7
Where to Deploy Django & React App?

I want to deploy a small to medium Django & React application and I am currently investigating my options. I don't want to deploy to Azure, AWS, or Google since it seems excessively expensive.

I have used Heroku before but even there it can get progressively more expensive when the app grows. I am now looking towards options such as Digital Ocean or Render.

Has anyone used these services before and if yes, what did you think? Also, do you have any other recommendations?

/r/django
https://redd.it/1csk8r4
Production grade AI Web apps, just using python ?

Hey guys, I have worked on building multiple ai/ml usecases and their specific backends. But now I want build interfaces for easy and quick integration. I saw a blog which used FastUI which looks quick decent but when I tried it just showed me a Json of elements on the page. Are there any other libraries I should use? πŸ€”

/r/Python
https://redd.it/1csfimo
Need suggestion and searching for a oppertunity .

Hello everyone,

I’m currently working as an Associate Backend Engineer and pursuing my Bachelor of Computer Application. I'm looking to enhance my skill set to improve my chances of getting a better job as I’m not satisfied with the pay at my current position.

Here are the skills and experiences I currently have:

* **Backend Development**: Created a payroll parser for streamlined data processing, integrated real-time communication systems using WebSocket, and designed/deployed diverse APIs with unit tests covered.
* **Notifications**: Implemented notification backends using technologies like Firebase Cloud Messaging for push notifications.
* **Performance Optimization**: Conducted load testing and API profiling to optimize and enhance system performance using tools like Locust and Django Silk.
* **Development Practices**: Introduced Behavior Driven Development (BDD), initiated automation testing using Selenium, and worked on transforming projects to multi-tenant architecture to improve scalability.
* **Testing and Automation**: Experience with unit testing, Pytest, BDD, TDD, and stress testing.
* **Web Services and APIs**: Hands-on experience with REST, GraphQL, and various async libraries.
* **Containerization**: Proficient with Docker (Images, Containers, YAML files).
* **Cloud Platforms**: Experience with AWS services such as EC2, S3, and SNS.
* **Databases**: Worked with PostgreSQL, MongoDB, Redis, and MySQL.

I would love to hear your suggestions on what other skills or technologies I should

/r/django
https://redd.it/1cso53l
Frontend sprinkles of Javascript, like Rails/Hotwired but for Django?

I'm new to Django, coming from a Ruby on Rails background. I will have to use Django for an upcoming project and would like to use Django templates with some JS sprinkled in to make the frontend more dynamic. What is the best tooling for introducing some JS functionality without having to use the heavy stacks like React single page application with Django just as an API?


In Rails, they recently introduced the Hotwired framework, which I think is fantastic. Stimulus can be used with Django templates, but as far as I can tell there is no equivalent for the Turbo component.

/r/django
https://redd.it/1cssevb
Get data from HTML to another

On a page use data from a model to fill tables and do calculations in Javascript That page is for audits and quality control, but I need another page for data business and graphics. Using Javascript generated tables using data rendered from views and functions.

How do I render from one page to another without having to do the calculations again, each page has an instance assigned to an id

/r/django
https://redd.it/1csx05s