r/Python 9h ago

Daily Thread Tuesday Daily Thread: Advanced questions

Upvotes

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 every Thursday.
  • Questions that are not advanced may be removed and redirected to the appropriate thread.

Recommended Resources:

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 performance implications of using native Python data structures vs NumPy arrays for large-scale data?
  9. Best practices for securing a Flask (or similar) REST API with OAuth 2.0?
  10. What are the best practices for using Python in a microservices architecture? (..and more generally, should I even use microservices?)

Let's deepen our Python knowledge together. Happy coding! 🌟


r/Python 3d ago

Showcase Showcase Thread

Upvotes

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.


r/Python 2h ago

Resource Date calculator (en)

Upvotes

import datetime

def calculate_weekday(day, month, year):

"""

Calculates the day of the week for any date using the Doomsday Algorithm.

Returns a string with the day name in English.

"""

days_of_week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

# 1. Check if the year is a leap year according to Gregorian rules

is_leap_year = (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)

# 2. Identify the century anchor day (400-year cycle)

century_base = (year // 100) * 100

if century_base % 400 == 0:

century_anchor = 2 # Tuesday (e.g., years 2000, 1600)

elif century_base % 400 == 100:

century_anchor = 0 # Sunday (e.g., years 2100, 1700)

elif century_base % 400 == 200:

century_anchor = 5 # Friday (e.g., years 2200, 1800)

else:

century_anchor = 3 # Wednesday (e.g., years 1900, 2300)

# 3. Calculate the year component (Standard Doomsday Algorithm)

year_last_digits = year % 100

quotient_4 = year_last_digits // 4

year_doomsday = (century_anchor + year_last_digits + quotient_4) % 7

# 4. Map the monthly anchor dates

month_anchors = {

1: 4 if is_leap_year else 3, # January 4 (leap year) / January 3 (normal year)

2: 29 if is_leap_year else 28, # February 29 (leap year) / February 28 (normal year)

3: 14,

4: 4,

5: 9,

6: 6,

7: 11,

8: 8,

9: 5,

10: 10,

11: 7,

12: 12

}

# 5. Calculate the distance from the closest monthly anchor

current_anchor = month_anchors[month]

distance = day - current_anchor

# 6. Resolve the final day index (modulo 7)

final_day_index = (year_doomsday + distance) % 7

return days_of_week[final_day_index]

def validate_date(day, month, year):

"""Checks if a combination of day, month, and year is a valid real date."""

try:

datetime.date(year, month, day)

return True

except ValueError:

return False

if __name__ == "__main__":

print("=== USER INTERFACE ===")

print("Enter the dates you want to calculate. Type 'exit' to quit.\n")

while True:

try:

date_input = input("Enter date (DD/MM/YYYY): ").strip()

if date_input.lower() == 'exit':

print("Closing the program.")

break

# Parsing the user input

parts = date_input.split('/')

if len(parts) != 3:

raise ValueError

d = int(parts[0])

m = int(parts[1])

y = int(parts[2])

# Calendar validation

if not validate_date(d, m, y):

print("Error: The entered date does not exist (e.g., check leap years or month limits). Try again.\n")

continue

# Final calculation and output

result_day = calculate_weekday(d, m, y)

print(f"The date {date_input} corresponds to: {result_day}\n")

except ValueError:

print("Error: Invalid format. Please use exactly the DD/MM/YYYY format (e.g., 23/02/2016).\n")


r/Python 2h ago

Discussion amazon ml challenge 2-26 (ml require python)

Upvotes

need 3 members for the team .

about me : am 2027 final year undergrad , have decent knowledge of ML and DL and wont claim myself as too muh of an expert . Has practical experince of such comepetitions .

what i am looking for :

dedicated team members who can work for 72 hour hackathon wthout ghosting at end time or not doing anything , you can 2027 or 2028 grad but should jave decent enough knowledge and practical experince too . i am not doing this for timepass but aimig for top 50 to get ppi if everything go well .

only serious people message , no ghosters !


r/Python 6h ago

Discussion Why can’t python devs just move to c++ or rust or smth

Upvotes

I feel like ai is too good at python. I’m worried about Python devs and their future because I feel like I can 1 shot projects with a prompt on Claude. I think it would be cool if all the Python devs maybe start changing their projects to other stuff just so ai doesn’t get too powerful ykwim?


r/Python 12h ago

Discussion DAE feel like python is a lot harder now

Upvotes

when i started python 10 years ago it felt like a baby language compared to C++ and C. now it feels as just as hard as those two . its because of the additional library knowledge u need to know for ai ml etc


r/Python 1d ago

Daily Thread Monday Daily Thread: Project ideas!

Upvotes

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" 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

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

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

Let's help each other grow. Happy coding! 🌟


r/Python 1d ago

Discussion Astral's endorsements for Python's first Packaging Council

Upvotes

Astral has announced their endorsements for Python's first packaging council elections.

PPC election details:

Note: Voting is currently open and ends on Tuesday, September 15th, 2:00 pm UTC

What are your thoughts? The candidates they have nominated are fine, they are/have been heavily involved in packaging in the past.

edit: fixed nominees link


r/Python 2d ago

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

Upvotes

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 3d ago

Discussion When scaling application pods with SQLAlchemy pools, who redistributes existing connections?

Upvotes

I’m running application pods that use SQLAlchemy’s connection pool to connect to PostgreSQL. Each pod has its own pool, so when I scale the application from, say, 3 to 10 replicas, the new pods create new pools while the existing pooled connections remain open.

If PostgreSQL has read replicas behind a Kubernetes Service or a proxy, I assume new connections might reach the new replicas, but the existing long-lived pooled connections will remain attached to the old replicas.

Who is normally responsible for redistributing those existing connections after scale-out?


r/Python 3d ago

Daily Thread Saturday Daily Thread: Resource Request and Sharing! Daily Thread

Upvotes

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 4d ago

Daily Thread Friday Daily Thread: r/Python Meta and Free-Talk Fridays

Upvotes

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:

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 4d ago

Discussion It seems like there was a change for how hex values and bytes can be compared

Upvotes

I made myself a lib for fast parsing RAW images from my sony camera.

My old code: ```python def check_for_endian(data:bytes) -> tuple[int, int]|None:

if data[:2] == 0x4949:   # "II" LE
    return 1, 0
if data[:2] == 0x4D4D:   # "MM" BE
    return 2, 0

return None

So it was possible to compare a hex value with bytes. Now it's not possible anymore, somehow, so I had to do this: python def check_for_endian(data:bytes) -> tuple[int, int]|None: header_endian = struct.unpack_from("<h", data, 0)[0]

if header_endian == 0x4949:   # "II" LE
    return 1, 0
if header_endian == 0x4D4D:   # "MM" BE
    return 2, 0

return None

```

I'm a bit confused, have I used it wrong in the first place and I was never supposed to compare a hex value with bytes?

E: I use python 3.13.9 and uv 0.9.9


r/Python 4d ago

Discussion Pyinstaller for android?

Upvotes

Hello friends, is there any way to make an APK from Windows or another operating system using a Python library similar to PyInstaller?

Convert .py in .apk?


r/Python 5d ago

Daily Thread Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Upvotes

Weekly Thread: Professional Use, Jobs, and Education 🏢

Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.


How it Works:

  1. Career Talk: Discuss using Python in your job, or the job market for Python roles.
  2. Education Q&A: Ask or answer questions about Python courses, certifications, and educational resources.
  3. Workplace Chat: Share your experiences, challenges, or success stories about using Python professionally.

Guidelines:

  • This thread is not for recruitment. For job postings, please see r/PythonJobs or the recruitment thread in the sidebar.
  • Keep discussions relevant to Python in the professional and educational context.

Example Topics:

  1. Career Paths: What kinds of roles are out there for Python developers?
  2. Certifications: Are Python certifications worth it?
  3. Course Recommendations: Any good advanced Python courses to recommend?
  4. Workplace Tools: What Python libraries are indispensable in your professional work?
  5. Interview Tips: What types of Python questions are commonly asked in interviews?

Let's help each other grow in our careers and education. Happy discussing! 🌟


r/Python 6d ago

Resource Python Under the Hood Update: Chapter 3 (Conditional Statements & Control Flow) is now complete

Upvotes

Hey everyone,

Chapter 3 is finally done. This chapter took way more time than I originally expected because it grew into a much deeper and larger chapter than planned.

Current Progress:
✅ Chapter 1 - Variables & Memory
✅ Chapter 2 - Expressions & Operators
✅ Chapter 3 - Conditional Statements & Control Flow

I'd love to hear your thoughts on the new chapter and any suggestions for future improvements.

With this, I’m taking a break from Python Under the Hood. I’ll be stepping away from the project for a while and will return to it before July 2027.

When I come back, we’ll continue with even deeper explanations, more advanced topics, and an even better approach to understanding what happens under the hood of Python.

For now, Chapter 3 marks the end of this phase. 🐍⚙️

GitHub: python-under-the-hood

See you in the next chapter.


r/Python 7d ago

Discussion I know I’m late, but Python 3.14.7 is out. Anyone actually upgraded yet?

Upvotes

I know I’m a little late to this, but I’ve been looking into Python 3.14.7 and something keeps bothering me.

The release itself looks solid. Python 3.14.7 was released on August 5 and is mainly a maintenance release with a lot of bug fixes and improvements.

But for people working on existing projects, the bigger question seems to be:

What makes you decide that it’s finally time to upgrade Python?

A new Python version sounds great until you have to check:

  • dependencies
  • C extensions
  • Docker images
  • CI/CD
  • production servers
  • test suites
  • old packages that nobody wants to touch

And Python 3.14 has some pretty interesting changes compared with 3.13, including officially supported free-threaded Python, t-strings, multiple interpreters, and the new compression.zstd module.

So I’m curious about real-world experience rather than release notes.

Have you upgraded to 3.14 yet?

If yes, what went smoothly and what broke?

If no, what’s the main reason you’re waiting?


r/Python 7d ago

Discussion When do you prefer asyncio.Semaphore over an asyncio.Queue for limiting concurrency?

Upvotes

I've been thinking about concurrency control in asyncio.

A common pattern for limiting concurrent work is:

sem = asyncio.Semaphore(10)

async with sem:
    await do_work()

But in many cases, couldn't the same problem be modeled by putting work into an asyncio.Queue and running a fixed number of worker tasks?

I'm curious how experienced Python developers decide between the two approaches.

Are there real-world situations where a semaphore is clearly the better abstraction than a worker queue? Are there meaningful differences in cancellation behavior, backpressure, fairness, task lifetime, or code complexity?

I'd especially be interested in examples from production async Python code.


r/Python 7d ago

Daily Thread Tuesday Daily Thread: Advanced questions

Upvotes

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 every Thursday.
  • Questions that are not advanced may be removed and redirected to the appropriate thread.

Recommended Resources:

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 performance implications of using native Python data structures vs NumPy arrays for large-scale data?
  9. Best practices for securing a Flask (or similar) REST API with OAuth 2.0?
  10. What are the best practices for using Python in a microservices architecture? (..and more generally, should I even use microservices?)

Let's deepen our Python knowledge together. Happy coding! 🌟


r/Python 7d ago

News Pycon 2026 in Aveiro

Upvotes

Below is the link for Python enthusiasts and programmers/anyone interested in the Pycon 2026 event, which will take place in Aveiro from September 3rd to 5th!

https://2026.pycon.pt/


r/Python 8d ago

Discussion Thank You | from Nova

Upvotes

Hello!
I'm Nova, I'm a college student taking CS in Norway. And I just wanted to share a bit of my story.

I started my developing career roughly 7 years ago when I was 8-9. I remember watching so many movies about these hackers and programmers growing up, and thinking "Wow, I wish I could be like them!". Luckily my father had a computer science background himself! So he saw this and showed me a couple things such as Scratch, blablabla.
I quickly quit Scratch, cause I thought it was boring and hard. But just a few months later, I installed Python and VSCode on the family computer! I started watching a multi hour Python course by Programming with Mosh and followed along. I remember being so bored haha!

But it clicked. It really did. It scratched (pardon the pun) something that Scratch couldn't. Some abstract yet so understandable logic. At the time it really felt like I was on top of the whole world.
Somewhere in the second last to last years of primary school, I was fully invested. I was making calculator apps and whatever I could think of during the free time at school with the provided iPads that hadn't been there the year before. Heck! I got some other kids in my class to become interested in programming too!

Eventually, a year later when I started middle school/high school (combined into the same three years in Norway), I naturally started learning new things such as Java and C# .NET. My Python usage was mostly just small prototypes for other languages at that time.

Yet I never abandoned it. Not even now.
Python is what started my journey, and I am so grateful for everything it has done.

So thank you,
Thank all of you,

Thank you every random StackOverflow member who posted weirdly specific help threads.

Thank you every StackOverflow member who responded to my silly little questions.

Thank you to all the Python maintainers and contributors.

Thank you Guido van Rossum for founding the language.

And thank you to the whole Python community who made this student's childhood dreams possible and bloom to life.

- Nova


r/Python 8d ago

Daily Thread Monday Daily Thread: Project ideas!

Upvotes

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" 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

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

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

Let's help each other grow. Happy coding! 🌟


r/Python 8d ago

Resource Nathan Goldbaum Interviewed about the Move to Free Threading and its Implementation

Upvotes

https://alexalejandre.com/interviews/interview-with-nathan-goldbaum/

After a lot of effort, the free threading build works but there is still much community work, making packages compatible etc.


r/Python 9d ago

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

Upvotes

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 9d ago

Discussion Contribution to pyperf

Upvotes

I am recently came across the library pyperf because I have to benchmark my changes in a certain open source project to add metrics to the PR I was creating for the changes, but one thing I feel off is types, I don't know why but pyperf has lot of unknown types which is kind of weird so I was planning to contribute to it to make it a little bit better typed.

So I am wondering do projects like pyperf which comes under pdf accept contribution in generally? If there are any maintainers/contributors of pyperf here then then could answer my question.

Thanks in advance.

My Dev Environment

OS: Windows

Type Checker: Pyrefly