pythondaily | Education

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

Subscribe to a channel

Python Daily

Can’t post my flask website online

Hi, I’m a somewhat experienced coder and I made a website that needed to be in flask to utilize a python library for scraping and to output data on the site. I work often with python but not much with websites so more issues are occurring than I expected.

I’ve been easily able to test and run the website in Pycharm on the local host but am struggling to upload it onto a website online so I can have other people look at it without making them download python and all that.

I’ve tried using python anywhere but the free version gave me a lot of issues and doesn’t offer enough storage for my site to be free. Is there any other free alternatives that aren’t too complicated for hosting?

Also one more note is Im struggling even to upload my pycharm project onto GitHub as “access to this site has been restricted”. So any help info there would be appreciated!

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

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

Python Daily

Store last_seen time before user is timeout in flask

Hello guys I need a bit of help with the community.

I have implemented a flask app where I keep track of my users loggin and loggout.

Everytime my user click on login or logout I have the time at which they did.

I also set my session to last 30 seconds to test

permanent_session_lifetime = timedelta(seconds=30)

I want to store the time right before my user is loggout of the session or before the timeout is reached can you help me please because some people forget to logout.

this is what I came up with but it's only working when I keep refreshing the page.

   
@app.route("/user", methods=["POST","GET"])
def user():
    if "user" in session:
        user = session["user"]
        users = User.query.filter_by(id=User_log.user_id).distinct().count()
        Number_of_connection = User_log.query.distinct().count()
        user_online = User_log.query.filter_by(status="on").
group_by(User_log.user_id).distinct().count()
     

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

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

Python Daily

Hardware requirements for a Flask web app

Hi all,

I am trying to determine the hardware specs that I am gonna need for my Flask app. The basics:

- Flask backend, the frontend is just html templates with bootstrap and tailwind, no framework is used. Some of the pages are loading simple JS scripts, nothing too fancy.

- The application consists of different functionalities, the main one - the users can solve coding exercises in Java, C#, Python or JS. The user writes the code in the application and then the solution is submited, a POST request containing the inputs and the expected outputs(taken from the database) + the actual code is being sent to another service - Piston API(Dockerized) which executes the code with the respective compiler/interpter and returns stdout/stderr/runtime, etc. The Piston API is running separatly from the actual app. In other worlds, the application is something similar to Leetcode, but very simplified version.

- The rest of the functionalities consists mostly of loading dynamic pages reading the user's data from Postgres database. Some of these pages have POST method forms, e.g. the user can update his own profile changing its email address, bio, etc. and executing write operations against the postgres db, but most of the transactions

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

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

Python Daily

Read .DBF tables and bring the data to the screen

Hello community, I'm new here and I need your help, I'm making an application that reads a specific table from a database and brings the data to the screen, it searches the table, recognizes it but doesn't bring the data to the screen, Could you give me any suggestions or help me with this?



Hello community, I'm new here and I need your help, I'm making an application that reads a specific table from a database and brings the data to the screen, it searches the table, recognizes it but doesn't bring the data to the screen, Could you give me any suggestions or help me with this?



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

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

Python Daily

In need of a kind soul

Hello everyone. I am a complete noob regarding backend trying to just teach myself to make fun projects as a hobby. But I've not been able to deploy any projects or even test it on a local host because no matter what I do the django wont render the templates or atleast that's what I think the problem is since I the page I get is the rocket saying Django is successfully installed and that I am getting that page since something is wrong or the debug = true which it is not. I've changed it a billion times. I've tried to fix my views.py and my urls.py and my settings.py a thousand times nothing works. I am sure that it is something anyone with basic django knowledge would be able to fix in a heartbeat but my flat head can't seem to figure it out. Thank you to anyone that takes the time out of their day to try to help me. I have the link to the directory here through GitHub: https://github.com/KlingstromNicho/TryingGPTIntegration/tree/main/sales\_analysis

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

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

Python Daily

Get lists from a form?

I want to have the user select colors from a form, then when I do "request.form'colors[']" I'd get a list of the checked/selected options

Ex
print(request.form'colors['])
Would either be a string like
"Red, Blue, Green"
Or
"Red","Blue","Green"


Does this come from the form itself? Or am I supposed to generate a list from a multitude of different fields that get combined in flask?

Is there a best practice for this sort of task?

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

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

Python Daily

I am finding the official docs of Django Rest Framework Overwhelming

I am constantly trying to grasp the idea about DRF from their docs but I am afraid and overwhelmed by the topics and languages used there. Most of the time when I sit to read certain topic and while reading the topic there comes another topic or feature which is new to me and I click into that link and the cycle repeats and I found myself to be lost.
If you are in the field of DRF, please suggest me how you get confidence at your initial days and what we're the strategies you used to grasp the good understanding over this framework.
Your suggestions would also mean another.
Thank you.

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

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

Python Daily

Add Item form django

https://redd.it/1fl9kd9
@pythondaily

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

Python Daily

Tips on structuring modern python apps (e.g. a web api) that uses types, typeddict, pydantic, etc?

I worked a lot on python web/api apps like 10-15 years ago but have mostly used other languages since then. Now I'm back to building a python app, using all the latest tools like type hinting, FastAPI, and Pydantic which I'm really enjoying overall.

I feel like code organization is more of a headache than it used to be, though, and I need better patterns than just MVC to keep things organized. E.g. a simple example - if I define a pydantic class for my request body in a controller file and then pass it as an argument to a method on my model, there's automatically a circular import (the model needs to define the type it takes as its argument, and the controller needs to import the model).

I know you can use "if TYPE_CHECKING" but that seems messy and it means you can't use the type at runtime to do something like "if type(foo) = MyImportedType".

What are some good file structure conventions to follow that make this easier?

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

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

Python Daily

SQLAlchemy Helper (for VS Code)

Hey guys, wanted to share this VS Code chat extension that makes it easier to use SQLAlchemy. It's basically a RAG system trained on SQLAlchemy's docs that developers can query through VS Code.

https://marketplace.visualstudio.com/items?itemName=buildwithlayer.sqlalchemy-integration-expert-jYSzG

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

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

Python Daily

🇧🇷 Marketplace de Veículos. Consegue me ajudar?

Fala galera, beleza?



Meu nome é João, e to desenvolvendo um Marketplace de Veículos. Obviamente pretendo atuar regionalmente a princípio, com plano de escalar pra nível estadual, a depender da adoção do mercado. Pra resumir bastante trabalho com revenda de veículos usados já tem uns 8 anos. Minha família empreende no ramo tendo mais duas outras empresas do mesmo nicho na nossa cidade, e eu recentemente (junho de 2022) abri a minha própria loja de motos. Diante dessa experiência prévia no mercado de revenda de veículos, ao observar o quanto do orçamento de marketing é direcionado pra esses marketplaces como WebMotors, iCarros, e muitos outros a nível regional do seu Estado, pensei: tem espaço pra mais um.



Não é uma ideia inovadora, nem disruptiva, é um mercado consolidado e validado com grandes players bem estabelecidos. Mas a depender da região e da abordagem de marketing e vendas, existe uma lacuna.



Vamos falar de desenvolvimento. Tenho uma pequena experiência com Flask, HTML, CSS, Bootstrap e JS. Já construí alguns projetos com essas tecnologias e me atenderam bem até onde precisei ir. Mas quando se trata de um marketplace de veículos com múltiplos usuários, múltiplas sessões simultâneas, alto volume de upload de imagens, eu sinceramente

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

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

Python Daily

Hello, any solution to this error?

https://preview.redd.it/16vnss1u1opd1.png?width=1920&format=png&auto=webp&s=d696e4e490922125618d1a8a4098e46107ffa7b2



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

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

Python Daily

Django unit tests are now supported in VS Code (1.93)
https://code.visualstudio.com/updates/v1_93#_python

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

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

Python Daily

D The autoencoder architecture for vision in 2024?

I’d like to train autoencoder on images to get useful latent representation, so I can later use it to train a diffusion and autoregressive model for image generation. What is the SOTA architecture I should pick?

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

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

Python Daily

Introducing FastAgency: the fastest way to deploy a console or web app from your AutoGen workflow

Hey everyone! I’m one of the core developers of **AutoGen**, a very popular open-source framework for developing AI agents with over 30k stars on GitHub.

I’ve been working with my team on an open-source project called **FastAgency**. We designed it to help developers quickly take a prototype built in AutoGen straight to production. We just released a version that lets you run your workflow as either:

A simple console application (great for debugging)
A web application using Mesop with just a single-line change!

We would love for you to check it out, give feedback, or contribute! The project is open-source, and contributors are always welcome :)

https://github.com/airtai/fastagency

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

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

Python Daily

ParLlama v0.3.8 released. Now supports Ollama, OpenAI, GoogleAI, Anthropic, Groq

# What My project Does:

PAR LLAMA is a powerful TUI (Text User Interface) written in Python and designed for easy management and use of Ollama-based Large Language Models as well as interfacing with online Providers such as Ollama, OpenAI, GoogleAI, Anthropic, Groq

# Key Features:

Easy-to-use interface for interacting with Ollama and cloud hosted LLMs
Dark and Light mode support, plus custom themes
Flexible installation options (uv, pipx, pip or dev mode)
Chat session management
Custom prompt library support

# GitHub and PyPI

PAR LLAMA is under active development and getting new features all the time.
Check out the project on GitHub or for full documentation, installation instructions, and to contribute: [https://github.com/paulrobello/parllama](https://github.com/paulrobello/parllama)
PyPI https://pypi.org/project/parllama/

# Comparison:

I have seem many command line and web applications for interacting with LLM's but have not found any TUI related applications

# Target Audience:

Anybody that loves or wants to love terminal interactions and LLM's

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

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

Python Daily

Ereddicator v3.1: A Python-based Reddit Content Removal Tool

What My Project Does:

Ereddicator is a Python script that allows you to selectively delete and/or edit your Reddit content: https://github.com/Jelly-Pudding/ereddicator/

Key features include:

Simple GUI
Selective Content Removal: Choose which types of content to delete, including:
Comments
Posts
Saved items
Upvoted content
Downvoted content
Hidden posts
Edit-Only Mode: For comments and posts, you can choose to only edit the content without deleting it. This may be desirable as Reddit is capable of restoring deleted comments.
Karma Threshold: You can set karma thresholds for comments and posts. Content with karma above or equal to the threshold will be preserved.
Subreddit Filtering:
Whitelist: Specify subreddits to exclude from processing.
Blacklist: Specify subreddits to exclusively process, ignoring all others.
Date Range Filtering: Set a specific date range to process content from, allowing you to target content from a particular time period.
Dry Run Mode: Simulate the removal process without actually making any changes. In this mode, Ereddicator will print out what actions would be taken (e.g. what comments and posts will be deleted) without modifying any of your Reddit content.


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

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

Python Daily

Updates to `django-nice` v0.5.0 🙂

Updates to[ version 0.5.0](https://github.com/rexsum420/django-nice)

Description of Updates and Extensions Made to the `django_nice` Library

The recent updates and extensions to the `django_nice` library have significantly increased its flexibility, allowing for more dynamic data binding and supporting complex use cases such as binding multiple fields to a single UI element, handling user-specific data dynamically, and enabling real-time updates with Server-Sent Events (SSE). Below is a detailed breakdown of the changes:

# 1. **Dynamic Binding with dynamic_query**

\*\*Previous Version:\*\*

* The library required a static \`object\_id\` to bind a UI element to a single field of a specific model instance.

\*\*Update:\*\*

* The \`bind\_element\_to\_model\` function now supports \*\*dynamic queries\*\* (\``dynamic_query`\` parameter), which allows model instances to be retrieved dynamically based on any criteria (e.g., a logged-in user's ID, the current high score, etc.).
* \*\*New Features:\*\*
* You can now bind UI elements to objects retrieved dynamically, without needing to know the \``object_id`\` in advance.
* This is useful for scenarios like binding a UI element to the current user's data or retrieving a model instance based on specific business logic (e.g., highest score).

\*\*Example:\*\*



bind_element_to_model(
element,
app_label='people',
model_name='Person',


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

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

Python Daily

Get clean markdown from any data source using vision-language models in Python

I have found that quality data preprocessing for LLMs from raw data sources can be an incredibly difficult task, so I'm sharing a new project I began working on this summer to solve this problem.

What My Project Does:

The package in question is an open-source project designed to simplify the process of scraping clean data from various sources (PDFs, URLs, Docs, Images, etc). Whether you're working with PDFs, web pages, or images, it can handle the extraction into a clean markdown format. Unlike traditional scraping tools, it is able to understand the context and layout of documents, thanks to vision-language models. It even handles complex tables and figures.

The beauty of The Pipe is that it's not just a black box. It's open-source so you can peek under the hood, understand how it works, customize it to fit your specific needs, etc. The Python library is quite thoroughly documented for this kind of stuff.

Comparison:

Look at existing Python packages for document scraping such as PyPDF2, Unstructured, PyMuPDF (fitz), PDFMiner, Tabula-py, Camelot, pdfplumber, and marker. While these tools are great at basic text extraction, they often struggle with more complex tasks like handling scanned PDFs, irregular data tables, tables that span multiple pages, and documents

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

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

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/1flq8cn

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

Python Daily

How to plan a new feature?

Iam a full-stack developer and every time I want to plan a new feature it feels very overwhelming and hard. Although my skills are way beyond this required feature yet I alwayys struggle. I read that I need to break the problem down but I don't know how to start thinking about breaking it.

Can you guys olease tell me if you yave experience how do you plan such feature. And if there are tools that help? Also shall I write pseudo code or it is not always a good idea?

Thanks in advance.

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

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

Python Daily

Simple Automation Script For Extracting Zip Files

**AutoExtract** is a Python-based tool that monitors a specified folder for ZIP files and automatically extracts them to a designated directory. It keeps track of processed files to avoid duplicate extractions and runs continuously, checking for new ZIP files at regular intervals.

**✅What My Project Does:**

* Monitors a folder for new ZIP files
* Automatically extracts ZIP contents to a specified location
* Keeps track of processed files to prevent redundant extractions
* Customizable folder paths and checking intervals

**✅Target Audience:**

This project is primarily intended for

* **Personal use**: Automate repetitive tasks such as extracting ZIP files from a specified directory.

**✅Comparison**

Compared to existing alternatives like desktop file managers with built-in extraction tools:

* **Simplicity**: Unlike GUI tools, this Python-based approach allows automation without manual intervention.
* **Customization**: Users can modify the folder paths, extraction logic, or check intervals, making it more adaptable than off-the-shelf solutions.

GitHub Link - [https://github.com/pratham2402/AutoExtract](https://github.com/pratham2402/AutoExtract)

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

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

Python Daily

I am overwhelmed by the django docs.

I am constantly trying to grasp the idea about DRF from their docs but I am afraid and overwhelmed by the topics and languages used there. Most of the time when I sit to read certain topic and while reading the topic there comes another topic or feature which is new to me and I click into that link and the cycle repeats and I found myself to be lost.
If you are in the field of DRF, please suggest me how you get confidence at your initial days and what we're the strategies you used to grasp the good understanding over this framework.
Your suggestions would also mean another.
Thank you.

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

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

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/1fkyw3m

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

Python Daily

Best way to eliminate or reduce redundancy in views?

I'm in the process of building a live chat using django\_channels and frontend as reactJS. In this project, I'm trying to be more familiar with class based views and utilize them as much as I can . The question that I have is what is the convention or best practice when eliminating or reducing redundancy in the views. I have three sets of snippets in the bottom and all of them are using .list() method to implement .filter(). Is there a way to reduce this or better way to this with less code? Any info will be greatly appreciated. Thank you very much.

class CommunityMessagesView(ListAPIView):
queryset = CommunityMessage.objects.all()
# authentication_classes = [TokenAuthentication]
# permission_classes = [IsAuthenticated]

def list(self, request, *args, **kwargs):
queryset = self.get_queryset().filter(community__name=kwargs['community_name'])
serializer = CommunityMessageSerializer(queryset, many=True)


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

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

Python Daily

Looking to hire Django developer with strong frontend skills

I run a med student education platform (Geeky Medics) built on Django with several hundred thousand users. You’re welcome to sign up and explore the app's various elements (app.geekymedics.com). I've been working on it for the last 14 years, alongside my training as a doctor.

We already have a couple of awesome, senior Django developers, but I’m looking for someone who is particularly strong in frontend development/UI/UX (even if junior from a Django perspective). 

Our stack is straightforward Bootstrap 5, JS and some recent sprinklings of HTMX (no fancy JS frameworks).

We’re fully remote and async. I'm looking for someone able to commit to 1-3 days a week, ideally. I'm happy to discuss rates, etc. You can message me with some details of your experience, and I’ll get back to you ASAP.  

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

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

Python Daily

I am using flask and bootstrap. I wondering, what is the best way to create admin features for flask?

Just to clarify I'm asking because I never built admin features before. I am just wondering what are the standard features.



I have a few options.



1)

I could use flask admin .

2)

Someone recommended this https://flask-appbuilder.readthedocs.io/en/latest/ .

3)

I could write the code myself the problem is I don't know all the features to implement.

I could write a wrapper like "@login_required" called "@admin_required". But like stated what other features should I add.

4)

An Alternative way.

If someone has any other suggestions for an alternative way please state them.

Thank you for the responses.











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

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

Python Daily

Django-Routify for routing your views in classic Django

Just dropped beta version for my own package which provide decorator routing for your views.

More details in PyPi:
https://pypi.org/project/django-routify/

I'll also appreciate for star in repo ;D

Simple example:

https://preview.redd.it/pa22t6540kpd1.png?width=1039&format=png&auto=webp&s=ae349c01d5e9d93dcfdbfa82176c5eab7aec7dc0

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

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

Python Daily

Space Invaders in Python - Tutorial

Hello friends!

There is a continuation of the game development series in Python. This time, it’s Space Invaders.

Space Invaders in Python for Beginners | Programming Basic Concepts (youtube.com)

Enjoy!

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

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

Python Daily

This is outrageous what do you do all day

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

Читать полностью…
Subscribe to a channel