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
Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?

Use this thread to chat about and share Python resources!

/r/Python
https://redd.it/10hdaol
Pynecone: New Features and Performance Improvements ⚑️

Hi everyone, wanted to give a quick update on Pynecone because there have been major improvements in the past month since our initial release.

For those who have never heard of Pynecone, it is a way to build full-stack web apps in pure Python. The framework is easy to get started with even without previous web dev experience, and is entirely open source / free to use.

# Improvements:

Here are some of the notable improvements we implemented. Along with these were many bug fixes to get Pynecone more stable. 

Components/Features:

πŸͺŸ Added Windows support! 
πŸ“ˆ Added built-in graphing libraries using Victory.
Added Dynamic Routes. 

Performance:

⚑️Switched to WebSockets (No more new requests for every event!)
Compiler improvements to speed up event processing.

Community:

⭐️ Grown from \~30 to \~2400 Github stars.
70 [Discord](https://discord.gg/T5WSbC2YtQ) members.
13 More contributors.

Testing:

βœ… Improved unit test coverage and added integration tests for all PRs.

Next Steps:

Add components such as upload and date picker.
Show how to make your own Pynecone 3rd party libraries.
And many more features!

/r/Python
https://redd.it/10h6l7e
NiceGUI now has a subreddit.

Hi Folks... Just a heads up that NiceGUI now has it's own subreddit at r/nicegui. If you want to do really fast and efficient web page development using Python this is definitely worth looking at. Cheers!

/r/Python
https://redd.it/10hg2i4
Add Watermarks To PDF, JPG & PNG files with no restrictive licensing

I created a small Python package to add watermarks to PDF, JPG & PNG files.

**Why?** Most Python PDF packages have licensing that requires you to release your source code which isn't ideal for everyone. In this package, I've utilised PIL (open source HPND License) & Pypdfium2 ( either Apache-2.0 or BSD-3-Clause, at your choice. ) and the code itself is released under MIT license.


Check it out - [https://github.com/bowespublishing/pythonwatermark](https://github.com/bowespublishing/pythonwatermark)
It can probably be massively improved but it works :)

## Installation

Installing the latest PyPI release (recommended)

python3 -m pip install -U pythonwatermark

This will use a pre-built wheel package, the easiest way of installing pythonwatermark.

## Dependencies

pythonwatermark uses two awesome open source python packages to work it's magic they are...

Pillow - [https://github.com/python-pillow/Pillow](https://github.com/python-pillow/Pillow)

Like PIL, Pillow is licensed under the open source HPND License

Pypdfium2 - [https://github.com/pypdfium2-team/pypdfium2](https://github.com/pypdfium2-team/pypdfium2)

PDFium and pypdfium2 are available by the terms and conditions of either Apache-2.0 or BSD-3-Clause, at your choice.

These are both fantastic packages and are liberally licensed meaning unlike with other options you don't need to release your source code to the public.

## Usage

Import watermark utils

from pythonwatermark import watermarkutils

Add watermark to file

watermarkutils.put_watermark(inputfile, outputfile, watermark,

/r/Python
https://redd.it/10hfz75
Am I over thinking this question?

Just for some context, this is my first coding class and read what I am supposed to read in the text book. All it taught us was how to use print and how to set up basic math.

This is the first question on the homework, this question seems complex for the first question. How am I supposed to know how to set this up with knowing little to no nothing about coding?



The US Census Bureau projects population based on the following
assumptions:
One birth every 7 seconds
One death every 13 seconds
One new immigrant every 45 seconds
Write a program to display the population for each of the next five years.
Assume the current population is 312032486 and one year has 365 days.

/r/Python
https://redd.it/10hde5l
Message Queueing: Using Postgres Triggers, Listen and Notify as a replacement for Celery and Signals

A common pattern in modern web development is the requirement to process data asynchronously after some user action or database event. In the article below, we describe via a concrete example a traditional approach to solving this problem for a Django/Postgres based application using django signals and Celery. We then proceed to discuss some of the shortcomings of this approach and demonstrate how using PostgreSQL triggers alongside the PostgreSQL LISTEN/NOTIFY protocol can offer a more robust solution.

Asynchronous processing of database events in a robust and lightweight manner using django-pgpubsub.

/r/django
https://redd.it/10hn5ij
PyI18n - Simple and easy-to-use internationalization library

Attention all Python developers! Are you tired of struggling with internationalization in your projects? Look no further! Introducing our new Python library, PyI18n, the ultimate solution for all your internationalization needs. With easy-to-use API and detailed documentation, localizing your projects has never been easier. This library is fully compatible with the Django framework, so you can easily integrate it into your existing Django projects. Don't miss out on this powerful tool, try it out today and take your internationalization to the next level!


repository: https://github.com/sectasy0/pyi18n

/r/django
https://redd.it/10hmu3p
Skinny models and fat views? Where should I be writing this code?

Hey folks,

I'm writing an app using Django that has fairly minimal locally stored data and is heavily dependent on hitting an external API for data, taking the returned data, manipulating it and mixing it up with locally stored object, before sending it back to the API.

I'm doing a lot of the work in my views.py file, even though what gets rendered to the client side is nearly irrelevant to the project ("here's a sign up form", "you've signed up for X" or "success, you've unsubscribed from y")

So that, combined with there being a) not a ton of local objects being used and b) a lot of taking external data and manipulating it for my needs means I'm getting relatively large views -- more logic happening there than in my models, for sure.

So I'm wondering if there's an inherent problem with writing 'skinny models, fat views' in a case like this? Or if convention or something suggests I should pull some/much of my code into a separate file (a utils.py or bad_architecture.py or whatever) file and just import at runtime? Is there any reason I should be doing that besides DRY when/if that becomes an issue?

Hopefully that makes sense

/r/django
https://redd.it/10hhe87
Need help with Stripe Connect onboarding using Django / DRF backend with JWT authentication

I am using Django Rest Framework to build a REST API for an expo react native mobile application and simplejwt to provide jwt authentication. Right now access tokens are sent in an Authorization header (i.e. Bearer <token> auth header). I am currently integrating with [Stripe Connect](https://stripe.com/docs/connect/collect-then-transfer-guide) and need to create both customers (users that pay) and connected accounts (users who are paid) via stripe's API and onboard them via links that the stripe API generates. During the process of onboarding a connected account we must provide [refresh and return URLS](https://stripe.com/docs/api/account_links/create?lang=python) which regenerate the onboarding URL and return the user to our application (via a deep link for instance) respectively.

import stripe
stripe.api_key = "sk_test_51M9QviJiqI7ZOGdYCVDyKVykMIEnSmGJ0dCENHRqqJKjPkhBYcgR50r71efIi6epNqHzNCxFGBeJrj6clwN9Vkok000WvY3ajz"

stripe.AccountLink.create(
account="acct_1M9QviJiqI7ZOGdY",
refresh_url="https://example.com/reauth",
return_url="https://example.com/return",
type="account_onboarding",
)

My current approach was to make a post request to an API view which creates a user account and then generates the link, sending it back to the mobile app so that it can open the link in the browser. The refresh and return links

/r/django
https://redd.it/10hnrvg
Django-filter; creating a variable which is callable from the view

I have a filter which can be used to filter the products on brand(s), which looks like this:

class SortFilter(django_filters.FilterSet):
ORDER_BY_CHOICES = (
('-discount_sort', 'Hoogste korting'),
('-new_price', 'Hoogste prijs'),
('new_price', 'Laagste prijs'),
)
order_by = django_filters.ChoiceFilter(label='Sorteer op', choices=ORDER_BY_CHOICES,
method='filter_by_order',
empty_label=None)

#HERE I WOULD LIKE THIS INPUT A VARIABLE INTO THE QUERYSET variable of the filter
brand = django_filters.ModelMultipleChoiceFilter(queryset=Product.objects
.order_by('brand')
.filter(categorie='eiwitten')
.values_list('brand', flat=True).distinct()
, widget=forms.CheckboxSelectMultiple)
q = django_filters.CharFilter(method='multiple_field_search', widget=TextInput(attrs=
{'placeholder': 'Zoek..'}))


class Meta:
model = Product
fields = ['brand', 'q']


def filter_by_order(self, queryset, name, value):
return queryset.order_by(value)


def multiple_field_search(self, queryset, name, value):
return queryset.filter(
Q(title__icontains=value) | Q(categorie__icontains=value) | Q(brand__icontains=value)
)

&#x200B;

As you can see, the brand filter returns a flat list of all possible brands in the categorie 'eiwitten'. Is there a way to make the queryset in brand a variable which I can input from my view function? This way I can use the filter for every page. Resulting in a unique brand list depending on the categorie. My view function for the 'eiwitten' page looks like this:

def eiwit(request):
#print(request.GET.getlist('brand'))
# filter alleen eiwitproducten

/r/django
https://redd.it/10houtj
Another modern game login screen!

&#x200B;

https://preview.redd.it/xbhsz6ncfdda1.png?width=702&format=png&auto=webp&v=enabled&s=a2d759494c9b041ae8e26ccef13422909fdb2ec5

Complete with a random splash text every time you open the window!

Made with the amazing CustomTkinter library - https://github.com/TomSchimansky/CustomTkinter

Please let me know what you think down in the comments! \^_\^

/r/Python
https://redd.it/10hnzmn
How to Secure Sensitive data

Hello, I'm trying to create a system where someone enters data via a form and the data is then saved and emailed to users. Is there a way(s) to safely secure the data so that only those who receive the email have access to it other than using csrf token in wtforms.

/r/flask
https://redd.it/10hu03v
Please explain this

/r/JupyterNotebooks
https://redd.it/10hssux
Sunday Daily Thread: What's everyone working on this week?

Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.

/r/Python
https://redd.it/10i5ly7
Django-axes, but for something else than failed login

Hello,

I'm currently seeking a way to temporarily ban users and/or IP, not because of failed login attempts or rate limits, but based on rules like "more than X HTTP 400 error". I'm trying to ban people that would try to play too much with my DRF rest API.

Another solution could be to handle the rule part in my validation step, and send the errors to the module so it could treat them.

If you heard about something like django-axes with admin pages, cool off, whitelist, etc. it would be great !!!

Thank you !

/r/django
https://redd.it/10i4gmq
Help with workflow for Django development on a machine with Anaconda/Miniconda/Conda installed

Hey guy, i have anaconda(and conda) installed, and it is my main package manager since i use python for Data Science a lot. I've been wanting to get into Django development, but a lot of useful and cool Django packages are only available through pip. I was wondering what's the most ideal workflow for this situation.

To clarify, conda doesn't work very well with pip, since they are both different package managers with different behaviours. I found a question on another website(which i can't link because of auto moderator), but none of the answers provided seemed like a straightforward solution for daily use.

&#x200B;

So i was wondering, if there's someone also using conda and Django on the same machine, what is your workflow?

Thanks :)

/r/django
https://redd.it/10i630h
delete or hide?

i was thinking on implementing a boolean field in my models to set the record as hide whenever someone click delete,instead of entirely deleting a record.i beleive this would be a safest way to recover a record whenever a mistake happens.whats your opinion?

/r/django
https://redd.it/10ht1p0