Daily Python News Question, Tips and Tricks, Best Practices on Python Programming Language Find more reddit channels over at @r_channels
Multiple domains and allowedhosts
I built a landing page app with different domain for each page, stored in a model with domain as a field. Is there a way to dynamically create ALLOWED\HOSTS in settings? I have tried this and it doesn't work because models have loaded yet. I want to avoid having a giant list of domains in my settings file and redeploying every time that needs to change. I would rather add LandingPages in the django admin and have it update allowed hosts automatically.
ALLOWEDHOSTS = list(LandingPage.objects.valueslist('domain', flat=True))
/r/django
https://redd.it/1gvth59
moka-py: A high performance caching library for Python written in Rust with TTL/TTI support
Hello!
I'm exited to share my first Rust lib for Python — [moka-py](https://github.com/deliro/moka-py)!
# What My Project Does
**moka-py** is a Python binding for the highly efficient [Moka](https://github.com/moka-rs/moka) caching library written in Rust. This library allows you to leverage the power of Moka's high-performance, feature-rich cache in your Python projects.
# Key Features:
* **Synchronous Cache:** Supports thread-safe, in-memory caching for Python applications.
* **TTL Support:** Automatically evicts entries after a configurable time-to-live (TTL).
* **TTI Support:** Automatically evicts entries after a configurable time-to-idle (TTI).
* **Size-based Eviction:** Automatically removes items when the cache exceeds its size limit using the TinyLFU policy.
* **Concurrency:** Optimized for high-performance, concurrent access in multi-threaded environments.
* **Fully typed:** mypy/pyright friendly. Even decorators
# Example (`@lru_cache` drop-in replacement but with TTL and TTI support):
```
from time import sleep
from moka_py import cached
@cached(maxsize=1024, ttl=10.0, tti=1.0)
def f(x, y):
print("hard computations")
return x + y
f(1, 2) # calls computations
f(1, 2) # gets from the cache
sleep(1.1)
f(1, 2) # calls computations (since TTI has passed)
```
# One more example:
```
from time import sleep
from moka_py import Moka
# Create a cache with a capacity of 100 entries, with a TTL of 30 seconds
# and a TTI of 5.2 seconds. Entries are always removed after 30 seconds
# and are removed after 5.2 seconds if there are
/r/Python
https://redd.it/1gvnsoh
Django Rest Framework Multiple Instance Creation tip
/r/django
https://redd.it/1gvnosg
Created an AI Research Assistant that actually DOES research! one query FULL document of knowledge!
Automated-AI-Web-Researcher: After months of work, I've made a python program that turns local LLMs running on Ollama into online researchers for you, Literally type a single question or topic and wait until you come back to a text document full of research content with links to the sources and a summary and ask it questions too! and more!
What My Project Does:
This automated researcher uses internet searching and web scraping to gather information, based on your topic or question of choice, it will generate focus areas relating to your topic designed to explore various aspects of your topic and investigate various related aspects of your topic or question to retrieve relevant information through online research to respond to your topic or question. The LLM breaks down your query into up to 5 specific research focuses, prioritising them based on relevance, then systematically investigates each one through targeted web searches and content analysis starting with the most relevant.
Then after gathering the content from those searching and exhausting all of the focus areas, it will then review the content and use the information within to generate new focus areas, and in the past it has often finding new, relevant focus areas based on
/r/Python
https://redd.it/1gvlzax
I'm stucking in installing numpy
Hello everyone , im trying to install numpy library on my terminal and always i face a problem on installing backend dependencies, i try to solve this problem by adding cmake to my system path and the c/cpp compiler and the problem continue , then i try installing .whl files of numpy and still the same problem , can anyone here have a solution for this problem .
/r/Python
https://redd.it/1gvkpbm
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/1gvbziu
Is this a good production setup?
I've just finished deploying my project on Digital Ocean and would like to hear your opinion on the way I've done it and if this is a production-friendly setup. Any feedback is welcome but please be nice as this is my first run-in with this amount of devops.
The application is a bookings management SaaS for small businesses to manage (calendar view) and sell (online store) their experiences (Surf camps, Yoga camps, Wellness retreats, etc)
The stack is a Django app with AlpineJs for frontend all within the same project + Postgres + Redis + Celery.
I set up my Django project with cookiecutter-django from the two scoops guys and for local dev I'm using Docker.
So for local Dev I use Docker and run all these services in one container.
On Digital Ocean I decided not to use Docker and to go for their App Platform app (Django app) + Managed Database (Postgres) + Managed Cache Database (Redis) + Spaces (Static) + App (Celery Worker).
The DO enviroment is connected to my Github where when I'm ready to deploy my local changes I push my local changes using git and DO rebuilds and deploys automatically.
The main reason I
/r/django
https://redd.it/1guuq8b
Build a fraud detection app with AI
Hi,
Our boss just wrote an article about creating a fraud detection app using AI in Python: https://taipy.io/blog/building-fraud-detection-applications-with-taipy
Reviews are welcome.
/r/Python
https://redd.it/1gux1d4
Joe: writing a Django mini-clone article series
Hey all!
I've written a series of article that go through the process of building a minimal Django clone, which I hope could be a useful learning resource.
https://artoale.gitlab.io/joe
Feedback welcome!
/r/Python
https://redd.it/1gutct7
D What’s the most surprising or counterintuitive insight you’ve learned about machine learning recently?
ML often challenges assumptions. What’s something you learned that flipped your understanding or made you rethink a concept?
/r/MachineLearning
https://redd.it/1gujfj2
Using Python's pathlib module
I've written a hybrid "why pathlib" and "pathlib cheat sheet" post: [Python's pathlib module\](https://www.pythonmorsels.com/pathlib-module/).
I see this resource as a living document, so feedback is very welcome.
/r/Python
https://redd.it/1guhphv
On Ajax what is the prefer way to get the CSRFTOEKN?
const csrfToken1 = document.cookie
const csrfToken2 = document.getElementsByName('csrfmiddlewaretoken')
From top snippet, what is the convention/prefer way to get the csrf\token? Any suggestion will be greatly appreciated. Thank you.
/r/djangolearning
https://redd.it/1guni1v
Basic Components: Server-Side UI Components for Python Web Apps (Feedback Appreciated)
Hi everyone! 👋
I'm excited to share a project I've been working on called Basic Components, which ports shadcn/ui component to the Python/Jinja.
# What My Project Does
Basic Components is a collection of reusable, server-side UI components built with JinjaX, htmx, and Alpine.js and Tailwind CSS. It's a port of shadcn/ui to Python/Jinja. It allows you to build dynamic, responsive web applications using Python web frameworks like FastAPI, Django, and Flask.
Key Features:
Copy/Paste Components: No package to install; simply copy the components you need into your project.
Full Customization: Complete control over the components to modify and extend as needed.
Tailwind CSS Styling: Styled using Tailwind CSS utility classes for consistent and rapid UI development.
Accessibility-First Design: Components are built with accessibility in mind, based on shadcn/ui.
Dark Mode Support: Built-in theming with light and dark modes.
Markup Compatibility: The component markup is the same as in shadcn/ui, making it easy to adapt and integrate.
# Target Audience
This project is intended for Python web developers who prefer a server-first architecture and want to build modern, interactive web applications without relying heavily on client-side JavaScript frameworks.
# Comparison to Existing Alternatives
While there are many frontend component libraries available for JavaScript frameworks like React or Vue,
/r/Python
https://redd.it/1gue0s5
difficulty with flask-login
I'm a beginner in Flask, and I think I didn't find this information in the documentation, or I may not have understood/read it correctly.
But, I'm having the following problem:
I can log my user into my application, everything works perfectly, but if I type the /login page again, it is accessed, even though the user is already authenticated. Is there a way that when the user is already logged in, the login page is not accessed and redirects to the home page, for example?
I would be very grateful to anyone who can help.
/r/flask
https://redd.it/1gtqpy0
For those of you that purchase templates online, is there a better way to edit the files to run it in flask?
I purchased a Bootstrap template online today and started to hack away at it to make it work with a website I am building with Flask. This involves rearranging files, folders and more annoyingly, going through all the links in the HTML that refer to images, css, js, and other HTML pages in the project and editing them with the {{ url_for('static', filename='...'}}
code Jinja expects.
Is there a better way to do this or is this just one of those annoying initial setup things that I need to do manually?
/r/flask
https://redd.it/1gtv56b
Running 24/7 chromedriver python script
Hello guys,
I was wondering if its possible to run a python script using a chromedriver on a AWS script service, or do I need to use a VPS ? This is simple task, no huge traitment.
Thanks !
/r/Python
https://redd.it/1gvq8z2
Migrating from black and flake8 to ruff
as the title says, so i'm currently working on a relatively huge python/django codebase, built over the course of 6 years, which has been using black and flake8 for formatting and linting in pre-commit hook, both have their versions unupdated for about 3 years, now i have a somewhat difficult task on hand.
the formatting and linting engine is to be moved to ruff but in such a way that the formatting and linting changes reflected in codebase due to ruff are minimal, i can't seem to figure out a way of exporting either configs from black and flake8 in their current state so i can somehow replicate them in ruff to control the changes due to formatting. if anyone has been in a similar situation or know any potential way i can approach this, that would greatly help. cheers!
pre-commit-config.yaml (in its current state, as you can see versions are a bit older)
repos:
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
/r/Python
https://redd.it/1gvnfvi
Boiler plate for flask back end.
I am looking for Flask boiler plate for creating backend services. I am exploring cookie cutter but it seems old. Is any other updated resource available ?
/r/Python
https://redd.it/1gvjp8p
I am thinking of making a tool script that makes it easier for linux admins
To many commands is a pain to recall the switches and so on. Anyone know of any shell script that can provide a menu then sub-menu of options?
/r/Python
https://redd.it/1gvhb2h
Has anyone here built a profitable side project with Django or created one for a client that generates profit?
Hi everyone,
I’m curious to hear from those who’ve created side projects using Django. Have any of you built something that turned out to be profitable, either as a personal project or for a client?
I’m working on a side project myself using Django and DRF, mainly focusing on the backend. While I enjoy the process, I’m also wondering about the potential for turning it into something financially viable.
Thanks in advance for sharing your experiences! I’m hoping this inspires ideas and helps me (and others) approach these projects with a more practical perspective.
/r/django
https://redd.it/1gv7q2v
Retro Terminal Chatbot (GLaDOS)
Hey everyone! I’d like to share a Python project I’ve been working on for a while now. It’s a chatbot based on GLaDOS from the Portal games, with a retro-style terminal interface and her iconic voice. I think any portal fans among you will enjoy it.
# What My Project Does
GLaDOS-Terminal is a fully interactive chatbot experience that brings the personality of GLaDOS to life.
Chatting: The responses are generated using the llama3.2:3b model, giving her personality depth and sarcasm that feels true to the original character.
Voice Synthesis: Her iconic voice is recreated using custom fine-tuned Tacotron 2 and HiFi-GAN models that I developed specifically for this project.
UI and Visuals: The terminal is built using pygame combined with a custom moderngl shader, inspired by the retro visuals from the Portal end credits and [this ](https://github.com/Swordfish90/cool-retro-term)project.
# Target Audience
This project is mainly for:
Portal fans who want a chance to talk to GLaDOS (or at least her chatbot counterpart).
Developers or Python enthusiasts who are curious about integrating AI models, custom shaders, and real-time voice synthesis.
Anyone looking for a cool and unique chatbot experience.
Right now, this is more of a showcase or experimental project since it’s somewhat technical to set
/r/Python
https://redd.it/1gv92l4
Keeping large data available to all users in memory
Not quite sure if this is the correct subreddit for questions like this, but here I go:
I'm currently building a website where I each day want yesterday's financial data cached in memory for the full day, to be quickly available to all users (note that this data is incommon for all users, and can be quite big at ~50 MB). I also want to cache older data on request, e.g. if a user looks at data for some date in 2023, I also want to cache that, although for a shorter time (say maybe 1 h).
Being new to Django, I've tried to read up on the different caching solutions that Django offers, but I'm a bit confused as to which would server me well.
* Does Django offer an existing solution fit for this purpose?
* Would it be easier to set up a manual pure python caching process, which fetches cached data if it exists, and otherwise retrieves and caches it for a specfied time period?
* Can this be solved by simply attaching the data to a middleware instance? Not quite sure how long such an instance lives to provide the attached data.
Thank you!
/r/django
https://redd.it/1guu1t8
Data Visualization Project.
Hi, i need to create a wep app whit streamlit to present some data. I just want to do somthing not boring. Any suggestion on how to create some dataset or some nice dataset?
/r/Python
https://redd.it/1guws6z
Rewriting 4,000 lines of Python to migrate to Quart (async Flask)
Talk Python rewritten in Quart (async Flask)
Here's a massive write up of why over at Talk Python we rewrote our website and why we chose Quart (async Flask). Lots of lessons here if you're choosing a framework for a project or considering rewriting your own.
/r/Python
https://redd.it/1gulzjt
I'm pretty lost on how to setup a full app from scratch.
I work at a software house, Im a junior developer (5months of experience). My first project had 2 seniors and plus 2 juniors besides me, I did all kind of tasks most of it creating views to do CRUD on django. My perfomance overall was pretty good, and when things got reallly ugly the senior always came in to solve it (for example we had a lot lot lot of problems with migrations, ppl running migrations on productions instead of local DB and etc.)
Given this context, whats happening now: I'm working at another project for this company, its a project from scratch and whats getting me desperate its I'm the only developer on the project. The PO of the project always says that his got react skills and always can help me on frontend ( I wont even speak how useless this help is, and every time he tries to help we got a new lib installed on the project that I have to study, so this is happening even tho in the start I tried to convice to use vanila JS since its a simple project but nah, we using react with a list of 10+ libs and
/r/django
https://redd.it/1gudped
Tuesday Daily Thread: Advanced questions
# Weekly Wednesday Thread: Advanced Questions 🐍
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
## How it Works:
1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.
## Guidelines:
* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.
## Recommended Resources:
* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.
## Example Questions:
1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the
/r/Python
https://redd.it/1gujmbz
If you use uv, what are your use cases for uvx?
I really love uv
as my new All-In-One tool for python project management.
I also really like the uv tool
functionality for tools I regularly use like Harlequin or my kanban/tasks apps kanban-python
and more lately the less minimal kanban-tui
.
But I it never really clicked for me when I would use uvx
which basically installs a tool temporary and after usage removes it again (though still cached, so future uses go faster).
Currently I am on my way to release v0.4.0 of kanban-tui with multi board support and board-individual columns. I develop those features in a new branch and just discovered that you can use something like:
uvx --from git+https://github.com/Zaloog/kanban-tui@lg/independent-board-columns ktui demo
uvx
, and what are your favourite tools to use with it?D Simple Questions Thread
Please post your questions here instead of creating a new thread. Encourage others who create new posts for questions to post here instead!
Thread will stay alive until next one so keep posting after the date in the title.
Thanks to everyone for answering questions in the previous thread!
/r/MachineLearning
https://redd.it/1gtgnk8
Support Python: Our End-of-Year Fundraiser with PyCharm Discount is live
Our end of year fundraiser and membership drive has launched! There are 3 ways to join in to support Python and the PSF:
- 30% off @PyCharm
from JetBrains
- Donate directly
- Become a member
Learn more
Python empowers you to build amazing tools, build/grow companies, and secure jobs—all for free! Consider giving back today.
/r/Python
https://redd.it/1gu7g70
Python Crash Course Notebook for Data Engineering
Hey everyone! Over the last 2 weeks, I put together a **crash course on Python** specifically tailored for Data Engineers. I hope you find it useful! I have been a data engineer for 4+ years and went through various blogs, courses to make sure I cover the essentials along with my own experience.
Feedback and suggestions are always welcome!
📔 **Full Noteboo**k: [Google Colab](https://colab.research.google.com/drive/1r_MmG8vxxboXQCCoXbk2nxEG9mwCjnNy?usp=sharing)
🎥 **Walkthrough Vide**o (1 hour): [YouTube](https://youtu.be/IJm--UbuSaM)
💡 Topics Covered:
1. Python Basics
* Syntax, variables, loops, and conditionals.
2. Working with Collections
* Lists, dictionaries, tuples, and sets.
3. File Handling
* Reading/writing CSV, JSON, Excel, and Parquet files.
4. Data Processing
* Cleaning, aggregating, and analyzing data with pandas and NumPy.
5. Numerical Computing
* Advanced operations with NumPy for efficient computation.
6. Date and Time Manipulations
* Parsing, formatting, and managing date time data.
7. APIs and External Data Connections
* Fetching data securely and integrating APIs into pipelines.
8. Object-Oriented Programming (OOP)
* Designing modular and reusable code.
9. Building ETL Pipelines
* End-to-end workflows for extracting, transforming, and loading data.
10. Data Quality and Testing
* Using `unittest`, `great_expectations`, and `flake8` to ensure clean and robust code.
1. Creating and Deploying Python Packages
* Structuring, building, and distributing Python
/r/Python
https://redd.it/1gu3her