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
ecommerce inventory data

curious to know if anyone here knows the architecture used to store inventory data of millions of products which is accessed by millions of users via frontend who shop at large ecommerce websites like amazon?

note that the inventory count field of these products is continually updated on the backend to reflect the most up to date information and data.

users shopping online via the frontend web or mobile app get the product data back instantly to add to their carts.

i was wondering what's the magic used to achieve this kind of performance for data that is also being constantly updated.

/r/flask
https://redd.it/1fb26q5
Streaming output from a chat-bot

I’m trying to make a Flask interface for an assistant I have created.

The assistant is setup correctly and streams output to a console perfectly. However, I am having a lot of trouble figuring out how to set up a Flask-app to stream the output for the chat bot correctly.

Does anyone have any examples of a Flask-interface with streaming that I could follow?

Here is the code that I have. It is working, but the streaming functionality is not. Instead of posting a chunk every time the assistant output is updated, it only posts chunks when the buffer limit is reached (several hundread words). Additionally, I have no idea how to integrate the streaming output into a typical chat-interface that shows the last few back-and-forths.

def chatstream():


# the chat
session contains assistantid, thread, and client instances
chat
session = currentapp.config['chatsession']

# using the stock event handler suggested here; https://platform.openai.com/docs/assistants/quickstart
handler = EventHandler()



/r/flask
https://redd.it/1farjm2
"detail": "No DocumentComment matches the given query." Django Rest Framework issue

In my modelviewset, I tried destroy function but it was not working, but when i tried to get object from id, it works, weird,. This is my viewset class.

class DocumentCommentView(viewsets.ModelViewSet):
   
    permissionclasses = (AdminStaffPermission,)
    queryset = DocumentComment.objects.all()
    serializer
class = DocumentCommentSerializer
   
    def getqueryset(self):
       
        document
id = self.kwargs.get('pk')
        if documentid :
            # print("ok ia m get")
            # breakpoint()
            return DocumentComment.objects.filter(document
id=documentid)
        return DocumentComment.objects.all()
   
    # def perform
destroy(self, instance):
    #     print("iam here")
    #     breakpoint()
    #     user = self.request.user
   

/r/django
https://redd.it/1faw8fr
Yes another question

when i try to run this command :
for label in labels:
!mkdir {'Tensorflow/workspace/images/collectedimages//'+label}
cap = cv2.VideoCapture(0)
print('Collecting images for {}'.format(label))
time.sleep(5)
for imgnum in range(numberimgs):
ret, frame =
cap.read()
imagename = os.path.join(IMAGES
PATH, label, label+'.'+'{}.jpg'.format(str(uuid.uuid1())))
cv2.imwrite(imgname, frame)
cv2.imshow('frame', frame)
time.sleep(2)

if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()

it shows this error:
The syntax of the command is incorrect.

Does anyone know why?

/r/IPython
https://redd.it/1fb6v04
Astral.sh (the company behind uv) paid product: is it going to be a Heroku replacement?

As you might know Astral, the company behind uv and ruff, are a small company but have venture capital funding. And right now they are not making money at all (but of course they're building awesome tools!)

I listened to the Talk Python podcast episode 476 where u/mikeckennedy & Charlie Marsh discuss the new capabilities uv has.

And it got me thinking, since uv is now able to install specific python versions, and since they stated they don't want to charge for features in uv ever, but are planning on charging for features adjacent to it that you might need to get your code up and running, could it be they'll be building a Heroku replacement? Certainly when you're wanting to build a Heroku-like thing it can be beneficial to allow users to specify their exact python version and have ways to install it.

I think it might be very cool and I'm sure there's a lot of opportunity in that space.

Does anybody know if Charlie Marsh or other Astral people ever discussed their plan to make money in more detail?

/r/Python
https://redd.it/1fbabmr
Send self-destructible emails

I've recently built a small free project called DiscardDraft.

Built with Flask and Nextjs. It's a project that allows people to send emails that would be deleted right after being read.

Check it out here: https://discarddraft.me


/r/flask
https://redd.it/1fanapo
Python 3.13 RC2 Available Today - Python 3.13 available October 1st

Python 3.13 will drop on October 1st.

The second release candidate just dropped today.

Don't be afraid to upgrade.

Install the RC2 from here and run your regression tests for your applications, and be ready to upgrade to Python 3.13 the moment it becomes available on October 1st.

If any of your dependencies fail when running your application on the RC2, immediately raise an issue on their github and complain loudly that they need to make the changes to make it compatible as well as publish binary wheels.


https://www.python.org/downloads/release/python-3130rc2/

/r/Python
https://redd.it/1fbb4qw
Issues with Cloud Run Deployment

I've been trying to solve this deployment issue for 2 days now and am at my wits end. I've deployed on VPSs before but never a managed service like Cloud Run.

All of my request coming from the frontend are getting the Network Error: ERR\_TOO\_MANY\_REDIRECTS. From what I've gathered, there is likely and issue with the way django is processing the internal request from Cloud Run. The google documentation says that we need to add this to our settings.py:

CLOUDRUN_SERVICE_URL = env("CLOUDRUN_SERVICE_URL", default=None)
if CLOUDRUN_SERVICE_URL:
ALLOWED_HOSTS = [urlparse(CLOUDRUN_SERVICE_URL).netloc]
CSRF_TRUSTED_ORIGINS = [CLOUDRUN_SERVICE_URL]
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")


I have added this and still continue to get these errors. I'm really not sure what else to look into or what could be causing this. I'm even will to pay you for your time if someone is willing to get on discord with me and help me work this out.

/r/django
https://redd.it/1fbcybz
Adding Python to Docker in 2 seconds using uv's Python command

Had great success speeding up our Docker workflow over at Talk Python using the brand new features of uv for managing Python and virtual environments. Wrote it up if you're interested:

https://mkennedy.codes/posts/python-docker-images-using-uv-s-new-python-features/

/r/Python
https://redd.it/1fb9qcy
How can I change the name options of this selectField based on which table was selected earlier in the form?

Edit: I fixed this issue by setting name = (column name) in each of the classes

-------------



Pretty much I am using a tutorial to make a form that will change possible selection option based on a previous selection. eg. a user chooses to see data filtered based on site and then have another dropdown with the possible site options.

the tutorial I am using uses only one table (see image one) but I have three different tables that need to be available for selection.

so far I have tried using both a variable and a function to do this but neither have worked. (the variable returned multiple selections of sites.site_name for each id in the table and the function returned multiples of <function results.<locals>.tableOptionName at 0x10e386e50>.

If it helps, the column that contains the names I am trying to display is the the second column the table for all three.

what I have at the moment is in image 2

image 1

image 2

Thank you so much!

/r/flask
https://redd.it/1fbhsk1
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/1fbku4v
Custom Template filters for global use

I am building a project and created a filter to format phone numbers. initially I created it inside one of my apps but decided since it could be use for the whole project to put it at project level but now its not working and giving me

TemplateSyntaxError at /
Invalid filter: 'formatphonenumber'


here is the file structure

projectManager/
β”œβ”€β”€ main/
β”‚ └── settings.py
β”œβ”€β”€ onboarding/
β”œβ”€β”€ templates/
β”‚ └── base.html
β”œβ”€β”€ templatetags/
β”‚ β”œβ”€β”€ init.py
β”‚ └── customfilters.py
β”œβ”€β”€ theme/
β”œβ”€β”€ unit/
└──
manage.py

the custom\
filter.py contents

from
django
import


/r/django
https://redd.it/1fbjtdq
Can't get Cloudfront to work (Heroku + Whitenoise)

Hi experts, thanks for any advice: as the title says, am in deployment on Heroku, am using Whitenoise. I have set up CloudFront as per directions from Whitenoise: https://whitenoise.readthedocs.io/en/latest/django.html#instructions-for-amazon-cloudfront, but it just doesn't want to work - e.g. my admin page has no CSS. I have put my app domain under origins in Cloudfront settings of course and have changed no other settings.

Settings:

STATIC_ROOT = BASE_DIR / "staticfiles"

Successful without Cloudfront

STATIC_URL = "static/"

Unsuccessful with Cloudfront

STATIC_HOST = os.environ.get("DJANGO_STATIC_HOST", "")

STATIC_URL = STATIC_HOST + "/static/" #https://xxxxxxxx.cloudfront.net/static

Logs aren't returning errors, but the Browser console is returning various "rejected" messages - it just can't see the Cloudfront resources, or there is some other security setting I need to change. It's driving me nuts: thanks for any tips you can give!

/r/django
https://redd.it/1fbgomg
Need to make sure I added the fields from my model correctly in search_indexes.py file. This is a Haystack/Solr question

Hey guys, new to Reddit here. I'm new to Haystack/Solr. I have a Django project and I'm using Haystack to build a search index for the data in my PostgreSQL database. Here is my `search_indexes.py` code ```

from haystack import indexes

from .models import Arborist





class ArboristIndex(indexes.SearchIndex, indexes.Indexable):

text = indexes.CharField(document=True, use_template=True)

arborist_city = indexes.CharField(model_attr='city')

arborist_state = indexes.CharField(model_attr='state')

price = indexes.PositiveIntegerField()

company_name = indexes.CharField(model_attr='company')

one_star = indexes.PositiveIntegerField(default=0, null=True, blank=True)

two_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

three_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

four_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

five_stars = indexes.PositiveIntegerField(default=0, null=True, blank=True)

review_by_homeowner = indexes.CharField(model_attr='reviews')

tree_pruning = indexes.CharField(model_attr='tree_pruning')

tree_removal = indexes.CharField(model_attr='tree_removal')

tree_planting = indexes.CharField(model_attr='tree_planting')

pesticide_applications = indexes.CharField(model_attr='pesticide_applications')

soil_management = indexes.CharField(model_attr='soil_management')

tree_protection = indexes.CharField(model_attr='tree_protection')

tree_risk_management = indexes.CharField(model_attr='tree_risk_management')

tree_biology = indexes.CharField(model_attr='tree_biology')





def get_model(self):

return Arborist



def prepare_arborist_cty(self, obj):

return [arborist_city.id for arborist_city in obj.aborist_city_set.active().order_by('-created')\]

```. I'm also following the docs tutorial https://django-haystack.readthedocs.io/en/v2.4.1/tutorial.html. Where I'm stuck, is that some of these fields are different field types than what the tutorial is using, for example, `PositiveInteger` and also some of these fields are from two other models that are foreign keys to this `Arborist` model.



I just want to make sure that I'm setting up the fields properly to be indexed. It's probably best to view this in my Github repo https://github.com/remoteconn-7891/MyProject/tree/master since I have five different model files in my models folder. I was using Discord Django, but they weren't helpful with this

/r/djangolearning
https://redd.it/1fbmrpe
VitePress vs. Material for MkDocs

Hey everyone,
I’m torn between using VitePress and Material for MkDocs to generate documentation for my code.

# mkdocstring support

I prefer VitePress for its interface, but Material for MkDocs can generate HTML directly from the source code and docstrings thanks to mkdocstrings library (see an example here), which VitePress doesn’t seem to support (or maybe I'm missing something?).

# Question

Why is such a common feature not available in VitePress? Would love to hear your thoughts or workarounds!

/r/Python
https://redd.it/1fbs772
global installations or project-specific environments

When installing libraries on python which one is better? Global installations or project-specific environment installation? Can you also write important bulletpoints for each?

/r/Python
https://redd.it/1fbs3ge
Flask authorization question ❓

Welcome, I am a jonuior web developer,
I have a question, now I know how can I implement a an authentication functionality with flask, flask-login, and also can I implement a More than role like an admin role manager role, and an employee role, I defined this roles in the code after the routes definition, and that's not helpful and not easiler in the development, what's the best way to can I implement the authorization functionality? I hope to find something let me to add the authorization feature for the client, as example like if I build a hr management system, the admin can add the employees and can add a new role from the GUI , and can select if The employee can add or read or update for something, and he also can select what is the page's the employee can access to it,
Please share the best resources and toturials for that, thanks guys.


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