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

UK: Python Developer job market? Is it worth it?

So i’ve been looking at a change of career and one that i’m currently exploring is in the IT industry as a developer.

Python seems to be the starting point for newbs so going down that route.

Looking at jobs in the UK though and theres 100’s of applications for each role. Is it a diluted market?

With no degree, i’d be looking to build my knowledge over the next 12-24 months in Python and create a couple of programmes to add to a portfolio.

Would I have any chance of getting a job in the industry with that alone?

Whats the market like in the UK for other developers? Is it a nightmare trying to find a job?

Is it all worth it?! 😵‍💫

Any help would be appreciated! TIA

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

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

Python Daily

I wrote some code that allow donations on a site. The first form allows you to input your email and the amount. The problem is in the first form I added the email and the amount to the db. But if I don't click pay in the second form the code is still added to the db. How do I fix this problem?

Here is the code.

app.py/routes.py

https://pastebin.com/NismhUbf

Here is the html. I did not include the success or failure page.

templates/stripe_payment/donations.html

https://pastebin.com/Hsr0YAVK

Here is a picture of the first form. https://imgur.com/a/ejBL7QL

Here is a picture of the second form https://imgur.com/a/Y98ahWu

models.py
https://pastebin.com/QU31ZCgi

forms.py + functions.py

https://pastebin.com/nFiCyYPQ

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

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

Python Daily

urlfor - rendertemplate generates .html

Hi everyone,

I'm currently having a big issue with Flask, and I can't seem to figure out what's going wrong. I've tried everything I can think of, but the problem persists. I'm hoping someone here can help me understand and fix this issue.

Problem Description:

I have a Flask application with the following route definitions in my app.py:

pythonCode kopierenfrom flask import Flask, rendertemplate

app = Flask(name)

@app.route('/')
def index():
return render
template('index.html')

@app.route('/blog')
def blog():
return rendertemplate('blog.html')


In my index.html template, I have a link that should direct users to the blog page:

<!-- index.html -->
<a href="{{ url
for('blog') }}" class="xx">View Blog</a>


The Issue:

When I load the index page in the browser, the {{ url_for('blog') }} is being resolved to blog.html instead of /blog. This means the generated HTML looks like this:

<a href="blog.html" class="xx">View Blog</a>

So when I click on the link, it tries

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

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

Python Daily

I'm learning Flask from Miguel grinbergs forum but feel overwhelmed and don't know how to learn properly.

I'm stuck like the 5th chapter but not it just feels like I'm learning to learn i feel like I won't remember anything what did you guys do.

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

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

Python Daily

Escaping from Anaconda

Sometime a friendly snake can turn dangerous.

Here are some hints

Escaping from Anaconda

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

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

Python Daily

An open-source platform for Django developers to build and share profit. What do you think, guys?

Hi Django Community!




Following my post yesterday about finding a fellow Django dev co-founder, I was amazed by the incredible response from developers worldwide. This inspired me to propose a larger idea: What if we created a platform specifically for Django developers to collaborate on profitable projects? Like "Tinder but for builders who match over an idea"

Here's the concept:

\- A free platform where specifically for Django developers ( for now) can share and browse project ideas

\- Developers can choose projects that interest them and find like-minded collaborators

\- Revenue sharing would be transparent and based on repository contributions and git commit.

\- The platform itself would be open-source, built by the community for the community

I'm looking for team members to help build this platform, specifically:

\- A technical lead/CTO with strong full-stack experience and software architecture expertise

\- 2-3 additional contributors interested in building the foundation

If you're interested in joining this initiative, please comment below with:

\- Your role preference (Tech Lead or Contributor)

\- Your experience level with Django

\- Time you can commit weekly

What do you think about this idea? Would this be valuable for our Django community?

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

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

Python Daily

Just released: Django Lazy Admin Pagination – Speed up your Django admin!

Hey everyone! 👋

I just launched **Django Lazy Admin Pagination**, a package that makes navigating large datasets in Django admin way faster by loading total counts lazily and updating pagination with AJAX.

# Why use it?

Speed: No more waiting for records count for page loads when working with big datasets.
Easy to use: Just pip install, add to INSTALLED_APPS, and extend your admin with LazyLoadPaginationMixin.

Perfect for any dev dealing with data-heavy Django projects. Check it out and let me know what you think!

Hey everyone! 👋

I just launched Django Lazy Admin Pagination, a package that makes navigating large datasets in Django admin way faster by loading total counts lazily and updating pagination with AJAX.

# Why use it?

Speed: The Django admin panel can be painfully slow when counting total records, especially if you have complex get\_queryset joins. This package skips that full count initially, making things load way faster.
Easy to use: Just pip install, add to INSTALLED_APPS, and extend your admin with LazyLoadPaginationMixin.

Perfect for any dev dealing with data-heavy Django projects. Check it out and let me know what you think!

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

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

Python Daily

Is Flask effective for a production server-sent-events running on a single machine?

@app.route('/stream')
def notifications_stream():
def notifications():
pubsub = redis_conn.pubsub()
pubsub.subscribe("notifications")
for message in pubsub.listen():
yield 'data: {}\n\n'.format(message['data'])

return Response(stream(), content_type="text/event-stream")

If I run a Flask app that contains the route above, among other routes, will it not block the application, let's say, on 1000 requests, even if I run Gunicorn with multi-threaded workers? Assuming 10 workers, each with 10 threads.

I need clarification on the matter to aid in my development.

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

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

Python Daily

Mega Flask Tutorial - best way to query and display this many-to-many relationship

I'm in a strange situation where as I fixed the issue while typing up this question. However, I'd like to know if my solution can be improved.

I've just completed the Followers section and part of the Pagination section of the Flask Mega Tutorial.

In addition to Users, Posts and followers, I've also added Tags. Each post can have multiple tags (many-to-many relationship). I've bridged Posts & Tags with a post_tag association table that contains the foreign keys Tag.id and Post.id.

To display the tags for each post, I have a method called get_tags() in Post. Let's say the page can display up to 20 posts per page (for development purposes, this is currently set to 3). For each post, I therefore query the database once for the tags with get_tags() and this doesn't sound very efficient (here's the visual if it helps). Is this considered bad, what's the usual way of getting posts and its associated tags?

I have pages which display only posts by one user and pages which can display posts from different users.

Here's are the relevant models from models.py (and sorry if the identation is wildly bad - I'm having some issue with VSCode where it won't let me indent

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

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

Python Daily

Beating the Dino Game with ML

# What My Project Does

Beats the dinosaur game with AI

# Target Audience

Not meant for any real life usage. Mainly just a side project, and hopefully a nice resource for someone trying to do something similar.

# Comparison

Performs quite poorly when compared to other libraries out there like TensorFlow.

# Other Details

Made with python from scratch(no ML libraries) to beat the dinosaur game. More details on my blog: https://matthew-bird.com/blogs/Dino-Game-ML.html

GitHub Repo: https://github.com/mbird1258/Dino-Game

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

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

Python Daily

Introducing screenman, a tool to setup the screen layout depending on the connected screens

My first attempt at a python package: screenman.

# What My Project Does

I was missing a tool that could match screen layout configurations to the connected screens so I decided to write one.

With screenman, I can easily switch between different screen layouts depending on the screens I have connected with a keyboard shortcut.

# Target Audience

Anyone that moves between different, fixed screen setups and wants to easily switch between them.

# Comparison

You can of course do this with xrandr and a shell script, but I wanted something that I can map to a single keybinding.



Any feedback is welcome!



GitHub repo: https://github.com/Jimmy2027/screenman



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

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

Python Daily

Sunday Daily Thread: What's everyone working on this week?

# Weekly Thread: What's Everyone Working On This Week? 🛠️

Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!

## How it Works:

1. Show & Tell: Share your current projects, completed works, or future ideas.
2. Discuss: Get feedback, find collaborators, or just chat about your project.
3. Inspire: Your project might inspire someone else, just as you might get inspired here.

## Guidelines:

Feel free to include as many details as you'd like. Code snippets, screenshots, and links are all welcome.
Whether it's your job, your hobby, or your passion project, all Python-related work is welcome here.

## Example Shares:

1. Machine Learning Model: Working on a ML model to predict stock prices. Just cracked a 90% accuracy rate!
2. Web Scraping: Built a script to scrape and analyze news articles. It's helped me understand media bias better.
3. Automation: Automated my home lighting with Python and Raspberry Pi. My life has never been easier!

Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟

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

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

Python Daily

Separating music into notes and instruments (audio source separation)

# What My Project Does

A basic program I made to turn music into sheet music(almost). Works by recreating the Fourier transform of the music by adding together the Fourier transforms of instrument samples and comparing the envelope of the instruments to the note being played. More details on my blog: matthew-bird.com/blogs/Audio-Decomposition.html

# Target Audience

Not meant for any real life usage. Mainly just a side project, and hopefully a nice resource for someone trying to do something similar. Might also be useful for music transcription.

# Comparison

Compared to other methods out there, I think this project holds up pretty well. Most sites on the internet also seem to use AI instead of a blind source separation algorithm.

# Other Details

Instrument samples from University of Iowa Electronic Music Studios: https://theremin.music.uiowa.edu/mis.html

GitHub Repo: https://github.com/mbird1258/Audio-Decomposition

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

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

Python Daily

DRF + React setup

Hi folks, im about to start my first DRF api project with a React frontend. I like to deploy early, so just thinking about how to engineer the two.

Ill be using Railway. So do i push my backend api (with cors and settings done etc ) to one repo and then deploy that to one Railway container?

The push my React frontend to another repo/railway container, and use the URL of my api container to make calls to the api?

This is what ive done with React/Pocketbase in the past.



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

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

Python Daily

Best way to generate a single page PDF using selected items from current page in MkDocs

Let's say i have a page in MkDocs that has a several paragraphs of text together with a checklist.

I now want the user to be able to click a button, and generate a PDF with just the checklist on it. I do not want the paragraphs of text to print, and I want to be able to control how the checklist looks on paper vs the screen (e.g. change font font size).

Is there a tool or plug-in that would be suitable for this type of use case?

Thank you!

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

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

Python Daily

D How to visualize the effect of an LLM attention layer on a set of tokens with an image model

Is it possible to visualize how an LLM “imagines” a token before and after processing it through the attention layer by feeding the token embeddings into an image model? I understand you can't copy paste it over, but is there a way to capture the latent transformation caused by the attention layer and apply this transformation to the embedding space of an image model?

For example if i were to enter "poor man," into an LLM the embedding for "man" would shift toward "beggar" while entering "royal man" it could move closer to "king." I want to visualize that change. Then you could transfer the embedding for man to an image model and it would create the something like a beggar or a king in this example.

It could make a really cool visualization if you captured the transformation after each attention layer and made a video by interpolating each step.

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

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

Python Daily

pipe-operator: Elixir's pipe operator in Python

TLDR: pipe-operator is an open-source python package which brings similar features to elixir's |> tap then to Python, with 2 vastly different implementations. Because why not :D

\---

Hey there! Thought it might be of interest to some of you! I come from Python but lately I've been working with Elixir (mostly at work) and came to really enjoy its pipe operator |> and its related features like tap, then, and shortcut syntaxes. So I thought to myself: "could be fun to bring this to python". So I did, and the **pipe-operator** project was born.

# What My Project Does

It provides similar features to elixir |>, allowing you to chain operations without using intermediary variables. Through 2 very different implementations, you can pass the result of the previous expression as the first parameter of the next one.

As for those 2 very different implementation, they are:

A pythonic class-based one, which is fully compatible with linters and type-checkers
And an elixir-like one, with a syntax resembling elixir's, which will drive you linters mad

# Target Audience

I don't think anyone would be using this in production/work projects, but it can be a fun tool for developers' side projects who enjoy functional programming.

# Quick demo

Python implementation:



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

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

Python Daily

What programming language would you recommend I learn to make a inventory management/POS system for windows application and web based.



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

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

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

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

Python Daily

Built this over the weekend - Netflix Subtitle Translator

Motivation: Recently, I've found myself deeply immersed in Japanese movies, dramas, and web series. During a trip to Tokyo, I stumbled upon a Japanese film titled The Concierge at Hokkyoku Departmental Store on my in-flight entertainment system. It had English subtitles, and I was hooked – but unfortunately, I couldn’t finish it before the flight ended. When I got back, I was excited to find it available on Netflix Japan. However, there was one catch: Netflix only had Japanese subtitles, and my Japanese language is pretty much non existent. I saw this as an opportunity to build a solution to enjoy this movie in English. Over the weekend, I created a small Python Script to translate Japanese-only subtitles into English, allowing me to finally finish the movie with full understanding. This may not be the most scalable setup, but it does the job!

What does this project do ? : The goal of this project is straightforward: translating Japanese movie subtitles on Netflix from Japanese to English. The motivation came from a lack of available English subtitles, making this project both an interesting technical challenge and a useful solution for my specific needs. It’s currently set to Japanese -> English, but

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

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

Python Daily

The Practical Guide to Scaling Django
https://slimsaas.com/blog/django-scaling-performance

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

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

Python Daily

Code examples: building efficient REST APIs with Django

Recently I had to fix a couple django rest-framework APIs at work that were built as part of a MVP that could not scale properly, which got me thinking of writing a tutorial about different ways of writing APIs in Django.



I provided the dockerized examples that you can easily run, the README contains step-by-step changes I make to the API, starting with a toy example that struggles to return 100k rows in over 30 seconds, optimized down to under 1 second.


I know some of these are controversial opinions of Django, but I thought I'd share them any way, hopefully you pick up something useful. It's a work-in-progress, I plan to add comparison to a Django-ninja as well as backend written in pure Go, as I've come to like those two as well.

https://github.com/oscarychen/building-efficient-api

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

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

Python Daily

D Self-Promotion Thread

Please post your personal projects, startups, product placements, collaboration needs, blogs etc.

Please mention the payment and pricing requirements for products and services.

Please do not post link shorteners, link aggregator websites , or auto-subscribe links.

--

Any abuse of trust will lead to bans.

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.

--

Meta: This is an experiment. If the community doesnt like this, we will cancel it. This is to encourage those in the community to promote their work by not spamming the main threads.

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

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

Python Daily

Ididi, dependency injection, in a single line of code

Ididi is a pythonic dependency injection lib, with ergonomic apis, without boilplate code, works out of the box.

# What My Project Does

it builds a dependency graph based on your type hints, and inject those dependencies into corresponding classes/functions.

In the base case, all you need to do is to make a call to instance = ididi.solve(class) and you are done.

# Quick Start

Here’s a quick example of how idid works:

import ididi

class Config:
def init(self, env: str = "prod"):
self.env = env

class Database:
def init(self, config: Config):
self.config = config

class UserRepository:
def init(self, db: Database):
self.db = db

class UserService:
def init(self, repo: UserRepository):


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

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

Python Daily

Open source drone localization

# What My Project Does

Small open source project that performs basic localization using cameras I made as a fun project. Not the most accurate nor fast, but hopefully still a good proof of concept.

# Target Audience

Not meant for any real life usage. Mainly just a side project, and hopefully a nice resource for someone trying to do something similar.

# Comparison

The feature matching in the project is slower than other methods like SIFT, SURF, and ORB, but seems relatively similar in terms of accuracy.

# Other Details

I used raspberry pi 0ws with socket to send images to my computer, where it calculates the relative positioning. Also makes use of ADXL345 accelerometers for rotational invariance. More details including the shopping list on my blog: https://matthew-bird.com/blogs/Drone-Rel-Pos.html

GitHub Repo: https://github.com/mbird1258/Drone-relative-positioning

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

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

Python Daily

How to find a Django dev cofounder, ?

Hey , Everyone

I am very interested in starting several AI-related projects. LLMs APIs are amazing, and there are numerous B2C applications that can be developed, particularly in fashion or health.—specifically, I’m aiming to build 3 or 4 within a month. I have a background as a Flutter developer +Firebase, but I’m also quite skilled in Django and PostgreSQL. I would love to find a co-founder who shares my passion and is proficient in Django as well. Are there any communities where I can connect with fellow Django developers?
Share ideas, brainstorm ,build fast and monetize it a week?
Honestly, I always had this idea: why don't developers join together to build, monetize quickly, and share the profit?

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

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

Python Daily

How do I maintain consistent web socket connections in my Django app?

I'm developing a Django application that requires a persistent WebSocket connection to continuously fetch live data from a crypto market API. I need to keep this WebSocket connection active throughout the application's lifecycle to update my local data as new information arrives. This updated data will later be displayed on the front end, so I anticipate needing a separate WebSocket connection between the front end and back end (one connection for backend-to-crypto market API, and another for backend-to-frontend).

I'm new to this type of setup and would appreciate guidance on the best practices for implementing it. I've explored Django Channels, Uvicorn, and Daphne. Although Django Channels might be suitable for the frontend-backend WebSocket connection, I'm more focused on maintaining a robust event-loop structure for the backend-to-crypto API connection to ensure it remains alive and responsive. I'm considering building a custom event-loop manager to handle this, but I'm unsure if it's the best approach.

Could you suggest any established methods, libraries, or patterns for maintaining a continuous WebSocket connection for real-time data updates in a Django application?

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

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

Python Daily

Freeze Flask and Payment

Hi. I am currently creating static Flask websites and converting them to HTML files using Freeze Flask. I then host the websites on Bunny CDN. I create these websites for clients and one of my clients has requested a system to sell digital products. Does anyone know how I can accept payment?

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

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

Python Daily

Mesa 3.0: A major update to Python's Agent-Based Modeling library 🎉

Hi everyone! We're very proud to just have released a major update of our Agent-Based Modeling library: [Mesa 3.0](https://github.com/projectmesa/mesa/releases/tag/v3.0.0). It's our biggest release yet, with some really cool improvements to make agent-based modeling more intuitive, flexible and powerful.

## What's Agent-Based Modeling?

Ever wondered how bird flocks organize themselves? Or how traffic jams form? Agent-based modeling (ABM) lets you simulate these complex systems by defining simple rules for individual "agents" (birds, cars, people, etc.) and then watching how they interact. Instead of writing equations to describe the whole system, you model each agent's behavior and let patterns emerge naturally through their interactions. It's particularly powerful for studying systems where individual decisions and interactions drive collective behavior.

## What's Mesa?

Mesa is Python's leading framework for agent-based modeling, providing a comprehensive toolkit for creating, analyzing, and visualizing agent-based models. It combines Python's scientific stack (NumPy, pandas, Matplotlib) with specialized tools for handling spatial relationships, agent scheduling, and data collection. Whether you're studying epidemic spread, market dynamics, or ecological systems, Mesa provides the building blocks to create sophisticated simulations while keeping your code clean and maintainable.

## What's New in 3.0?

The headline feature is the new agent management system, which brings pandas-like functionality to agent handling:

```python
# Find

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

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

Python Daily

Project Idea, Is this worth doing?

hi, my name is Joel , I am a uk based software engineer.

I have been working on an idea, using JS and a REST API in Django. the general gist of it is that it is using the canvas and added in functionality to allow users to design a functional webpage where they can choose buttons and redirects make queries and send and receive data, and use stripe to sell subscriptions or products. Basic website stuff. the webapp would include this, but also a team dashboard and hub for people to collaborate and find people who would be interested in making these webpages for business purposes. I'm thinking of letting the custom webpages leverage google maps for increased utility. I also would like to add GPT assistance features for if people want to use them on there custom webpages

Is this all too much for one application? any feedback would be appreciated.

I'm also open to any interested to help me out on what's left of the project, I have no qualms sharing credit or anything thereafter

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

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