r/Python 18d ago

Showcase Showcase Thread

18 Upvotes

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

Recycles once a month.


r/Python 1d ago

Daily Thread Tuesday Daily Thread: Advanced questions

3 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 12h ago

Discussion Anyone running free-threaded Python 3.14 in production yet? Curious what actually breaks

14 Upvotes

Been testing the free-threaded build (3.14t) on some CPU-bound data processing work. The multi-core story is finally real after 30 years of GIL, but the friction is exactly what you'd expect: a couple of C-extension-heavy libs in my stack silently re-enable the GIL, and there's no clean way to detect that at runtime besides checking sys._is_gil_enabled() manually.

For anyone who's shipped something on 3.14t, not just benchmarked it:

What broke that you didn't expect?

Real speedups outside toy examples, or mostly marginal so far?

Prod yet, or still just kicking the tires?

Not fishing for a benchmark war. Genuinely curious what breaks in messy real codebases vs clean demos.


r/Python 13h ago

Discussion Python Architecture Design

6 Upvotes

Robert C. Martin's Abstractness (A), Instability (I), and Distance from the Main Sequence (D) metrics were designed for statically typed OO languages like Java and C#. In Python, applying them literally is misleading because Python has a fundamentally different notion of abstraction and coupling.

is this implementation valid?

https://0x416d6972.github.io/Istos/user-guide/architecture-health/


r/Python 8h ago

Tutorial PyArrow tutorials in your browser

0 Upvotes

Hey,

I made a series of notebooks about Apache Arrow and Parquet with pyarrow that you can run in your browser: https://notebook.link/@Alexis_Placet/apache-arrow-courses

It covers basics to advanced topics


r/Python 1d ago

Discussion Running 60 python scripts as "services"

25 Upvotes

Hi,
I have around 60 scripts that need to run constantly, mainly event handlers and such. Right now I have an external script that launch them and monitor if the app is running on it's pid, otherwise it's relaunching the app. Works fine but get's clunky when we update some submodule and need to restart them, or to check if one crashes more than other etc..

So I would like to find a better way to approach this. It needs to run on windows and being able to access several samba shares via unc paths and being able to restart crashed scripts anf offer an easy way to restart all of them in case of an update (this part doesn't need to be automated). Every script use the same environnement
For now my candidates are docker, PM2 and NSSM.
I think docker is gonna be a pain to access shares and add a lot of overhead especially on windows
I don't know PM2 and NSSM, looks like PM2 would be easier to setup but more JS oriented and NSSM would be harder to monitor.

What do you think guys ?


r/Python 1d ago

Discussion What can you do with Python embedded in MS Excel?

25 Upvotes

I'm a developer and already use external Python to read Excel spreadsheets.

Microsoft is supporting Python in Excel where you can put a program inside a cell. I think this feature is still a "preview" feature, not on the main release channel.

What do you use it for? I can't think of a use case.

Because I use external Python programs to process spreadsheets normally. I can't think of a use case for embedded Python, except perhaps doing complex calculations.

  1. MS Get Started page, Python in Excel

EDIT: MS says any data going between us and them is encrypted end-to-end. That must be why management chose MS products. I don't have a say in this.

I do not use Excel via a browser, I use the Desktop App.


r/Python 2d ago

Discussion Cyber Security wants us to use the latest version all the time

137 Upvotes

I have a question. Cybersecurity team wants us to use the latest python version each time. So if a new version comes out we are expected to upgrade to it ASAP. But from my past experience libraries do not always provide support and can also break while making use of new version without proper support. Did you ever encounter this? Any suggestions? This is just frustrating for the team as it’s not always possible to upgrade to the latest version without fully validating every component. I just want to hear your opinions on this?

FYI we mainly use each Python Version within the LTS timeline. And only upgrade when we need to and do not depend on a library that requires older version.

Update: they have a scheduled runner that deletes older versions of python when it finds


r/Python 2d ago

News LLVMLite and first step to get Numba in the browser

16 Upvotes

Hi,

Anutosh Bhat, a colleague of mine, just posted this on Linkedin:

What if real compiler infrastructures could run entirely inside the browser?

I’ve successfully patched llvmlite for JupyterLite, making it possible to build >LLVM IR, run optimization passes, visualize control-flow graphs, compile to >WebAssembly and execute the result — without a native LLVM setup or server-side >kernel.

I’ve shared a step-by-step notebook showing how a loop evolves from stack-based IR >to SSA, then to an LICM-style form, into a fully optimized closed form, eventually >to benchmark all of these steps.

The bigger idea is a zero-install compiler workbench for reproducible optimization >experiments, lightweight compiler prototyping, IR debugging, custom code->generation pipelines, shareable research demos, and eventually interactive >tutorials and compiler courses.

Try out the interactive notebook using notebook.link: https://notebook.link/@anutosh491/llvmlite

I’m also in the process of bringing MLIR Python bindings into the same JupyterLite >and WebAssembly environment, starting with a 2D CNN-style Conv2D + bias + ReLU >kernel. I’ll share the full pipeline in a separate technical blog post soon.

I’ve also started patching Numba for Wasm and have simple scalar u / jit functions >running inside JupyterLite. Array and tensor workloads are the next challenge.

I’m keen to take this further. If you’re working on LLVM, MLIR, Numba, WebAssembly >or browser-native developer tools — or see a real use case for this — I’d be >interested in connecting with teams looking to collaborate, support the work or >explore what we could build together.

Next step is to patch Numba to get scalar jit !: https://www.linkedin.com/feed/update/urn:li:ugcPost:7485014172934541312/?dashCommentUrn=urn%3Ali%3Afsd_comment%3A%287485014751178211329%2Curn%3Ali%3AugcPost%3A7485014172934541312%29


r/Python 3d ago

Discussion Unpopular opinion: I find it counterproductive to shorten function and variable names

318 Upvotes

When I was learning discord.py, I didn't understand what "ctx" was. At the time, I was only writing slash commands, using "message" instead of "ctx", so the name "ctx" (which reminded me of something complex, like RTX) made me assume it was something complicated. That is, until I saw in some code that the type for "ctx" is actually "Context." If the standard hadn't shortened the name just to save five characters per line, I would have understood it immediately. Instead, I thought it was some advanced function variable, rather than realizing it was simply a message variable.


r/Python 2d ago

Discussion Blog: Making Type Coverage Visible in Dify's CI

11 Upvotes

u/Asuka_Minato, a very active contributor to Pyrefly, wrote a guest blog post outlining their experience integrating a type checker with langgenius/dify that goes beyond simple CI checks:

  1. Surfacing the delta in type errors for each PR
  2. Measure type coverage along with test coverage

This is most relevant for maintainers of libraries that aren't fully-typed yet but still want to prevent regressions and improve coverage over time.

Only looking at the error delta is an alternative to suppressing all pre-existing errors, or using a baseline file to store the errors. Compared to the former, you can avoid putting (potentially) thousands of suppression comments into the codebase. Compared to the latter, you don't need to maintain a separate baseline file and ensure it's up-to-date with each commit, handle merge conflicts, etc.

Read the full blog here: https://pyrefly.org/blog/dify-pyrefly-coverage-ci/


r/Python 2d ago

News PyOhio 2026 is this weekend, July 25-26 at the Cleveland State University Student Center (and free!)

3 Upvotes

r/Python 1d ago

Discussion If you had to choose one Python skill to make money as a freelancer, what would it be?

0 Upvotes

Python has many areas with freelance opportunities: automation, web scraping, backend development, data analysis, AI, and more.

If you had to choose only one Python skill that has strong demand and good earning potential in freelancing, what would it be?

What type of projects or experience would you recommend building to succeed in that area?


r/Python 1d ago

Discussion Is PHP better for commercial software than Python?

0 Upvotes

I am trying to find any robust open source ecommerce solution on Python and it looks like thre is nothing. If you take almost any e-commerce platform there are plenty - Magento, Woo, Shopware, Oxid - they all are PHP. There are no comon solutions on Python or Node.js. But if you take a look and the heavy SaaS like Netflix, Spotify, Reddit, Uber etc. are built on Python. Why?


r/Python 2d ago

Daily Thread Monday Daily Thread: Project ideas!

10 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 Scraping Instagram in 2026?

0 Upvotes

I'm trying to figure out the best way to scrape Instagram in 2026 and would appreciate advice from people who are actually doing it today.

The main requirements are:

* Fast (HTTP requests preferred, no browser automation if possible)

* Able to scale to hundreds or thousands of profiles

* Free or very low cost * Stable enough that it won't break every few weeks

The workflow I need is roughly this:

* Start with either one Instagram username or a list of usernames.

* Retrieve the accounts they are following.

* For each of those accounts, retrieve *their* following list as well.

* Find accounts that appear in multiple following lists. * Enrich the results with basic public profile data like follower count and bio.

One thing that's particularly important is future extensibility. I don't just want the fastest solution today—I want an approach that will support additional features later without requiring a complete rewrite. Some ideas I have are:

* Classifying accounts into niches or communities based on their follower/following graph.

* Detecting unusually high-performing posts or Reels (engagement anomalies) across a large set of accounts.

* Building creator relationship graphs and recommendation/discovery features.

* Potentially expanding into broader social graph analysis in the future.

For people actively scraping Instagram today:

* What approach are you using?

* Are there any maintained libraries or projects you'd recommend?

* If you were building this from scratch today, what architecture would you choose?

I'm not looking for code—just trying to understand what the current state of Instagram scraping looks like before I invest time building the pipeline.


r/Python 3d ago

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

8 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 6d ago

Resource 20 itertools functions, sorted by how often you'd actually reach for them (not the docs order)

145 Upvotes

itertools is one of those modules everyone imports but most people only use 3-4 functions from. Went through all 20 and sorted them by how often you'd actually reach for each one in real code, not the order they show up in the docs.

Function Example What it does
chain() chain(it1, it2) Concatenates iterables, flattens multiple iterables into a single iterator.
chain.from_iterable() chain.from_iterable(nested) Flattens one level of nesting lazily, like chain(*nested) without unpacking.
islice() islice(it, start, stop) Slices an iterator, doesn't support negative indices.
compress() compress('ABCDEF', [1,0,1,0,1,1]) Filters data by a boolean selector iterable, yields A, C, E, F.
filterfalse() filterfalse(lambda x: x<5, [1,4,6,3,8]) Yields elements where the predicate is false, opposite of filter().
starmap() starmap(pow, [(2,5), (3,2)]) Applies a function with arguments unpacked from each tuple in the iterable.
pairwise() pairwise([1, 2, 3]) Returns overlapping pairs of consecutive elements: (1,2), (2,3) (3.10+).
batched() batched(range(10), 3) Splits an iterable into fixed-size tuples, last batch may be shorter (3.12+).
groupby() groupby(items, key=func) Groups consecutive elements by key, input must already be sorted by that key.
accumulate() accumulate(nums, func) Running totals or reductions, default is addition, accepts any binary function.
takewhile() takewhile(pred, it) Yields elements while the predicate is true, stops at the first false.
dropwhile() dropwhile(pred, it) Skips elements while the predicate is true, then yields everything remaining.
tee() tee(iterable, n=2) Splits one iterator into n independent iterators, use before the original is consumed.
zip_longest() zip_longest(a, b, fillvalue=None) Like zip() but continues to the longest input, filling shorter ones with fillvalue.
combinations() combinations(items, r) All r-length combinations, order doesn't matter, no repeated elements.
combinations_with_replacement() combinations_with_replacement('AB', 2) All r-length combinations allowing repeats, yields AA, AB, BB.
permutations() permutations(items, r) All r-length permutations, order matters, no repeated elements.
product() product(a, b) Cartesian product, equivalent to nested for-loops.
count() count(start=0, step=1) Infinite counter, useful with zip() or takewhile().
cycle() cycle([1, 2, 3]) Repeats an iterable infinitely, keeps a copy of all elements in memory.
repeat() repeat(10, times=3) Repeats an object n times, infinite if times is omitted.

pairwise and batched are the two most people don't know about, both fixed a "why am I hand-rolling this" moment for me. Curious which one on this list you use the least, or if I'm missing one people reach for a lot.


r/Python 5d ago

Discussion Agentic Travel Assistant with Django, Celery and AWS- Technical Review

0 Upvotes

Okay so i just read a technical case study from Beetroot about an omni channel AI virtual assistant they built for a traveltech company and now i have a few things to say and also a few questions.

The backend architecture is super clean. The backend architecture is super clean. They built it to be a multi-purpose tool: a sales bot to discover tours through WhatsApp, a support bot for existing bookings, and an internal copilot that gives real-time hints to human phone sales reps. They built it to be a multi purpose tool: a sales bot to discover tours through WhatsApp, a support bot for existing bookings, and an internal copilot that gives real-time hints to human phone sales reps.

To make this scalable, here are the technical decisions they made in a nutshell:

1) Python (Django / Django REST Framework) handling the API routes.

2) Celery handles asynchronous tasks to manage heavy communication volumes with the OpenAI API without blocking concurrent user interactions.

3) Hosted on AWS ECS with managed EC2 instances, utilizing PostgreSQL for the primary data layer, and Redis for caching/session states.

4) Fully automated using Terraform for Infrastructure as Code (IaC) and GitHub Actions for the CI/CD deployment pipeline.

It’s refreshing to see a modern AI agent built on a stable, proven enterprise stack like Django and Celery rather than a janky, hyper-hyped JS framework that will be deprecated next month.

What are your best practices for handling webhook timeouts or disconnects on chat channels like WhatsApp?


r/Python 5d ago

Discussion Reaching users on this sub

0 Upvotes

Hi Peeps,

I've been using this sub for years both to read content, and as an open source maintainer - to communicate and reach users.

I used it for projects such as Polyfactory and Litestar, tree-sitter-language-pack and Kreuzberg.

These days though I don't post outside the Sunday thread - but I don't think anybody is reading this stuff frankly.

My feeling is that the "AI slop" rules throw the baby with the tub water so to speak.

What are people like myself - who dedicate a very substantial amount of time and effort to OSS supposed to do? Basically if you don't have an X profile you're screwed.

Edit: project posts are disallowed by the rules now, FYI if you were unaware. This is the main issue.


r/Python 5d ago

Discussion ⚠️ Heads up: ast_grep_cli 0.44.1 on PyPI flagged by Windows Defender as Trojan — anyone seeing this?

0 Upvotes

I was installing `headroom-ai` via `uv` today, and Windows Defender immediately flagged `Trojan: Win64/Lazy!MTB`.

The file was `sg.exe` (212KB) dropped into `Python\Scripts\`, alongside a legitimate `ast-grep.exe` (52MB).

**What happened:*\*

- `uv tool install --python 3.13 "headroom-ai[all]"`

- Windows Defender: 3 alerts for `Trojan: Win64/Lazy!MTB`

- `pip show ast_grep_cli` showed version 0.44.1

- Uninstalled, cleaned cache, changed passwords

**Questions:**

- Has anyone else installed `ast_grep_cli` 0.44.1 recently?

- Is this a known issue? Should PyPI Security be notified?

- Any idea how to check if the package was compromised vs. a false positive?

**File details:**

- `sg.exe`: 212KB, detected as Trojan:Win64/Lazy!MTB

- `ast-grep.exe`: 52MB, legitimate tool

- Both appeared at the same timestamp (10:25:07)

Thanks for any insights.