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
Async proxy view for map layers in my app - is this a bad idea?

We have a mature Django app used as a user and sort of data management system (geospatial data layers). The app currently only tells our frontend which users are authenticated and gives them a list of authorized layers that is served by another "dumb" app (QGISServer). I say dumb since it doesn't know about our users. Just a nginx sub request Auth system is used.

Now we will need to add other map servers, which my require their own authentication that can't be client side, so my plan is to create a new Django proxy view. This view will deal with authentication and authorization of layers using async ORM as well as act as a proxy auth and cache to external servers. It will use async aiohttp to fetch the response tile from the mapserver, cache it in redis, and return it.

The problem is that map tiles get requested by the frontend Open Layers easily 10 at a time when you pan. And it can take a second to render the tile, download it to the proxy and then push to the client. 10 of these at a time would kill the app for a second if it had 10 wsgi

/r/djangolearning
https://redd.it/xtk4a5
Monday Daily Thread: Project ideas!

Comment any project ideas beginner or advanced in this thread for others to give a try! If you complete one make sure to reply to the comment with how you found it and attach some source code! If you're looking for project ideas, you might be interested in checking out Al Sweigart's, "The Big Book of Small Python Projects" which provides a list of projects and the code to make them work.

/r/Python
https://redd.it/xu3v9h
Hitting a learning wall at application factory pattern

After a month of doing this every day i’ve become really comfortable with setting up and deploying new flask apps and deploying them. I now understand the usage of blueprints, and while from an outer perspective I understand why an application factory would come in handy for large apps, I just cannot wrap my head around how the setup actually works. Every tutorial becomes so complicated very quickly and I can’t seem to find any simplified examples.

Looking for any recommended tutorials or tips to push through this wall.

/r/flask
https://redd.it/xuth2j
How does a single running instance of a Flask application handle multiple requests at once? Is it all async or multithreaded? Or handled by the webserver (NGINX, gunicorn, etc)?

Say I had a single Flask application running on an EC2 instance, and 300+ requests were made from other machines at about the same time. How does Flask handle this? Does it spawn new threads and bounce control around?

/r/flask
https://redd.it/xv0js7
Problem viewing images using VSCODE on Apple M1

Does anyone having problems viewing images on Jupyter Notebooks using VSCODE? I am using 14" MacBook Pro , M1..

​

Here is a picture to show you what I am looking at when opening the same notebook using VSCODE (right) vs Jupyter-Lab (Left).

​

https://preview.redd.it/zmzni9roorr91.png?width=1920&format=png&auto=webp&s=dbbab9afb49b63283e9bf0777b4dd2904d907491

/r/JupyterNotebooks
https://redd.it/xum6n6
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/xuzlry
Collaborative Jupyter Whiteboards

I found a common occurrence in data science type of meetings is someone screen-shares their Jupyter notebook either by Zoom, Hangouts, or conference room display and then starts scrolling through it explaining their tables, plots, markdown, Latex, etc. When I want to ask a question about a plot that the presenter scrolled past, there's a lot of "can you scroll up a little, no too far, back down a little". If I want to point to an area of a plot or column in a table, I can do it in Zoom, but it's all out of place once the notebook is scrolled. Usually someone has to ask the presenter to zoom in to see some tiny Matplotlib font.

This led me to start looking into multiplayer versions of Jupyter that strive to be like Google Docs. There's proprietary ones like CoCalc and DeepNote, then there's open-source work underway to add real time collaboration to JupyterLab using Yjs. All of these are geared towards collaborative editing of the notebook code, but I really needed and saw a use for was collaborative viewing of the results contained in the notebook. Since notebooks usually have access to lots of valuable data, IT can

/r/JupyterNotebooks
https://redd.it/xvjtjd
Your all-time favorite Django youtube tutorial?

Looking for some suggestions!

/r/django
https://redd.it/xvd7fv
Can pylint be used for jupyter notebook projects?

Can pylint be used for jupyter notebook projects? If not is there another lint that gets the job done?

Appreciate the answers

/r/JupyterNotebooks
https://redd.it/xtzch6
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/xvut41
%%time only displays wall time

Hello everyone I am having trouble measuring the CPU time taken by a function but the problem is as the title says. The cell magic command %%time only displays the wall time and does not display the CPU time.

Any suggestion would be really helpful.

Thank you.

/r/JupyterNotebooks
https://redd.it/xtdnhc
Generate image in pdf via pdfjinjax

Hi so I am using this library https://github.com/edgaraafelix/pdfjinjax pdfjinjax a fork from pdfjinja I believe both examples were already in pdf format and upon checking both sample.json and example.py the field signature was just a file path and it was already instantiated the image once the pdf created.

But I had a pdf from scracth and I do not know what field in LibreOffice to use for that effect. I tried Image control, Image button but image was not created. In textfield it just paste the file path and not rendering.

In django use, I need to send a file back to the user with premade pdf :) and it needs the image for the header.

So any experienced user used that library how to achieve that? Thank you.

/r/djangolearning
https://redd.it/xwak6u
Update and delete database records with AJAX

so currently i'm using javascipt and ajax to delete and update records of my database but I've seen tutorials creating routes for these actions and linking the button to that route while passing the id as a parameter.

My question is is my way of doing things worse than the route method? Should I adapt the route method instead? if yes why if no why?

it's either:python

@app.route("/example", methods="GET","POST")
def example():
if request.method="GET":
return rendertemplate("example.html")
if request.method="POST":
req= request.get
json()
id = req"request"
logic for deleting from database

javascript

let mybtn = document.getElementById("mybtn")
mybtn.addEventListener("click", ()=>{
fetch(window.origin+"/example",{
method:"POST",
headers: new Headers({
"X-CSRFToken": document.getElementsByName("csrf
token")0.value,


/r/flask
https://redd.it/xwe3ob
Loop through colummyear (not time series)?

I have a huge data set that will only run every paragraph when one year is filtered at a time. i.e. the publication year of a book.
Right now, I have to manually change the year filter each time I want updated data.
Is there a way to create a loop using a specific column (publication
year)?

I know I can use airflow to autmoate this, but I'm too unfamiliar with it. Tried finding an answer on stackflow & google but can't seem to find what I need.

/r/JupyterNotebooks
https://redd.it/xwjlwx
how to use flask with existing database

I am really quite confused about working with databases that already exist. I have followed a bunch of tutorials and read Miguel Grinberg's book, so I am familiar with the basics of how to use flask-sqlalchemy. However I have very limited database experience outside of this (aside from writing a few basic SQL commands), and the SQLAlchemy documentation completely defeats me.

Surely this is a common scenario (already have database, decide to create flask app to access it and so on), but I have never seen a tutorial anywhere that actually explains ways to handle this and now I am stuck. I do not really mind if it is with flask-sqlalchemy or with standard sqlalchemy, as long as I can do something robust.

Flask-sqlalchemy makes it reeeeally convenient to connect the app and query/insert into the table. As I understand it, this requires a set of table classes e.g. a `User` class in a `models.py` file. I know there are things like automap/reflect in the SQLAlchemy API, but I have not been able to really understand those docs sufficiently to know if I can use it with flask, and without any frame of reference it is hard to know if this is

/r/flask
https://redd.it/xwhvic
Tried to deploy my project on the internet - getting this error. What am I doing wrong?

/r/django
https://redd.it/xw42bn