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
I created a no-cost AWS infrastructure boilerplate for Python API

Hi r/Python!

I created a low-cost AWS infrastructure boilerplate for Python API (Django as implemented). Works with free tiers for accounts less than a year old. The only thing you need to pay for is Secret Manager (1$ monthly for each secret).

What's in the box?
It's a boilerplate to link up your Python API with AWS. It keeps things straightforward, and AWS CDK makes it easy to tweak the setup.

Why bother?
If you've ever wanted a straightforward way to get your API going without making things overly complicated, this could be useful. It's all about building your app fast without boxing you into a rigid system. By using AWS CDK your infrastructure could be extended without any limits!


Fully deployed project uses:

RDS (postgres, T3 MICRO)
S3 bucket (for static files, images or/and django-admin)
Lambda (DockerImage with 3 MB of memory and 60 second timeout by default)
ECR (keeps only 2 newest images)
API Gateway
RDS secrets (generated automatically)
Other secrets (like DJANGO_SECRET_KEY, generated manually)

It's my first "open source" solution. I'm open to hearing your thoughts and any ideas you might have. Thanks for checking it out, and I hope this makes your development process a bit

/r/Python
https://redd.it/18crgim
Which AI is best for Django help?

I have found chatgpt 3.5 pretty great for certain tasks, on waitlist for 4.0. Obviously it has its limitations but I'm wondering if there are any AIs out there that work better specifically for django/python. I have not tried anything else.

/r/django
https://redd.it/18cxjsy
I finally have something worthy of posting on the Python Reddit. I present to you SavonPython!

https://github.com/huths0lo/SavonPython


I shop at vons. They have digital coupons that can offer some hefty discounts if you use them. The best way to maximize your savings is to literally just clip every single coupon; whether you use it or not. They are adding literally hundreds every single week, so this could be a huge time suck. I wanted to find a way to automate this so that all of my coupons were clipped automatically.


This lead me on a journey of understanding what are the interactions that take place between an end user and their app. I was initially trying to understand how their app worked on my iphone, but eventually realized that the iphone app always requires a one time passcode; which I cant automate around easily. I do have some sms automation, but it would require I change my account to a different phone number, and wouldnt really be usable by others. But I found that they have the same functionality on vons.com, which does allow for the use of passwords.


I'm not a web developer. In fact I only have a couple of years of programming

/r/Python
https://redd.it/18d6oyz
Inherited Model with Inherited Serializer

Hi all!

Even just the necessary keywords to look this up on my own would be awesome, I'm not sure how to phrase it.

I have two models, where ChildModel is inheriting from ParentModel:

class ParentModel(models.Model):
field_1 = models.IntField()
field_2 = models.IntField()
count = models.IntField(default=0)


class ChildModel(ParentModel):
field_3 = models.IntField()
sub_count = models.IntField(default=0)

Then, I have two serializers:

class ParentModelSerializer(serializers.ModelSerializer):
class Meta:
model = models.ParentModel
fields = '__all__'

field_2 = serializers.IntField(read_only=True)
count = serializers.IntField(read_only=True)

def create(self, validated_data):
instance = models.ParentModel.objects.create(**validated_data)


/r/django
https://redd.it/18d6roz
Developing APIs with DRF

I have a question regarding the text case used when developing APIs from Django models. DRF has a model serializer class that automatically creates a serializer based on model fields. For instance, if you have a User model and there's a field called first_name is it OK to use the field_name as a key name in your API or firstName? In short, which one is appropriate between {'first_name': 'Django'} and {'firstName':'Django'}

/r/django
https://redd.it/18cvawj
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/18d9i0f
Implementing vueform templates

Now that vueform has become open source.
Is there any django module available that could reuse its templates as django forms ?

https://vueform.com/

/r/django
https://redd.it/18dfl1l
WtForms not passing data

First off, this is my first Flask project, so please excuse any messy code. Though, i'm open to being critiqued.

I've set up a very simple form just to try to get this to work, but after the submit button is clicked, it doesn't seem to make it to my IF statement under the function. Here is the code.

In my main.py file:

from flask_wtf import FlaskForm

from wtforms import StringField, SubmitField

from wtforms.validators import DataRequired

from flask_wtf.csrf import CSRFProtect

​

class TestForm(FlaskForm):

myname = StringField('Enter Name', validators=[DataRequired()\])

submit = SubmitField('Sign in')

​

u/app.route('/testform', methods=['GET', 'POST'\])

def testform():

myname = None

form = TestForm()

print(form.errors)

if form.validate_on_submit():

print(form.errors)

print("Testing to see if we ever get to this point.")

myname = form.myname.data

form.myname.data = ''

flash("Holy shit, that worked!")

​

return render_template('testform.html', myname = myname, form = form)

​

Here is the code on the testform.html file:

​

{% extends "baseCode.html" %}

​

{% block head %}

{% endblock %}

{% block body %}

​

{% if myname %}

<h3>Hello {{ myname }}</h3>

{% else %}

<h2>Hello, Please Sign In</h2>

<form method="POST">

{{ form.hidden_tag() }}

&#x200B;

{{ form.myname.label }}

{{ form.myname() }}

<br /><br />

{{ form.submit() }}

</form>

{% endif %}

{% endblock %}

&#x200B;

I've spent far too much time walking through iterations to dumb this down and find the issue, but haven't been able to. Any help would be wonderful.Thank you all!

/r/flask
https://redd.it/18c57i3
NFL Odds API

Looking for a good source for nfl odds & scores. I’ve played a bit with scraping this data but everytime i think i have a decent solution there are big gaps in data or a total redesign of the site(s). I’m definitely price sensitive but i am willing to pay if there were a decent rest api that would give me each game’s home team, away team, date, score, spread, and o/u. If anyone knows of a good one, i’ll be forever grateful

/r/Python
https://redd.it/18d9v73
Run migration on specific schema

Hi everyone, is there any option to run migrations on specified schema i want to have same database tables as in default public schema but in my own custom schema. I'm using PostgreSQL thanks in advance.

/r/django
https://redd.it/18dkz55
Made a Python script to get your Spotify stats

I wrote a Python script while I was playing with the Spotify API which can get your Spotify Stats :)

&#x200B;



Repository Link : https://github.com/ni5arga/spotify-stats-python

Feel free to star and fork!

/r/Python
https://redd.it/18dscdi
The Python on Microcontrollers Newsletter, a free weekly news and project resource, please subscribe

&#x200B;

https://preview.redd.it/41ir56yu235c1.jpg?width=503&format=pjpg&auto=webp&s=55dbf7fb7ea7aca981e7666a190f330b00575716

With the Python on Microcontrollers newsletter, you get all the latest information on Python running on hardware in one place! MicroPython, CircuitPython and Python on single Board Computers like Raspberry Pi & many more.

The Python on Microcontrollers newsletter is the place for the latest news. It arrives Monday morning with all the week’s happenings. No advertising, no spam, easy to unsubscribe.

10,673 subscribers - the largest Python on hardware newsletter out there.

Catch all the weekly news on **Python for Microcontrollers** with adafruitdaily.com.

>This ad-free, spam-free weekly email is filled with CircuitPython, MicroPython, and Python information that you may have missed, all in one place!
You get a summary of all the software, events, projects, and the latest hardware worldwide once a week, no ads!

Ensure you catch the weekly Python on Hardware roundup– you can cancel anytime – **try our spam-free newsletter today**!

**https://www.adafruitdaily.com/**

/r/Python
https://redd.it/18dodr9
Understanding TTFB Latency in DJango - Seems absurdly slow after DB optimizations even locally

Hello

Our team has been undergoing optimizing our Django DRF / Graphene stack for latency we can't quite understand the source of our slowdowns

Our Stack:

Python 3.11
Django 4.2.8
DRF 3.14.0
Django Graphene 3.1.5

We've done the 'basic' optimizations of

implementing prefetch / select related
removed all n+1 generated SQL queries

And of course, scrounged the internet looking for answers, and saw the ModelSerializer issue posted here: https://hakibenita.com/django-rest-framework-slow

Which as I understand it is 'mostly' fixed in the latest Django?

We've manually optimized our QuerySets . SQL, and got our worst case SQL latency is around 200ms, most in the 10-100 range.

However, our TTFB, is anywhere from 1 to 3 seconds as measured in dev tools on a browser performing a graphiQL query, as well as in our test suites

Here are some numbers from GraphiQL Console:

One GQL QUery generates 6 optimzied SQL Queries resulting in a response of a 1.4 MB JSon file which has a heavy amount of nested of elements (necessary for our workload)

Django Debug Toolbar numbers:

101.9ms for SQL access

Chrome Dev Tools

6 SQL Querues 56.44 ms (not sure how it knows this?)
44us to send request
937 ms waiting for server response
8.48 ms to download
Total \~1 second for a

/r/django
https://redd.it/18dszpy
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/18e0fjt
Flask-Gravatar

Is Flask-Gravatar not compatible with Flask 3.0??

I am just importing it and it throws me this error--
ImportError: cannot import name '_request_ctx_stack' from 'flask' (C:\\Users\\pc\\OneDrive\\Documents\\Python Projects\\Blog Website - Final Product\\venv\\Lib\\site-packages\\flask\\__init__.py)


Are there any workarounds to this problem??

&#x200B;

/r/flask
https://redd.it/18dwkly
The Dawn of Concurrency and Parallelism: Python 3.12 Starts to Support a Per-Interpreter GIL

> PEP 684 introduces a per-interpreter GIL, so that sub-interpreters may now be created with a unique GIL per interpreter. This allows Python programs to take full advantage of multiple CPU cores. This is currently only available through the C-API, though a Python API is anticipated for 3.13.

## Summary

- Per-interpreter GIL with C-API is available in Python 3.12
- Python API is anticipated for Python 3.13

## References

- A Per-Interpreter GIL section in _What’s New In Python 3.12_
- PEP 686: A Per-Interpreter GIL
- PEP 734: Multiple Interpreters in the Stdlib

/r/Python
https://redd.it/18e0q7p