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
Computational Collision Physics

Hello, so I recently wrote a paper on my Python project based on collision physics. If possible, I would to love to hear anyone's honest feedback about it and possible areas of improvement. Additionally, could anyone suggest any other notable academic sites where I can publish my paper?

https://www.academia.edu/123663289/Computational\_Physics\_Collision\_Project

/r/Python
https://redd.it/1fd9k40
What job boards do you use?

I've been looking for a senior Django (also Flask or FastAPI) dev for a couple of months now and the quality of candidates I got was abysmal.

So I'm wondering if I'm using the wrong channel (Linkedin). Where do you guys typically look for jobs?

/r/django
https://redd.it/1fdd99j
Issue: Microsoft SSO Integration State Mismatch (Django + Azure App Service)

I’m working on integrating Microsoft SSO into my Django app (hosted on Azure App Service). The SSO login flow seems to work up to the point where the callback is received, but I’m consistently encountering a "State Mismatch" error. I’ve tried multiple solutions, and I’m hoping someone could help me resolve this issue.

# Django & Azure Configuration:

Django version: 5.0.6
Python version: 3.12
SSO Integration Package: `django-microsoft-sso`
Azure App Service: Hosted with App Service Plan for deployment.
Time Zone: Central Time (US & Canada) on local development and UTC on the Azure server.
Session Engine: Using default Django session engine with database-backed sessions (django.contrib.sessions.backends.db).

ERROR 2024-09-09 14:12:40,723 - State Mismatch. Time expired?

INFO "GET /microsoft_sso/callback/?code=... HTTP/1.1" 302 0

DEBUG views Login failed at 2024-09-09 19:xx:xxpm: Displaying login_failed page.

DEBUG views Session ID during login_failed: None

DEBUG views Session contents during login_failed: {}

DEBUG views CSRF token during login_failed: None

SSO Callback Code:

import logging

import os

import binascii

from django.contrib.auth import login

from django.shortcuts import redirect, render

from django.urls import reverse

from django.conf import settings

from django.contrib.auth.models import User

from django.utils.timezone import now

logger = logging.getLogger(__name__)

def microsoft_sso_callback(request):

logger.debug(f"Start Microsoft SSO login. Current Server Time: {now()}")

# Retrieve the state from the callback and session

state = request.GET.get('state')

session_state = request.session.get('oauth2_state')

logger.debug(f"Received state in callback: {state}")

logger.debug(f"Session state before validation: {session_state}")

logger.debug(f"Session ID during callback: {request.session.session_key}")

logger.debug(f"Session contents during callback: {dict(request.session.items())}")

#

/r/djangolearning
https://redd.it/1fd83fu
Seasoned Developers: What does you .gitignore look like?

Help a novice out. When building with Django, what are the essentials to add to a gitignore file before pushing to remote?

/r/django
https://redd.it/1fdigtr
A web UI for SQLAlchemy to integrate into your web apps

# What my project does

I was missing a UI to visualize my DB schema, quickly check what's in the DB, see the migrations, etc. So you know what happened next :S

I created a very simple PoC to visualize the tables and relationships of a DB, later I'm planning data visualization and alembic migrations view/management/don't know possibly some git integration to check for DB changes on other branches. The idea is to integrate the UI into your existing web application, for the moment I only support FastAPI and Starlette:

pip install dbstudio

from dbstudio.fastapi import getfastapirouter

app = FastAPI()
app.mount("/dbstudio", getfastapirouter(engine))

Link to repo: https://github.com/lucafaggianelli/dbstudio

# Target Audience

The project is meant to be used during development and not in production as an admin panel or whatever

# Comparison

I was inspired by Prisma, an ORM for NodeJS that ships with its own Studio and ChartDB a tool to visualize DB schemas offline running a SQL query, I didn't find much for the SQLAlchemy world only sqladmin for FastAPI, but it doesn't show the DB schema, is more a data editor and some projects for Flask.

The alternative is to use tools like DB browser for

/r/Python
https://redd.it/1fdje37
I made an app to visualize H1B visa data

Inspired by a post in another subreddit so I made this webapp in Flask. You can query and visualize data from H1B visa applications. So far I've only included roughly 9 months data there. It shows that "Web Devs" average salary is only $68k, even behind English teachers lol.

https://preview.redd.it/p6q2cqi2j1od1.png?width=901&format=png&auto=webp&s=f779706cf85a14c3684852daae12daa85974114a

https://urchin-app-qdr2l.ondigitalocean.app/by-soc-occupational-title

Still very early prototype as you can tell and don't even have a domain yet.

Really love Flask for it's simplicity and extensibility, I can see myself sticking to Flask most of time.

Happy to hear your thoughts & questions!

/r/flask
https://redd.it/1fdrx9q
Best Django Courses

I am a Senior Frontend Developer with +7 years. The company I am already working has a Tech Stack with Django.

One of my mission is getting certificate related to our tech stack. I want to learn Django with advanced backend concepts because it is opportunity for me.

I know that the best way to learn a new technology is reading and applying the docs. But my company rule is collecting certificate as well.

What are your suggestions in this point? Which courses do you suggest to me? Thanks in advance 🖖

/r/django
https://redd.it/1fds72q
Wednesday Daily Thread: Beginner questions

# Weekly Thread: Beginner Questions 🐍

Welcome to our Beginner Questions thread! Whether you're new to Python or just looking to clarify some basics, this is the thread for you.

## How it Works:

1. Ask Anything: Feel free to ask any Python-related question. There are no bad questions here!
2. Community Support: Get answers and advice from the community.
3. Resource Sharing: Discover tutorials, articles, and beginner-friendly resources.

## Guidelines:

This thread is specifically for beginner questions. For more advanced queries, check out our [Advanced Questions Thread](#advanced-questions-thread-link).

## Recommended Resources:

If you don't receive a response, consider exploring r/LearnPython or join the Python Discord Server for quicker assistance.

## Example Questions:

1. What is the difference between a list and a tuple?
2. How do I read a CSV file in Python?
3. What are Python decorators and how do I use them?
4. How do I install a Python package using pip?
5. What is a virtual environment and why should I use one?

Let's help each other learn Python! 🌟

/r/Python
https://redd.it/1fdwqji
Dict Hash: Efficient Hashing for Python Dictionaries

# What My Project Does

Dict Hash is a Python package designed to solve the issue of hashing dictionaries and other complex data structures. By default, dictionaries in Python aren’t hashable because they’re mutable, which can be limiting when building systems that rely on efficient lookups, caching, or comparisons. Dict Hash provides a simple and robust solution by allowing dictionaries to be hashed using Python’s native hash function or other common hashing methods like sha256.

It also supports hashing of Pandas and Polars DataFrames, NumPy arrays, and Numba objects, making it highly versatile when working with large datasets or specialized data structures. Of course, the package can hash recursively, so even dictionaries containing other dictionaries (or nested structures) can be hashed without trouble. You can even implement the Hashable interface and add support for your classes.

One of the key features of Dict Hash is its approximated mode, which provides an efficient way to hash large data structures by subsampling. This makes it perfect for scenarios where speed and memory efficiency are more important than exact precision while maintaining determinism, meaning that the same input will always result in the same hash, even when using approximation. Typically we use this when processing large

/r/Python
https://redd.it/1fdkpkz
Ive been working with Django professionally for a couple years now so Ive decided to make my home office more comfy!

/r/django
https://redd.it/1fdvkv0
cannot import apps.views

i am developing a django app to analyze some log files and extract data and store it to the sqlite database.one of the tasks i need is to monitor a txt file where the log lines are being written by my syslog server.for the same purpose i developed a watchlog file,which will keep monitoring this file.this setup works very well in pycharm.but when i want to install the watchlog.py file as a windows service i get an error which says cannot find module.this is the import :


files is an another app in my django project.

from files.views import uploadlogfilewithoutrequest

https://preview.redd.it/wln0z8nk15od1.jpg?width=449&format=pjpg&auto=webp&s=992e6faffc122d50a8869e0c5e06aaf0820ccea5

https://preview.redd.it/yju8tvml15od1.png?width=374&format=png&auto=webp&s=d9e3939f428adbba49c99e4635a4033c1159ec32



/r/djangolearning
https://redd.it/1fe4xnz
Implementing Python Bindings for Dust DDS with PyO3

Hi everyone! 👋

I recently wrote an article for my company on how we created Python bindings for our native Rust implementation of the Data Distribution Service (DDS) middleware, called Dust DDS.

While the article isn't exclusively about Python, it dives deep into the process of using PyO3 for binding Rust to Python, going through the design decisions we made and how we programmatically generate the pyi file from the original Rust API. I thought it might be helpful or inspiring for anyone looking to bridge Rust and Python in their projects so you can check it out here: https://www.s2e-systems.com/2024/09/11/dust\_dds\_python\_bindings/

/r/Python
https://redd.it/1fe4w3m
Migrations

My company is making something i think it's stupid,

They don't track migrations with git, and in every environment stage, prod, local

They make migrations and migrate with every push

And every environment have different files

Is that fuckin normal, or this company is a shit? Cause i feel like I'm stupid

/r/django
https://redd.it/1fe603z
My first open-source project built with Python to inspect databases through CLI fast

What My Project Does:

peepDB is a CLI tool designed for rapid database table inspection without writing SQL. It supports MySQL, PostgreSQL, and MariaDB, allowing users to view all tables or a specific table with simple commands. The tool securely stores connection details, provides output in formatted table or JSON format.

Target Audience:

peepDB is aimed at developers debugging database-driven applications, DBAs performing quick checks or audits, data analysts exploring table structures, and those learning about databases who want an easy way to explore data. It's suitable for use in both development and production environments, providing a versatile tool for various database inspection needs.

Comparison:

peepDB distinguishes itself from alternatives by focusing solely on quick table viewing, supporting multiple databases out-of-the-box, and securely storing connection details. It requires no SQL knowledge to use, has a minimal footprint compared to larger database management tools, and offers both CLI and Python library interfaces for flexibility.

GitHub Repo: https://github.com/evangelosmeklis/peepdb
if you have any suggestions for the project or comments on how to improve let me know

/r/Python
https://redd.it/1febbx0
Integrating Stripe with Flask: A Step-by-Step Tutorial

I recently put together a beginner-friendly tutorial on how to integrate Stripe into your Flask application. If you're looking to implement payment processing but feel a bit overwhelmed, this guide breaks down the steps in a straightforward manner.

One of the key aspects of the tutorial is setting up user authentication to manage payments and subscriptions securely. We cover everything from user registration and login processes to implementing Stripe subscriptions and webhooks for handling payment events.

Additionally, you'll find snippets of code provided, which you can use as a handy template. By the end of it, you'll be equipped to start monetizing your Flask app with Stripe.

Here's what you can expect from the post:
- Setting up Stripe and your Flask app environment.
- Implementing user authentication using Flask-Login.
- Creating a checkout session for subscriptions.
- Handling webhooks to update subscription status in your database.
- Differentiating between free and premium content based on user subscriptions.

You only need a Stripe account to get started. For anyone interested, check out the full guide here: Integrating Stripe with Flask

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