pythondaily | Образование

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

Подписаться на канал

Python Daily

I am in love with Django

Originally I am a data engineer with 4 years of experience. For some side projects I started developing Django around 2 years ago from now. Currently I am developing a yoga education platform for my wife. I feel like I really started to grasp the principles behind the framework. And I realized how all the framework is in harmony with SOLID principles.

I am really enjoying every piece of work I had so far. And I am totally in love with the framework.



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

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

Python Daily

Event Driven Architecture

I'm planning to adopt an event-driven architecture (EDA) for our backend services to improve inter-service communication and system scalability. I'm considering using domain events and a message bus(probably NATS). Does anyone have experience with implementing EDA in Python? Are there any specific libraries or frameworks you'd recommend? Also, what are some common pitfalls to avoid during the transition?"
 We have a mix of “microservices” and services that form a distributed system that is dependent on each other.What is lacking is an existing, reliable way for implementing asynchronous inter-service communication by adoption of an EDA . Right now the services talk to each other directly . For a majority of the communication, we’ve utilized REST. The challenge with REST is that it implements a response pattern that tends to couple services together . So I am hoping the domain events should be able to offer a standardized schema for domain events using a schema with each service having the capability to extend as desired. Also a way to view and keep track of events and their associated side effects in the services (An Eventory). For messaging bus should be able to support distributed messaging patterns as well offer high

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

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

Python Daily

Some thoughts on omegaconf and hydra

I recently finished a tutorial on using omegaconf and hydra for ML projects. At the beginning, I thought "okay sure this is nice, a flexible way of specifying config options either in a yaml file or at the command line". By the end, we had developed a complex ML project where we configured different tasks, datasets, training options, optimizers and evaluation settings, all via these nested folders & yaml files, in order to demonstrate hydra's composition, class instantiation, and interpolation abilities. At this point though, all I could think is, "this just feels like learning another programming language" and moreover...why not just do this all in native python to begin with? I was just left feeling rather unclear on what this solves / makes easier?

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

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

Python Daily

ShareLMAPI: Local Language Model API for Efficient Model Sharing Across Devices and Programs

# What [ShareLMAPI ](https://github.com/starpig1129/ShareLMAPI)Does

ShareLMAPI is a local language model API that allows **sharing model weights across multiple programs on the same device** and supports **cross-device API calls**. Its goal is to reduce resource consumption by avoiding the need to load models multiple times for different processes or devices. Some of its key features include:

* **Local server and client**: The server allows managing model settings, API configurations, and dynamic model loading. The client supports setting various generation parameters when making API calls.
* **Streaming output support**: For real-time tasks, the API can stream responses, improving efficiency for interactive applications.
* **Supports advanced model loading**: It can load models using techniques like BitsAndBytes and PEFT for efficient handling of large language models.
* **API token-based authentication**: Secures both local and cross-device access to the API.
* **Environment setup with Conda and Docker**: Provides an easy way to manage the environment and deploy the API using containerization.

# Target Audience

This project is aimed at developers and AI practitioners who work with large language models and need a solution to **share models efficiently across applications** on the same device or across multiple devices in a local environment. It is designed for **local deployment** and can be used in small-scale

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

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

Python Daily

Does Flask support Asynchronous Programming?

I'm working on a project with flask and thought about adding making the project asynchronous with asyncio because i take the queries from a search engine (like google, duckduckgo,etc). But as far as i've seen this is not possible with flask as of now. (I am using python 3.10) and flask = 3.0.3

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

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

Python Daily

Open-sourced FastAPI reference architecture

We just open sourced the reference architecture we use for FastAPI projects here.

Would love to discus different ideas and approaches as this is going to be a living document.

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

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

Python Daily

How does Flask actually run in practice? Question about how the code actually executes when deployed.

I'm writing a simple app with Flask that I want to deploy and I'm confused about how this actually runs when it's been deployed. I have a strong feeling this is a case of me not knowing what questions I need to ask/"I don't know what I don't know."

I want to deploy this using Google App Engine because it seems very user-friendly and I'm a noob, and I found an excellent tutorial on how to deploy there and it seems like a perfect fit for my project.

I want the code within the for-loop to be run once per day, not when a user accesses the website - this is the issue that's leading me into confusion.

Here's my code and my questions are at the bottom. Thanks in advance for your help :)

from flask import Flask, rendertemplate
from getshows import get
shows
import pandas as pd
from time import sleep
from datetime import datetime


app = Flask(name)

# declare the global variable for storing show info

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

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

Python Daily

Is it bad to display primarykeys on the client side?

Let's say I put the primary\
key of an object inside of the URL or inside a hidden form field of, as an example, a form that deletes an object selected by the user. In that case, the user would be able to access it very easily. Is it a bad thing to do and why?

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

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

Python Daily

P I built a live AI sports commentator that can talk in any language


It detects key frames in the video and talks without prompting. In the backend, I use Whisper for STT, Gemini Flash for vision and ElevenLabs for voice.

Demo: https://www.veed.io/view/b19f452b-9589-4270-b11f-e041f2065713?panel=share

GitHub: https://github.com/outspeed-ai/outspeed/tree/main/examples/sports\_commentator

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

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

Python Daily

Fantasy Premier League - Mini-League History

**Repo/Dashboard Links:**

* [Github Repo Link](https://github.com/EdwardAnalytics/fpl-league-history)
* [Streamlit dashboard Link](https://fpl-league-history.streamlit.app/)

**What My Project Does:**

The FPL League History dashboard creates tables for FPL leagues showing past winners, and team records. This data is not available directly on the FPL league website, and utilises the FPL API to create it.

**Features**

* Allows user to input specific league ID to get historical data from the FPL API
* Creates a Streamlit dashboard which is hosted on the Streamlit Community Cloud
* There's also a script to generate it as a dashboard with Dash
* A caveat is that it looks at who is in the league at the moment, and looks back at their past season records.
* It's for smaller sized leagues (up to \~100 teams max).

**Comparison**

* [https://www.livefpl.net/league\_history/](https://www.livefpl.net/league_history/) - Not the primary objective of the dashboard but it does show individual season history. It does not show the summary aggregated stats (e.g. most winners etc.)

**Target Audience:**

* Fantasy Premier League players

Any feedback on the GitHub repo or dashboard would be appreciated!

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

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

Python Daily

PyTrilogy adds typing and a semantic layer to SQL

PyTrilogy lets you define strongly typed interfaces for your SQL (think TypeScript vs JavaScript) and directly write queries in that same syntax. It's written in Python and can be used from python directly or compile to SQL to be used by other tools. The unified model definition and query language means you can iterate on the model and your queries in realtime. It aims to be more concise, composable, and reusable than SQL, without sacrificing the best parts of the language.

# What My Project Does

* Provides a lightweight, SQL-like language for defining a semantic layer and writing queries against it
* Supports composing/reusing models and through a python-like import syntax
* Automatic join resolution that provides correctness across grains/aggregation/nulls
* Backends for compiling and executing against DuckDB, Bigquery, Snowflake, SQL Server
* Type-checking + other static validation to surface errors sooner in the development cycle

Links:

* [Interactive Demo/Docs](https://trilogydata.dev/)
* [Github](https://github.com/trilogy-data/pytrilogy)

# Target Audience

Do you work with data analytics and love the declarative nature of SQL, but hate some of the sharp corners? Trilogy's opinionated about a workflow where you get your data model accurate, and can then query expressively and confidently. It's not well suited to transactional work, and isn't an ORM.

Aspirationally, for professional data teams it

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

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

Python Daily

Haystack and Solr

Hello guys, this is just a general question, nothing specific. But I'm currently building a search engine for my Django project. My question is, are there any resources where I can Haystack coupled with Solr?

Anything would help, thank you. Please let me know if you need more details

company.py

from django.db import models
from django.conf import settings
from.user import User


# Create your models here.
class ArboristCompany(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, related_name='arborist_company')
arborist = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
company_name = models.CharField(max_length=30)
company_logo = models.ImageField(upload_to='company_logo', blank=True)

def __str__(self):
return f'{self.company_name} ArboristCompany'

```

arborist_model.py

from django.db import models
# Create your models here.
# Model Arborist
class Arborist(models.Model):
arboristcity = models.CharField(maxlength=30)
arboriststate = models.CharField(maxlength=30)
yearsexperience = models.CharField(maxlength=30)
price = models.IntegerField(null='True')

class Meta:
ordering = 'arborist_city',

/r/django
[
https://redd.it/1fnaae2

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

Python Daily

is oauth verification required if you're just using non sensitive scopes and want more than 100 users?

I am integrating oauth to my django project and I'm only using non sensitive scopes, also no brand logo or anything. It even says that no Verification is required for my app but still I'm seeing the 100 user cap there.

Edit: I forgot to mention, I'm using Google's OAuth consent screen

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

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

Python Daily

Hy 1.0.0, the Lisp dialect for Python, has been released

- Announcement post
- Official website
- Source code

# What My Project Does

Hy (or "Hylang" for long) is a multi-paradigm general-purpose programming language in the Lisp family. It's implemented as a kind of alternative syntax for Python. Compared to Python, Hy offers a variety of new features, generalizations, and syntactic simplifications, as would be expected of a Lisp. Compared to other Lisps, Hy provides direct access to Python's built-ins and third-party Python libraries, while allowing you to freely mix imperative, functional, and object-oriented styles of programming. (More on "Why Hy?")

Okay, admittedly it's a bit much to refer to Hy as "my project". I'm the maintainer, but AUTHORS is up to 113 names now.

# Target Audience

Do you think Python's syntax is too restrictive? Do you think Common Lisp needs more libraries? Do you like the idea of a programming language being able to extend itself with as little pain and as much flexibility as possible? Then I've got the language for you.

After nearly 12 years of on-and-off development and lots of real-world use, I think I can finally say that Hy is production-ready.

# Comparison

Within the very specific niche of Lisps implemented in Python, Hy is to my knowledge the most feature-complete and generally

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

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

Python Daily

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

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

Python Daily

Best way to approach this?

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

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

Python Daily

Flask at scale

I'm writing a Flask app in EdTech. We'll run into scaling issues. I was talking with a boutique agency who proclaimed Flask was/is a bad idea. Apparently we need to go MERN. The agency owner told me there are zero Flask webapps at scale in production. This sounded weird/biased... But now wondering if he has a point? I'm doing vanilla Flask with sass, Jinja and JS on the front. I run gunicorn and a postgresql with redis...

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

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

Python Daily

Connor: Fast and fully local NLP file organizer that organizes files based on their textual content

What **Connor** Does

Connor works locally on your computer using a pre-trained NLP model sentence-transformers/paraphrase-MiniLM-L6-v2 to understand the meaning of the data and calculate the cosine similarity between files. The folders are appropriately named using topic modeling through the Latent Dirichlet Allocation (LDA) technique.

Example of before and after running the app within a folder with bunch of files. you can see the tree structure for the same (the screenshot of the tree structure is from the app itself. It gets displayed while using the cli too).

Links: Repo and PyPI

End-user (you) can:

1. Organize files within a selected folder or manually uploaded files (uploading files is only supported for GUI).
2. Organize text-based files (.docx, .txt, .pdf, etc.) using NLP based on their content.

Customization Options:

1. Similarity Threshold: Allows yous to choose a similarity percentage threshold for grouping similar files.
2. Reading Word Limit: You can to set a limit on the number of words read from file content.
3. Folder Name Word Limit: You can specify a maximum number of words allowed in the created folder names.

Target Audience
Anyone who has a bunch of text-based files they need to organize based on content quickly.

Comparison
Most file organizer sort the files based on their extension.

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

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

Python Daily

Django-Routify v0.2.5 stable release with Poetry support

**Django-Routify** is a package for simple routing Views in the classic Django framework.

Downloads last week on PyPi: 400+
Stars in GitHub: 8

With Django-Routify package you no longer have to manually register your views in urlpatterns using django.urls.path function.

Django-Routify can help you to easily register your views using Router class and his @Router.route(...) decorator.

Also you can set auto_trailing_slash to True value when you're initializing your Router and can write your url_path similar to Flask, FastAPI etc.

If auto_trailing_slash is True then url_path which will be equal to '/hello-world' will be translated to classic Django url rule - 'hello-world/'.


**Detail example**

Registration views with Router

Including router's pathes to urlpatterns




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

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

Python Daily

Help with code optimisation for my DigitalOcean droplet

Hello, I am quite new to Flask and all, and currently I made a Flask App that OCR's and Parses some information for me. For OCR I am using easyocr and for parsing I am using openai API, I deployed it by the 1gb RAM, basic droplet plan from DigitalOcean with Nginx and Gunicorn, but even without curl post a single thing it's already on Max Memory and CPU usage.


I'll paste my code down here and any suggestions would be appreciated, if it's better to upgrade my DO plan or if by optimizing the existing code might be enough. Thanks in advance:

# Initialize the Flask app
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'uploads'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB

# Set up rate limiting
limiter = Limiter(
get_remote_address,
app=app,
default_limits=["1000 per day", "100 per hour"]
)

#

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

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

Python Daily

I just made my own game!

Rock 🪨 Paper 📄 Scissors ✂️


It’s for a class I’m taking… and I built in a loop where the game will continue until it completes a best of five and then exits automatically!!

I’m so excited. Haha

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

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

Python Daily

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

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

Python Daily

Simplify OAuth2 token capture in your Django apps without the overhead of django-allauth.

Hey everyone,

I’m glad to share `django-oauth2-capture`, a Django package designed to simplify the process of capturing OAuth2 tokens for non-login purposes.


**Why did I create this?**

While working on projects that require acting on behalf of users on external platforms like GitHub, LinkedIn, and X (Twitter), I found that existing solutions like `django-allauth` weren’t suitable. `django-allauth` is fantastic for authentication and user management, but using it solely for token capture without user authentication feels like working against the grain of both the framework and the package. It introduces unnecessary complexity when you just need to obtain an OAuth2 token.


**What does** `django-oauth2-capture` **offer?**

By removing unnecessary abstractions, the complexity of handling OAuth2 melts away into **three important flows**:

1. **Initiate OAuth2 Authorization**: Start the authorization process with the external platform.
2. **Handle the Callback and Capture the Token**: Receive the token securely without extra overhead.
3. **Refresh Tokens as Needed**: Maintain token validity seamlessly.

This streamlined approach makes it easier to integrate with various external platforms without the bloat.


**Why is this important?**

This package is a cornerstone of all my **LLM (Large Language Model) projects** across healthcare, finance, publishing, and sh*t-posting. It enables these applications to interact with external services efficiently and securely.


**Check it out on GitHub:**

[github.com/heysamtexas/django-oauth2-capture](https://github.com/heysamtexas/django-oauth2-capture)

I'm still

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

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

Python Daily

I've just released v1.0.0 of my first Django package!

Hi everyone! 👋

I've been working with Django for the last 5 years and I've finally released my first package! It is called [django-auto-actions](https://github.com/Flexonze/django-auto-actions).

By adding it to your ModelAdmins, it will automatically generate basic Django admin actions based on your models' fields. For example, if your model has a nullable `is_approved` BooleanField, it will create the following admin actions:

* Set *is\_approved* to True
* Set *is\_approved* to False
* Set *is\_approved* to None

Right now, it works with **BooleanFields**, **DateTimeFields**, **DateField** and **TimeField**.

This idea came to me because of a client who kept asking me for a way to bulk update a bunch of objects. I had to create very similar admin actions for each time. I figured I'd extract this logic into a more generic mixin that would work with every model. I then decided to make a package out of it.

I would **LOVE** for you to try it and give me some feedback. Thanks in advance!

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

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

Python Daily

A PyQt TodoMVC cross-OS desktop app

https://github.com/Jeff-Mott-OR/pyqt-todomvc

What My Project Does and A brief comparison: From project’s readme:

> In the spirit of TodoMVC, I used PyQt (Python + Qt) to create a cross-OS desktop todo app. And I used the fman build system (aka fbs) to package the Python runtime and the Qt library binaries into a standalone executable and installer for each of the big three OSes.

> But why?
For fun and no profit. When I learned C++, at first I put off learning a GUI library. But I was interested in and always meant to learn the Qt GUI library. It lets you write desktop GUIs once that will look native for each of the various OSes. Later, after I did a hobby project in Python, I stumbled upon PyQt -- a project that exposes the Qt C++ library in Python -- and I decided to dive in.

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

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

Python Daily

ComiQ: Comic-Focused Hybrid OCR Library


What My Project Does:

ComiQ is an advanced Optical Character Recognition (OCR) library specifically designed for comics. It combines traditional OCR engines like EasyOCR and PaddleOCR with Google's Gemini Flash-1.5 model to provide accurate text detection and translation in comic images.

Features

Hybrid OCR approach for improved accuracy of Bounding Box of Comics
Utilizes Gemini Flash-1.5 model, for fixing errors generated by the OCR Engines.
Gemini Flash-1.5 model, which is free, and allows 1,500 requests per day(As of 23-09-2024).
Specialized in detecting text within comic bubbles and panels
Support for multiple OCR engines
Easy-to-use Python interface

Comparison

[Speech-Bubble-Aware-Automatic-Colorization](https://github.com/Rabbit1010/Speech-Bubble-Aware-Automatic-Comic-Colorization) : Has Downside of Mis-Detection of Text Bubbles, and Does not Extract Text.
Bubble-Detector-YOLOv4 : Has Downsides, with detection of Directional Text, and Background text bubble, and also dosen't extract Text

Capabilities

Please Visit the [Examples](https://github.com/StoneSteel27/ComiQ/tree/main/examples) Section in the GitHub Page.

Target Audience:

ComiQ, was built for people, who wants to extraxct text and process from Comics image,


Your Feedback, and advice are welcome 😊

Github: https://github.com/StoneSteel27/ComiQ

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

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

Python Daily

Monday Daily Thread: Project ideas!

# Weekly Thread: Project Ideas 💡

Welcome to our weekly Project Ideas thread! Whether you're a newbie looking for a first project or an expert seeking a new challenge, this is the place for you.

## How it Works:

1. **Suggest a Project**: Comment your project idea—be it beginner-friendly or advanced.
2. **Build & Share**: If you complete a project, reply to the original comment, share your experience, and attach your source code.
3. **Explore**: Looking for ideas? Check out Al Sweigart's ["The Big Book of Small Python Projects"](https://www.amazon.com/Big-Book-Small-Python-Programming/dp/1718501242) for inspiration.

## Guidelines:

* Clearly state the difficulty level.
* Provide a brief description and, if possible, outline the tech stack.
* Feel free to link to tutorials or resources that might help.

# Example Submissions:

## Project Idea: Chatbot

**Difficulty**: Intermediate

**Tech Stack**: Python, NLP, Flask/FastAPI/Litestar

**Description**: Create a chatbot that can answer FAQs for a website.

**Resources**: [Building a Chatbot with Python](https://www.youtube.com/watch?v=a37BL0stIuM)

# Project Idea: Weather Dashboard

**Difficulty**: Beginner

**Tech Stack**: HTML, CSS, JavaScript, API

**Description**: Build a dashboard that displays real-time weather information using a weather API.

**Resources**: [Weather API Tutorial](https://www.youtube.com/watch?v=9P5MY_2i7K8)

## Project Idea: File Organizer

**Difficulty**: Beginner

**Tech Stack**: Python, File I/O

**Description**: Create a script that organizes files in a directory into sub-folders based on file type.

**Resources**: [Automate the Boring Stuff: Organizing Files](https://automatetheboringstuff.com/2e/chapter9/)

Let's help each other grow. Happy

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

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

Python Daily

Between Render platform and AWS

I’m working on my startup idea and wondering what is better option for me between render and aws.

Overall, render unload some parts of works and take care of it. On the other hand AWS looks cheaper, and once I have one web app deployed on AWS, I can just copy or replicate for another web app.

My question is Is AWS really cheaper with side project that hasn’t found PMF yet? How complex will it be to deploy on AWS instead of render. Anything particular I need to know about render?

I’m a backend engineer, learning frontend. My web app tech stack will be:

1. Django main framework
2. Either django celery for async task or another container to run long time async task
3. Influx database
4. Postgres database
5. uwsgi
6. Redis might or might not needed for celery
7. JavaScript
8. React
9. Cloudflare for DNS
10. TLS
11. Stripe payment
12. No other authentication needed as Django already has battery for authentication

I guess the render solves some problems like TLS and postgres, static site part… how about other parts and how hard will it be with AWS and their cost



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

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

Python Daily

Choosing the Right Authentication API for Django REST Framework
https://www.django-rest-framework.org

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

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

Python Daily

D Understanding 1.58-bit Large Language Models

Hi all, I wrote an arunnanda/understanding-1-58-bit-large-language-models-88373010974a">article about ternary (trinary) models to summarize what I read on the topic. It's more like a high level literature review. The target audience is the developer who is curious about the research but doesn't have the time to dig into the papers themselves. It is a free article on Medium.


Appreciate any feedback and inputs on it.

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

Читать полностью…
Подписаться на канал