Tuesday Daily Thread: Advanced questions
Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.
If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/13ip05k
Have some burning questions on advanced Python topics? Use this thread to ask more advanced questions related to Python.
If your question is a beginner question we hold a beginner Daily Thread tomorrow (Wednesday) where you can ask any question! We may remove questions here and ask you to resubmit tomorrow.
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/13ip05k
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
Introducing seaborn-polars, a package allowing to use Polars DataFrames and LazyFrames with Seaborn
In the last few months I've been using Polars more and more with only major inconvenience being that when doing exploratory data analysis, Polars dataframes are not supported by any of the common plotting packages. So it was either switching to Pandas or having a whole lot of boilerplate. For example, creating a scatterplot using pandas df is simply:
But with Polars you'd have to do:
That's quite a lot of boilerplate so I wrote this small package that is a wrapper around seaborn plotting functions and allows for them to be used with Polars DataFrames and LazyFrames using the same syntax as with Pandas dfs:
The code creates a deepcopy of the original dataframe so your source LazyFrames will remain lazy after plotting.
The package is available on PyPI: https://pypi.org/project/seaborn-polars/
If you want to contribute or interested in source code, the repository is here: https://github.com/pavelcherepan/seaborn\_polars
/r/Python
https://redd.it/13ittrl
In the last few months I've been using Polars more and more with only major inconvenience being that when doing exploratory data analysis, Polars dataframes are not supported by any of the common plotting packages. So it was either switching to Pandas or having a whole lot of boilerplate. For example, creating a scatterplot using pandas df is simply:
import seaborn as sns
sns.scatterplot(df, x='rating', y='votes', hue='genre')
But with Polars you'd have to do:
x = df.select(pl.col('rating')).to_numpy().ravel()
y = df.select(pl.col('votes')).to_numpy().ravel()
hue = df.select(pl.col('genre')).to_numpy().ravel()
sns.scatterplot(x=x, y=y, hue=hue)
That's quite a lot of boilerplate so I wrote this small package that is a wrapper around seaborn plotting functions and allows for them to be used with Polars DataFrames and LazyFrames using the same syntax as with Pandas dfs:
import polars as pl
import seaborn_polars as snl
df = pl.scan_csv('data.txt')
snl.scatterplot(df, x='rating', y='votes', hue='genre')
The code creates a deepcopy of the original dataframe so your source LazyFrames will remain lazy after plotting.
The package is available on PyPI: https://pypi.org/project/seaborn-polars/
If you want to contribute or interested in source code, the repository is here: https://github.com/pavelcherepan/seaborn\_polars
/r/Python
https://redd.it/13ittrl
PyPI
seaborn-polars
Wrapper for plotting with seaborn using Polars dataframes and lazyframes
Python Flask routing return 404 in my hosting (Centos 7 Cpanel)
Hi,
I’ve got an issue in terms of using send_from_directory in my app.py :
​
`app.run`
​
However, when i deploy to my hosting (using centos 7 in Cpanel), the @app.route(“/”) it’s works as well as if i type manually in http://[my_website\]/riwu. but not for @app.route(“/newIndex”).
it shows error “Not found : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.”.
I already setup the .htaccess and httpd.conf to change value from :
​
​
to
​
​
but still does not work.
I’ve tried in my local server using Visual Code (Windows 10) and it’s works normally.
note : @ app.route(“/newIndex”) is does not have any redirect new .html , It just to download file from send_from_directory.
​
is there any configuration that i missed?
Thanks
/r/flask
https://redd.it/13j7jv3
Hi,
I’ve got an issue in terms of using send_from_directory in my app.py :
​
from flask import Flask, render_template, request, jsonify, send_from_directoryimport jsonapp = Flask(__name__)u/app.route("/")def home():return render_template("index.html")u/app.route("/newIndex", methods=["GET", "POST"])def newIndex():Appdata = extractApp(appUrl)json.dumps(Appdata)filename = Appdata["nama_file"].replace("./static/assets/save\\", "")permitted_directory = "static/assets/save/"return send_from_directory(directory=permitted_directory, path=filename, as_attachment=True)u/app.route("/riwu")def riwu():return "<h1>ini test saja 123</h1>"if __name__ == "__main__":`app.run`
(debug=True)​
However, when i deploy to my hosting (using centos 7 in Cpanel), the @app.route(“/”) it’s works as well as if i type manually in http://[my_website\]/riwu. but not for @app.route(“/newIndex”).
it shows error “Not found : The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.”.
I already setup the .htaccess and httpd.conf to change value from :
​
<Directory /var/www/html/public>...AllowOverride None...</Directory>​
to
​
<Directory /var/www/html/public>...AllowOverride All...</Directory>​
but still does not work.
I’ve tried in my local server using Visual Code (Windows 10) and it’s works normally.
note : @ app.route(“/newIndex”) is does not have any redirect new .html , It just to download file from send_from_directory.
​
is there any configuration that i missed?
Thanks
/r/flask
https://redd.it/13j7jv3
app.run
app.run - This website is for sale! - app Resources and Information.
This website is for sale! app.run is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, app.run has it all. We hope you find what you are searching for!
I made a small Website where everyone can leave a little note. I am not the most experienced, so this project was a lot of fun.
/r/flask
https://redd.it/13imus9
/r/flask
https://redd.it/13imus9
Python’s super() considered super! (Raymond Hettinger)
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
/r/Python
https://redd.it/13j39al
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
/r/Python
https://redd.it/13j39al
Deep Thoughts by Raymond Hettinger
Python’s super() considered super!
If you aren’t wowed by Python’s super() builtin, chances are you don’t really know what it is capable of doing or how to use it effectively. Much has been written about super() and much of that wri…
RPython-based emulator speeds up RISC-V simulation over 15x
RPython, the python sublanguage behind PyPy, has been used to create a RISC-V emulator. It beats the C version by over 15x when booting linux. https://www.pypy.org/posts/2023/05/rpython-used-to-speed-up-risc-v-simulation-over-15x.html
/r/Python
https://redd.it/13j9i06
RPython, the python sublanguage behind PyPy, has been used to create a RISC-V emulator. It beats the C version by over 15x when booting linux. https://www.pypy.org/posts/2023/05/rpython-used-to-speed-up-risc-v-simulation-over-15x.html
/r/Python
https://redd.it/13j9i06
PyPy
RPython-based emulator speeds up RISC-V simulation over 15x
In cooperation with RISC-V International, who funded a part of this project,
we recently created a workflow to
use RPython to take a Sail RISC-V model and automatically create a RISC-V ISA
emulator fr
we recently created a workflow to
use RPython to take a Sail RISC-V model and automatically create a RISC-V ISA
emulator fr
Wednesday Daily Thread: Beginner questions
New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/13jlfti
New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!
This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.
/r/Python
https://redd.it/13jlfti
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
Easiest way to add write-through cache for authuser queries?
Hello! I'm new to django. I have an existing app with quite a lot of scale, and I'm seeing that simple reads from the auth\user table (ie
What's the easiest path to do this? Is there any way to override just the queries for the select and the insert/update? I've tried googling, but there are a lot of similar topics that make it hard to hone in on the best path, so I thought I'd bring it to y'all :-)
/r/django
https://redd.it/13jbzs1
Hello! I'm new to django. I have an existing app with quite a lot of scale, and I'm seeing that simple reads from the auth\user table (ie
SELECT .. WHERE id=$1) account for a huge amount of load on database. I'd like to put a write-through cache in front of that. It's very read heavy so I think it should effectively reduce that load to near-zero.What's the easiest path to do this? Is there any way to override just the queries for the select and the insert/update? I've tried googling, but there are a lot of similar topics that make it hard to hone in on the best path, so I thought I'd bring it to y'all :-)
/r/django
https://redd.it/13jbzs1
Reddit
r/django on Reddit: Easiest way to add write-through cache for auth_user queries?
Posted by u/smittyplusplus - 4 votes and 11 comments
Flask hosting for specific purpose
Hello. I am sorry if this comes off as an oblivious, and perhaps frequently asked, question. I am quite new to this, and am overwhelmed with the different options.
For my bachelor project, I will need to post a specialized survey, which I have created as a flask application, containing the survey questions, as well as some background code to show randomized context each time the survey is taken, and then storing the survey responses.
Right now, I simply have the server hosted on a free Repl.it server, but as the application will need to properly manage upwards of 300-500 concurrent requests at a time, I will need to host it on a more capable server to avoid latency problems/errors, but that allows for the survey responses to be stored and continuously updated, either in a dedicated database, or simply writing them into a JSON file or something like that.
As such, I am looking for the best/simplest place to host this application properly. I won't expect this to be entirely free, but am hoping that it is not too expensive, especially since the website only needs to be up for a few weeks.
/r/flask
https://redd.it/13jdslm
Hello. I am sorry if this comes off as an oblivious, and perhaps frequently asked, question. I am quite new to this, and am overwhelmed with the different options.
For my bachelor project, I will need to post a specialized survey, which I have created as a flask application, containing the survey questions, as well as some background code to show randomized context each time the survey is taken, and then storing the survey responses.
Right now, I simply have the server hosted on a free Repl.it server, but as the application will need to properly manage upwards of 300-500 concurrent requests at a time, I will need to host it on a more capable server to avoid latency problems/errors, but that allows for the survey responses to be stored and continuously updated, either in a dedicated database, or simply writing them into a JSON file or something like that.
As such, I am looking for the best/simplest place to host this application properly. I won't expect this to be entirely free, but am hoping that it is not too expensive, especially since the website only needs to be up for a few weeks.
/r/flask
https://redd.it/13jdslm
Replit
Replit – Build apps and sites with AI
Replit is an AI-powered platform for building professional web apps and websites.
Issues with form submission and form.validate_on_submit()
I am having issues with a form submission using wtforms and form.validate_on_submit(). Here is the code from the following files:
myapp/forms.py:
from flask\_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me')
submit = SubmitField('Sign In')
myapp/routes.py:
from flask import render_template, flash, redirect, url_for
from myapp import app
from myapp.forms import LoginForm
@app.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
flash("{}".format(form.username.data))
return redirect(url_for('index'))
flash("setup")
return render_template('login.html', form = form)
myapp/templates/login.html:
{% extends "clientbase.html" %}
{% block content %}
<main id="main">
<section id="breadcrumbs" class="breadcrumbs">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
<h2>Login</h2>
<ol>
<li><a href="{{ url_for('index') }}">Home</a>
<li>Login</li>
</ol>
</div>
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-lg-11 col-md-4 text-lg-left">
<h3 data-aos="fade-up">Login</h3>
{%
/r/flask
https://redd.it/13jd01c
I am having issues with a form submission using wtforms and form.validate_on_submit(). Here is the code from the following files:
myapp/forms.py:
from flask\_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me')
submit = SubmitField('Sign In')
myapp/routes.py:
from flask import render_template, flash, redirect, url_for
from myapp import app
from myapp.forms import LoginForm
@app.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('index'))
form = LoginForm()
if form.validate_on_submit():
flash("{}".format(form.username.data))
return redirect(url_for('index'))
flash("setup")
return render_template('login.html', form = form)
myapp/templates/login.html:
{% extends "clientbase.html" %}
{% block content %}
<main id="main">
<section id="breadcrumbs" class="breadcrumbs">
<div class="container">
<div class="d-flex justify-content-between align-items-center">
<h2>Login</h2>
<ol>
<li><a href="{{ url_for('index') }}">Home</a>
<li>Login</li>
</ol>
</div>
</div>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-lg-11 col-md-4 text-lg-left">
<h3 data-aos="fade-up">Login</h3>
{%
/r/flask
https://redd.it/13jd01c
Reddit
r/flask on Reddit: Issues with form submission and form.validate_on_submit()
Posted by u/coyote_zed - 1 vote and 6 comments
Design patterns with django?
There is some common design patterns used in django? Does the default folder structure scalable? It is possible to use some other like Hexagonal Structure with django?
/r/djangolearning
https://redd.it/13jhahf
There is some common design patterns used in django? Does the default folder structure scalable? It is possible to use some other like Hexagonal Structure with django?
/r/djangolearning
https://redd.it/13jhahf
Reddit
r/djangolearning on Reddit: Design patterns with django?
Posted by u/tgoofarias - No votes and no comments
Revolutionize Django Admin: Give it a SPA like look-and-feel with Hotwire/TURBO
https://viewflow.medium.com/revolutionize-django-admin-give-it-a-spa-like-look-and-feel-with-hotwire-turbo-9ea44871a083
/r/django
https://redd.it/13j3nvj
https://viewflow.medium.com/revolutionize-django-admin-give-it-a-spa-like-look-and-feel-with-hotwire-turbo-9ea44871a083
/r/django
https://redd.it/13j3nvj
Medium
Revolutionize Django Admin: Give it a SPA like look-and-feel with Hotwire/TURBO
Django Admin has long been a reliable tool for managing databases and performing administrative tasks. However, compared to modern SPA…
Pyscan: A command-line tool to detect security issues in your python dependencies.
pyscan v0.1.0 | Github
+ blazingly fast and efficient scanner that can be used to scan large projects fairly quickly.
+ automatically uses requirements.txt, pyproject.toml or straight from the source code (though not reccomended)
+ easy to use, and can be integrated into existing build processes.
+ In its very early alpha stage, so some features may not work correctly. PRs and issue makers welcome.
## Install
or
or check out the releases.
## Usage
Go to your python source directory (or wherever you keep your requirements.txt/pyproject.toml) and run:
or
that should get the thing going.
Here's the order of precedence for a "source" file:
+ requirements.txt
+ pyproject.toml
+ your python source code (.py) highly not reccomended
Any dependencies without a specified version defaults to its latest stable version. Make sure you version-ize your requirements and use proper pep-508 syntax.
/r/Python
https://redd.it/13jq6bw
pyscan v0.1.0 | Github
+ blazingly fast and efficient scanner that can be used to scan large projects fairly quickly.
+ automatically uses requirements.txt, pyproject.toml or straight from the source code (though not reccomended)
+ easy to use, and can be integrated into existing build processes.
+ In its very early alpha stage, so some features may not work correctly. PRs and issue makers welcome.
## Install
pip install pyscan-rs
or
cargo install pyscan
or check out the releases.
## Usage
Go to your python source directory (or wherever you keep your requirements.txt/pyproject.toml) and run:
pyscan
or
pyscan -d path/to/src
that should get the thing going.
Here's the order of precedence for a "source" file:
+ requirements.txt
+ pyproject.toml
+ your python source code (.py) highly not reccomended
Any dependencies without a specified version defaults to its latest stable version. Make sure you version-ize your requirements and use proper pep-508 syntax.
/r/Python
https://redd.it/13jq6bw
GitHub
GitHub - aswinnnn/pyscan: python dependency vulnerability scanner, written in Rust.
python dependency vulnerability scanner, written in Rust. - aswinnnn/pyscan
Tips Multicontainer Deployment on AWS or other Cloud Provider
Hi all, the company I‘m working on is deploying a multi-container application (Django, Redis, Nginx) to AWS Elastic Beanstalk with a docker-compose file. The deployment takes forever and is quite error prone. Any tips on deploying such kind of apps to AWS in an easy and reliable way? It would also be possible to change the cloud provider, if there is a more developer friendly way. Thanks!
/r/django
https://redd.it/13jw01v
Hi all, the company I‘m working on is deploying a multi-container application (Django, Redis, Nginx) to AWS Elastic Beanstalk with a docker-compose file. The deployment takes forever and is quite error prone. Any tips on deploying such kind of apps to AWS in an easy and reliable way? It would also be possible to change the cloud provider, if there is a more developer friendly way. Thanks!
/r/django
https://redd.it/13jw01v
Reddit
r/django on Reddit: Tips Multicontainer Deployment on AWS or other Cloud Provider
Posted by u/rupert_bra - No votes and 3 comments
The Power of Bit Manipulation - How to Solve Problems Efficiently
https://www.anurag629.club/posts/the-power-of-bit-manipulation-how-to-solve-problems-efficiently
/r/Python
https://redd.it/13jy2x8
https://www.anurag629.club/posts/the-power-of-bit-manipulation-how-to-solve-problems-efficiently
/r/Python
https://redd.it/13jy2x8
Reverse django migrations
There is a way to reverse a migrations in django? i've seen this feature in other frameworks but i have never listen to something like that in django. I always forget to put an attribute in models and i need to delete or modify in the database, especially when it is the uuid
/r/djangolearning
https://redd.it/13kault
There is a way to reverse a migrations in django? i've seen this feature in other frameworks but i have never listen to something like that in django. I always forget to put an attribute in models and i need to delete or modify in the database, especially when it is the uuid
/r/djangolearning
https://redd.it/13kault
Reddit
r/djangolearning on Reddit: Reverse django migrations
Posted by u/tgoofarias - No votes and 1 comment