pythondaily | Образование

Telegram-канал pythondaily - Python Daily

1102

Daily Python News Question, Tips and Tricks, Best Practices on Python Programming Language Find more reddit channels over at @r_channels

Подписаться на канал

Python Daily

Django Ninja vs DRF for Async ? Seeking Advice

Hey everyone,

We’re building an API for our app, and while we really want to use Django, we need robust async capabilities since we’ll be making external API requests (e.g., OpenAI, LLMs).

We’re torn between Django REST Framework (DRF) and Django Ninja. While Django Ninja supports async out of the box and looks very developer-friendly, we’re concerned about its long-term support and community size compared to DRF. Future-proofing our app is important since this API will be a core part of our project.

For those who have used Django Ninja in production, would you recommend it? What are your experiences with its stability and scalability?

If not Django Ninja, how would you approach incorporating async functionality into a DRF-based API? Any advice or recommendations would be greatly appreciated! We will definitely use Celery for some tasks but rn we're looking for a solution for immediate responses.

Thanks in advance! 🙏


P.S. We also need robust permission handling since we need to be HIPAA compliant.

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

Читать полностью…

Python Daily

blackjack from 100 days of python code.

Wow. This was rough on me. This is the 3rd version after I got lost in the sauce of my own spaghetti code. So nested in statements I gave my code the bird.

Things I learned:
write your pseudo code. if you don't know **how** you'll do your pseudo code, research on the front end.
always! debug before writing a block of something
if you don't understand what you wrote when you wrote it, you wont understand it later. Breakdown functions into something logical, then test them step by step.

good times. Any pointers would be much appreciated. Thanks everyone :)

from random import randint
import art

def checkscore(playerlist, dealerlist): #get win draw bust lose continue
if len(player
list) == 5 and sum(playerlist) <= 21:
return "win"
elif sum(player
list) >= 22:
return "bust"
elif sum(playerlist) == 21 and not sum(dealerlist)

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

Читать полностью…

Python Daily

Need Help deploying React + Flask

Hi, flask newbie here


i spent quite a while developing a react and flask application thats pretty simple,

react fronend, sends post requests and get requests to flask backend, uses routing aswell.

i had it up working fine with localhost:5000 and localhost:3000 and now I'm trying to deploy it,
tried to use Dockerfile with render and deploy them both at the same time, ended up being really frustrating so i switched to using a digitalocean droplet, and following a tutorial that got me setup with nginx, but because my flask backed doesnt really display anything i am having trouble debugging - i set up a system service on the droplet (just a linux vm) so a gunicorn process is alway running, but i cant visit it properly. also i have a domain but it doenst seemt o work with nginx.

any advice on deployment?
Thanks

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

Читать полностью…

Python Daily

Example large open source rest API?

I started reading Indico, but looks like it is mostly a server rendered app rather than an API and SPA. Are there are other large examples that I can read?

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

Читать полностью…

Python Daily

Bagels v0.3 update! Expense tracker that lives in your terminal.

Hi r/Python! I'm excited to share about the launch of Bagels 0.3 - a terminal (UI) expense tracker built with the textual TUI library! Check out the git repo for screenshots!

This new major version adds a whole new manager page, equipped with a display of 3 new plots (spending per day, cummulative spending trajectory and balance over time). The new budget section is designed to assist with saving part of your income and limit unnecessary spending!

The plotting is implemented with plotext!

# Target audience

Pain point: I find it annoying that my mobile budget tracker often gets out of sync with my actual balance when a record is missing, and I have no clue when that was. Also, it was frustrating that the most feature-rich budget trackers require you to pay to export your data.

Bagels is designed for you to conveniently enter your records at the end of each day, and store them in sqlite for easy export and processing if needed!

Comparison: Unlike traditional expense trackers that are accessed by web or mobile, Bagels lives in your terminal. Intended for you to check in and add records for the day, instead of doing so on the go with a mobile app.

#

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

Читать полностью…

Python Daily

Saturday Daily Thread: Resource Request and Sharing! Daily Thread

# Weekly Thread: Resource Request and Sharing 📚

Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!

## How it Works:

1. Request: Can't find a resource on a particular topic? Ask here!
2. Share: Found something useful? Share it with the community.
3. Review: Give or get opinions on Python resources you've used.

## Guidelines:

Please include the type of resource (e.g., book, video, article) and the topic.
Always be respectful when reviewing someone else's shared resource.

## Example Shares:

1. Book: "Fluent Python" \- Great for understanding Pythonic idioms.
2. Video: Python Data Structures \- Excellent overview of Python's built-in data structures.
3. Article: Understanding Python Decorators \- A deep dive into decorators.

## Example Requests:

1. Looking for: Video tutorials on web scraping with Python.
2. Need: Book recommendations for Python machine learning.

Share the knowledge, enrich the community. Happy learning! 🌟

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

Читать полностью…

Python Daily

Quick Question - New to Flask

I created a python script that generates the "Turning LED on" text in a web browser using the Flask API. After finding success with printing the text to the web browser, I attempted to import the GPIOZERO library and use the script to literally turn on an LED. Unfortunately, I cannot get it to work. I would appreciate any help with troubleshooting the code.

I tried creating local variables under the defined method. Please see below:

from flask import Flask

from gpiozero import LED

app = Flask(\_\_name\_\_)

u/app.route('/led/on')

def led\_on():

return "Turning on the LED"

return {'status': True}

led = LED(17)

green.on()



u/app.route('/led/off')

def led\_off():

return "Turning off the LED"

led = LED(17)

green.off()



Thanks in advance for the help!

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

Читать полностью…

Python Daily

Open Source Load Testing with Locust: 13 years, 60 million downloads later

Hi, maintainer of Locust, the popular load testing tool for Python here 👋

Recently our project turned 13 years old, got its 25,000th GitHub star AND 60 millionth download*, so I figured now might be a good time to look back a little.

In fact, I wrote a whole blog article about it. The TL;DR of it is

* Expressing load tests in Python is still much more powerful than clicking around in a GUI

* Open source is fun, messy and benefits greatly from automated testing

* We're going to do tons of new stuff going forward (AsyncIO, freethreading, extended protocol support). Let me know if you want to contribute! There's also a hosted version nowadays (Locust Cloud)

A big shout out and thanks to the almost 300 people who have contributed so far. You rock.

Let me know if you have any comments on the article or on Locust in general, happy to answer any questions :)

* The truth is that nobody knows how many times Python packages have been downloaded, due to mirrors etc, but at least this one says its 61.3M https://pepy.tech/projects/locust?timeRange=threeMonths&amp;category=version&amp;includeCIDownloads=true&amp;granularity=daily&amp;viewType=chart&amp;versions=2.32.7.dev14%2C2.32.7.dev9%2C2.32.7.dev8



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

Читать полностью…

Python Daily

Need help in getting zip files from Postman on Flask server and using it

from
flask
import
Flask, redirect, url_for, Blueprint, request, jsonify
from
myproject
import
db
from
myproject.manager.models
import
Manager, Events
from
flask_jwt_extended
import
create_access_token, jwt_required, get_jwt_identity
from
datetime
import
datetime
import
zipfile
import
os
from
io
import
BytesIO
from
werkzeug.utils
import
secure_filename

manager_bp = Blueprint('manager_bp' ,__name__)


@manager_bp.route('/sign-up/',
methods
=['POST'])
def sign_up():


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

Читать полностью…

Python Daily

Is it possible for non-IT person to get a part-time job in django?

Does an IT degree really matter?

/r/djangolearning
https://redd.it/1i804cq

Читать полностью…

Python Daily

How to Implement Role-Based Access Control (RBAC) into a Django Application
https://www.permit.io/blog/how-to-implement-role-based-access-control-rbac-into-a-django-application

/r/djangolearning
https://redd.it/1i85sed

Читать полностью…

Python Daily

Fastapi deployment posting here for help



Newbie in Deployment: Need Help with Managing Load for FastAPI + Qdrant Setup

I'm working on a data retrieval project using FastAPI and Qdrant. Here's my workflow:

1. User sends a query via a POST API.


2. I translate non-English queries to English using Azure OpenAI.


3. Retrieve relevant context from a locally hosted Qdrant DB.



I've initialized Qdrant and FastAPI using Docker Compose.

Question: What are the best practices to handle heavy load (at least 10 requests/sec)? Any tips for optimizing this setup would be greatly appreciated!

Please share Me any documentation for reference thank you

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

Читать полностью…

Python Daily

Friday Daily Thread: r/Python Meta and Free-Talk Fridays

# Weekly Thread: Meta Discussions and Free Talk Friday 🎙️

Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!

## How it Works:

1. Open Mic: Share your thoughts, questions, or anything you'd like related to Python or the community.
2. Community Pulse: Discuss what you feel is working well or what could be improved in the /r/python community.
3. News & Updates: Keep up-to-date with the latest in Python and share any news you find interesting.

## Guidelines:

All topics should be related to Python or the /r/python community.
Be respectful and follow Reddit's Code of Conduct.

## Example Topics:

1. New Python Release: What do you think about the new features in Python 3.11?
2. Community Events: Any Python meetups or webinars coming up?
3. Learning Resources: Found a great Python tutorial? Share it here!
4. Job Market: How has Python impacted your career?
5. Hot Takes: Got a controversial Python opinion? Let's hear it!
6. Community Ideas: Something you'd like to see us do? tell us.

Let's keep the conversation going. Happy discussing! 🌟

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

Читать полностью…

Python Daily

R ENERGY-BASED DIFFUSION LANGUAGE MODELS FOR TEXT GENERATION

https://arxiv.org/pdf/2410.21357

The authors of this paper combine diffusion models with energy based modeling to address the challenges in discrete generative modeling.

/r/MachineLearning
https://redd.it/1i87lgy

Читать полностью…

Python Daily

Rotate refresh tokens in JWT

Hi. If anyone has worked with JWT tokens where rotate refresh tokens is set to True, can you please explain how rotation works?

For example, below is my simple JWT settings.

ACCESSTOKENLIFETIME": timedelta(minutes=5), "REFRESHTOKENLIFETIME": timedelta(days=1), "ROTATEREFRESHTOKENS": True, "BLACKLISTAFTERROTATION": True.

Here’s how I think it works:

1. when the access token expires after 5 minutes, user requests a new access token using the refresh token (let's call it RT1) .
2. Along with the access token, a new refresh token (RT2) is sent to the user. RT1 is invalidated/blacklisted.
3. when again this new access token expires after 5 minutes, RT2 is used for requesting the new access token.

I believe I have understood the process correctly so far.

My question is, what is the validity of RT2? Is it 1 day from the time RT2 was issued or 1 day from the time RT1 was issued?

If it’s the former, then rotation keeps happening, and the user will remain logged in until they explicitly log out of the application. Am I right? If yes, then specifying a 1-day validity for the refresh token would serve no purpose.

If it's the latter, then the subsequent refresh tokens after RT1 will not have 1 day validity.

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

Читать полностью…

Python Daily

Zoho's ZeptoMail has released a Django integration pip package.

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

Читать полностью…

Python Daily

Any reason to NOT use Pyright?

Based on this comparison (by Microsoft): https://htmlpreview.github.io/?https://github.com/python/typing/blob/main/conformance/results/results.html

It seems Pyright more or less implements nearly every specification in the Python Type System, while it's competitors are still lagging behind. Is there even any reason to not use Pyright (other than it relying on Node.js, but I don't think it's that big of a deal)? I know MyPy is the so-called 'Reference Implementation' but for a Reference Implementation it sure is lagging behind a lot.

EDIT: I context is which Type Checker is best to use as a Language Server, rather than CI/CD.

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

Читать полностью…

Python Daily

Need Help Improving My Resume – Seeking Ideas and Feedback!

I’m currently in the process of updating my resume and could really use some fresh ideas or suggestions to make it stand out. I’m applying for a Python Django Developer/Full Stack Developer role, and I want my resume to effectively highlight my skills and experience.

Here’s a bit about me:

Experience: I have 2 years of experience as a Python Django Trainer, where I’ve taught aspiring developers and built a strong foundation in Python, Django, and web development. I’m now transitioning into Full Stack Development roles to apply my technical and teaching expertise in real-world projects.
Skills: Python, Django, JavaScript, REST APIs, SQL, Git, and front-end tools like Tailwind CSS and Bootstrap. I also have experience with creating and deploying projects using Django, collaborating with teams, and building RESTful applications.
Career Goal: I aim to grow as a Full Stack Developer by contributing to innovative projects, building scalable solutions, and exploring modern web development practices.

If you have any suggestions for improving the structure, format, or content of my resume, I’d really appreciate your input.

Are there specific sections or layouts that work best for tech resumes?
What’s the best way to showcase teaching experience in a way that resonates with recruiters?


/r/djangolearning
https://redd.it/1i8122h

Читать полностью…

Python Daily

Django + HTMX

I am playing around for a while now with this combo with mixed feelings.
It’s really hard to remain a clear structure when rendering only with partials, snippets and including it then in content…
Do you struggle with that too? Is there any helpful resource how not to lose track with the overall structure?



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

Читать полностью…

Python Daily

Anthropic CEO says at the beginning of 2024, models scored ~3% at SWE-bench. Ten months later, we were at 50%. He thinks in another year we’ll probably be at 90% N

"One of the reasons I'm optimistic about the rapid progress of powerful AI is that, if you extrapolate the next few points on the curve, we’re quickly approaching human-level ability.

Some of the new models we've developed, as well as reasoning models from other companies, are starting to reach what I’d consider PhD or professional level. For example, our latest model, Sonnet 3.5, gets about 50% on SWE-bench, which is a benchmark for professional real-world software engineering tasks. At the start of the year, the state of the art was only around 3 or 4%. In just 10 months, we've gone from 3% to 50% on this task. I believe in another year, we could reach 90%.

We've seen similar advancements in graduate-level math, physics, and biology, with models like OpenAI’s GPT-3. If we continue to extrapolate this progress, in a few years, these models could surpass the highest professional human levels in skill.

Now, will that progress continue? There are various reasons why it might not, but if the current trajectory holds, that's where we're headed."

\- Dario Amodei. See the full interview here.

/r/MachineLearning
https://redd.it/1i8wkth

Читать полностью…

Python Daily

DO THE TUTORIAL!!

So I'm on track graduating with my first cs degree this may.

I felt really uncomfortable because with only two classes left I really don't think I can build anything yet.

Our capstone project my group is doing a web based photo sharing platform and it led to me making this...

https://preview.redd.it/y26d5c1unnee1.png?width=866&amp;format=png&amp;auto=webp&amp;s=035d969257c1a8c775f2f404845c1db05fc18d85

https://preview.redd.it/hc4y11xunnee1.png?width=892&amp;format=png&amp;auto=webp&amp;s=e7516b37326877f981002308185e2ffc0494fe92

https://preview.redd.it/wemja97vnnee1.png?width=882&amp;format=png&amp;auto=webp&amp;s=1117e08e1e0ae43eb7fa72b903e25e617bb81638

I made some more, and am aiming to complete one part of the tutorial a day, and been trying to document the process ([Here on my blog\](https://victorynotes.hashnode.dev)). I cannot stress how much the tutorial have helped me vs watching and following along youtube videos.

Really changed my world not only on learning django and other comsci process in general.

/r/djangolearning
https://redd.it/1i7t9xj

Читать полностью…

Python Daily

Resurrected: Announcing django-guardian 3.0.0rc1

Hi All,

Our beloved django-guardian (object level permissions for django) went unmaintained for a long time. After a lot of patience we've managed to resurrect the project and get all the permissions in place for the associated github, pypi, rtd accounts etc.

Today I released 3.0.0rc1 which brings django version support up to date and containes a whole ton of bugfixes, doc improvements and minor features. I'm very confident in it and expect to make this a full release over the next couple of months.

In this PR I explain why we've made this a major version release, although this shouldn't break your setup and *should* be a drop in replacement.

If you try this, please post because I want to hear your experience!



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

Читать полностью…

Python Daily

Can my Flask app be downloaded?

If I'm running Flask / Gunicorn and Traefik in Docker, without any other webserver, can my app.py be downloaded?

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

Читать полностью…

Python Daily

how to learn Flask

I would like to learn Flask and SQLite to make simple web apps for hobby.
What are the best resources? Any course or video you would recommend?

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

Читать полностью…

Python Daily

I made this using Django and tailwind

I’ve been learning Django for the past year and working on various small projects. While searching for ideas to build a project that could solve real-time problems, one of my photographer friends suggested an idea: "Hey AJ, can you build something where I can share and showcase my event photos with clients?" (He’s a wedding photographer.) He wanted a way to share photos of live weddings through a website, using a QR code.

Inspired by this, I built **ShareMySnaps** —a platform that allows users to create digital albums in minutes. Although there are many products available in the market, this project was entirely for my learning experience.

Here are some features of the app:

1. Users need to sign up via their Google account.
2. On the dashboard, users can create a folder, which will automatically be created in their Google Drive.
3. When users click to upload an image, they are redirected to their Google Drive page to upload.
4. Users can download a beautiful QR code that links to their gallery page.
5. The gallery page fetches all the photos from the specific folder and showcases them on the gallery website.
6. Each gallery has its own dedicated page, and these pages are customizable (currently, the

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

Читать полностью…

Python Daily

DRF first or wait?

In a hypothetical situation where you wanted to deliver an MVP with minimal functionality to showcase an idea, but you knew one day it would also be an app, would you build DRF from the beginning or iterate into DRF over time?

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

Читать полностью…

Python Daily

Test & Code. Why is pytest-cov the number 1 pytest plugin? Here's my take on it.

Listen here [https://testandcode.com/episodes/pytest-cov](https://testandcode.com/episodes/pytest-cov)

Discussed:

* what Coverage.py is
* why you should measure code coverage on both your source and test code
* what pytest-cov is
* extra features pytest-cov gives you over and above coverage.py
* and generally why using both is awesome

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

Читать полностью…

Python Daily

Python flask hosting help

Hello i am still relatively new to programming and developed a python flask app that uses openai api call to respond to user input. My application works fine locally but continues to crash during the build whenever i try to host it. Ive tried Vercel as well as Digital Ocean and Fly.io

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

Читать полностью…

Python Daily

Implementing Graceful Shutdown in a Flask Application with Gunicorn and Multiprocessing

I need to implement graceful shutdown in an application where there are two Flask servers (running on different ports) and a shared multiprocessing setup.

Assume Server 1 handles the actual API endpoints, while Server 2 collects metrics and has an endpoint for that. Here's the mock setup I’m working with:

import multiprocessing as mp
import os
import signal
import time

from typing import Dict
from flask import Flask, Response
from gunicorn.app.base import BaseApplication
from gunicorn.arbiter import Arbiter

import logging

LOGGER = logging.getLogger(name)

def numberofworkers():
return mp.cpucount() * 2 + 1

def handler
app():
app = Flask(name)

u/app.route("/", methods="GET")
def index():
return "Hello, World!"


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

Читать полностью…

Python Daily

deidentification - A Python tool for removing personal information from text using NLP

I'm excited to share a tool I created for automatically identifying and removing personal information from text documents using Natural Language Processing. It is both a CLI tool and an API.

https://github.com/jftuga/deidentification
https://pypi.org/project/text-deidentification

What my project does:

Identifies and replaces person names using spaCy's transformer model
Converts gender-specific pronouns to neutral alternatives
Handles possessives and hyphenated names
Offers HTML output with color-coded replacements

Target Audience:

This is aimed at production use.

Comparison:

I have not found another open-source tool that performs the same task. If you happen to know of one, please share it.




**Technical highlights:**

* Uses spaCy's transformer model for accurate Named Entity Recognition
* Handles Unicode variants and mixed encodings intelligently
* Caches metadata for quick reprocessing

Here's a quick example:

Input: John Smith's report was excellent. He clearly understands the topic.
Output: [PERSON]'s report was excellent. HE/SHE clearly understands the topic.



This was a fun project to work on - especially solving the challenge of maintaining correct character positions during replacements. The backwards processing approach was a neat solution to avoid recalculating positions after each replacement.

Check out the deidentification GitHub repo for more details and examples. I also wrote a blog post which goes into more details.

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

Читать полностью…
Подписаться на канал