Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
Independent lambda functions and Django

Hi all, I’ve tried researching this question but I can’t seem to find an answer so any help appreciated!

Background:

I currently have multiple Lambda functions that gather data from various sources and save them to a s3 bucket (currently as parquet). All are on cron schedules and deployed to aws.

At the same time I’m creating a Django app to use this data as part of a larger crud app. Am using RDS (MySQL)

I want to update the lambdas to save the data directly to the RDS in the format of the Django models.

Can I insert the data directly to RDS independent of Django or do I need to somehow integrate Django models to the lambda?

Or any other suggestions feel free to raise!

Thanks 😊



/r/django
https://redd.it/1ctvush
Trying to Publish my Flask API on Postman

I'm trying to publish my Flask API on Postman but I'm not sure if I need to host the API on a hosting service before I can do that. Most tutorials I've seen are not working on the localhost so I'm not sure how to go about it.
I know this is supposed to be on the postman sub-reddit, but the sub-reddit is not active

/r/flask
https://redd.it/1cu37d6
Homoiconic Python Code

Homoiconic, what does it mean? In simple terms, homoiconic code is when code is treated as data and can be manipulated as you would data. This means the code can be changed, new functions and variables added, the code can generate new code or even examine and modify its own structure and behavior all while it is running. That’s why homoiconic languages like Lisp are so powerful. But what if we can make a homoiconic python code, where the code and the data are one and the same and can be modified in the same way?

This guide does a good job in trying to explain how you would create a python version of the “Lisp in Lisp” code which would give you access to all those homoiconic features that Lisp brags of like the macro systems, the expressiveness and flexibility, the metaprogramming etc. while still using python. What do you guys think of this?

/r/Python
https://redd.it/1cu2bpv
sjvisualizer: a python package to animate time-series data

What the project does: data animation library for time-series data. Currently it supports the following chart types:

* Bar races
* Animated Pie Charts
* Animated Line Charts
* Animated Stacked Area Charts
* Animated (World) Maps

You can find some simple example charts here: [https://www.sjdataviz.com/software](https://www.sjdataviz.com/software)

It is on pypi, you can install it using:

`pip install sjvisualizer`

It is fully based on TkInter to draw the graph shapes to the screen, which gives a lot of flexibility. You can also mix and match the different chart types in a single animation.

Target audience: people interested in data animation for presentations or social media content creation

Alternatives: I only know one alternative which is bar-chart-race, the ways sjvisualizer is better:

* Smoother animation, bar-chart-race isn't the quite choppy I would say
* Load custom icons for each data category (flag icons for countries for example)
* Number of supported chart types
* Mix and match different chart types in a single animation, have a bar race to show the ranking, and a smaller pie chart showing the percentages of the whole
* Based on TkInter, easy to add custom elements through the standard python GUI library

Topics to improve (contributions welcome):

* Documentation
* Improve built in screen recorder, performance takes a hit when using the built in screen recorder
*

/r/Python
https://redd.it/1cu4epm
Custom MultiInput Model Field by Extending the JSONField in Django

Hi all,

I'm trying to create a custom field for volume made up of 4 parts (length, width, height and units). I'm thinking that extending the models.JSONField class makes the most sense.

Does anyone have any experience with doing this or another suggestion on how to achieve the same result?

I've implemented what I think is correct. However, I keep getting this error:

`TypeError: Field.__init__() got an unexpected keyword argument 'encoder'`

Below are the relevant project files.

inventory/models.py

from django.db import models
from tpt.fields import VolumeField

class Measurement(models.Model):
volumne = VolumeField()

tpt/fields.py

from django.db import models
from tpt import forms

class VolumeField(models.JSONField):
description = 'Package volume field in 3 dimensions'

def __init__(self, length=None, width=None, height=None, units=None, *args, **kwargs):

self.widget_args = {


/r/djangolearning
https://redd.it/1ctmhu0
The best Python CLI library, arguably.

What My Project Does

https://github.com/treykeown/arguably

arguably makes it super simple to define complex CLIs. It uses your function signatures and docstrings to set everything up. Here's how it works:

Adding the `@arguably.command` decorator to a function makes it appear on the CLI.
If multiple functions are decorated, they'll all be set up as subcommands. You can even set up multiple levels of subcommands.
The function name, signature, and docstring are used to automatically set up the CLI
Call arguably.run() to parse the arguments and invoke the appropriate command

A small example:

#!/usr/bin/env python3
import arguably

@arguably.command
def somefunction(required, notrequired=2, others: int, option: float = 3.14):
"""
this function is on the command line!

Args:
required: a required argument
not_required: this one isn't required, since it has a default value
others: all the other positional arguments go here


/r/Python
https://redd.it/1cu6toc
MySQLdb.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)") when I try to access my Flask CRUD app on Ubuntu server with nginx and gunicorn

Inside an Ubuntu server, I have my codebase for my flask CRUD app as well as a mysql database

Here's the code I am running to integrate the database to my flask app:

from flask_mysqldb import MySQL

app.config['MYSQL_HOST'\] = 'localhost'

app.config['MYSQL_USER'\] = 'root'

app.config['MYSQL_PASSWORD'\] = 'new_password'

app.config['MYSQL_DB'\] = 'crud'

mysql = MySQL(app)


When I try to run, the app locally on the ubuntu server, using the line python3 flaskappmysql.py, there seems to be no problem AT ALL.

However, when I access it thru the hosted IP address 172.xx.xxx.xxx, I get this kind of error:

MySQLdb.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")

What do I need to do to fix this problem? I provided correct mysql credentials and can't seem to diagnose what's wrong.

/r/flask
https://redd.it/1cube0z
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/1cuk3zp
Paying gig: need someone to write a python script for a public art project.

If you are available for a couple of hours of script creation and editing let me know. Shouldn’t take much longer as it a simple project using a raspberry pi, a button on a GPIO board, and a microphone.

Details: This is one giant game of telephone.
Essentially, someone leaves a message and the next person that hears the message replies to it, and the game continues.

When a user picks up the phone (depresses a button) they will hear instructions on what to do. then the most recent message is played and a
'beep' noise indicating it's time for them to record their response. They then hang up the phone and the process starts over.

This process is run through a raspberry pi using python script and a telephone that has a microphone to record the audio and a speaker to play the audio back. It utilizes a GPiO board for for a button that acts as the phone receiver.


All audio messages are saved to the raspberry pi storage. Only the most recent message is played back to the newest user.

/r/Python
https://redd.it/1cujgwk
Mastering Python: 7 Strategies for Writing Clear, Organized, and Efficient Code

Optimize Your Python Workflow: Proven Techniques for Crafting Production-Ready Code

Link

/r/Python
https://redd.it/1cuqmmh
How to Prevent Overlapping Async Tasks When Using APScheduler with asyncio in Python?

I'm using APScheduler to schedule jobs that call various webhook functions asynchronously. However, I'm encountering an issue where overlapping tasks cause errors, particularly the Task got Future attached to a different loop error. This happens because APScheduler jobs might run at the same time, leading to multiple async tasks being scheduled on different event loops.



import asyncio
import logging
import traceback

channeltowebhooks = {
"channelA": "webhookurlA",
"channel
B": "webhookurlB",
"channelC": "webhookurlC",
}

async def webhook
funcA(webhookurl, args):
async with aiohttp.ClientSession() as session:
await webhook.send(content=args.get("message))

async def webhookfuncB(webhookurl, args):
pass

async def webhook
funcC(webhookurl, args):
pass

def callwebhook(channelname, args):


/r/django
https://redd.it/1cuts96
My first 2 flask sites

Been building sites with flask

https://youcodeme.com
https://chatgod.co.uk

YouCodeMe my company I’ve been setting up as I’m wanting to try earn some money by making websites for small local businesses.

ChatGod is a site I’ve been building alongside YouCodeMe to not only have something to showcase on the main site as a portfolio, but also because I wanted to make this app for a long time just for fun and figured it could generate me something, even if it’s just peanuts.

It’s an Artifical Intelligence chatbot that ‘can answer any question’. So you can ask it what you are wearing and it will actually tell you. Or ask who the person sitting next to you is, and it can tell you. There’s some real trickery going on to make it actually work, it’s not pervasive in any way. All my friends and family that I’ve used it on have all been super thrown with it and asking how does it know lol so I’m really excited to be able to release the full version once I’m sure everything is perfect ready to go.

The sites at the moment are for the most part incomplete. But full versions are already on my local system. I’m just perfecting and

/r/flask
https://redd.it/1cv0x5n
Tutorial: Simple Pretty Maps That Will Improve Your Python Streamlit Skills

Interactive web applications for data visualization improve user engagement and understanding.

These days, Streamlit is a very popular framework used to provide web applications for data science.

It is a terrific programming tool to have in you Python knowledge toolbox.

Here’s a fun and practical tutorial on how to create a simple interactive and dynamic Streamlit application.

This application generates a beautiful and original map using the prettymaps library.

Free article: HERE



/r/Python
https://redd.it/1cuyivc
Deploying Django backend + React frontend on Vercel / Render

Does anyone know of / have a tutorial or step-by-step guide for deploying a Django backend and React frontend on Vercel / Render? Both communicate through the Django serializer (API).

Thank you.

/r/django
https://redd.it/1cv20ln
confusion in using urls.py

I am pretty confused in usage of urls.py in project and app. I only knew to use of urls.py in project but not in app. Can anyone explain me the different and their usage. And suggest me how the usage of urls.py in app will be done.

/r/djangolearning
https://redd.it/1cv73ut
Extract text color from ocr

Im currently working on a project, requiring to perform ocr on images , extract texts and do some processing, and sticht it back again

Using keras ocr / easy ocr ive successfully did that now challenge is to make look & feel in original state ,

Im redrawing text using pillow , where u can supply font and color

Ive tried , doin cv2. Kmeans to get dominant color from roi of text im replacing , but due to less dpi and pixelated quality , dominant color is not actual font color

Is there a way to get text color from ocr ??

/r/Python
https://redd.it/1cv8ueo
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/1cvay3b
Picodi - Simplifying Dependency Injection in Python

# What My Project Does

[Picodi](https://github.com/yakimka/picodi) is a lightweight and easy-to-use Dependency Injection ([DI](https://en.wikipedia.org/wiki/Dependency_injection)) library for Python. Picodi supports both synchronous and asynchronous contexts and offers features like resource lifecycle management. Think about Picodi as a decorator that helps you manage your dependencies without the need for a full-blown DI container.

# Key Features

* 🌟 Simple and lightweight
* 📦 Zero dependencies
* ⏱️ Supports both sync and async contexts
* 🔄 Resource lifecycle management
* 🔍 Type hints support
* 🐍 Python & PyPy 3.10+ support

# Quick Start

Here’s a quick example of how Picodi works:

import asyncio
from collections.abc import Callable
from datetime import date
from typing import Any
import httpx
from picodi import Provide, init_resources, inject, resource, shutdown_resources
from picodi.helpers import get_value


def get_settings() -> dict:
return {
"nasa_api": {
"api_key": "DEMO_KEY",


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