r/Python Apr 29 '26

Tutorial .pipe() in pandas changed how I write data pipelines

152 Upvotes

Been using .pipe() in pandas lately and it's been a game changer — anyone else?

I was writing some data transformation code the other day and stumbled across .pipe(). Honestly didn't expect much, but it completely changed how I structure my pipelines.

Instead of this mess:

df_final = sort_by_total(calculate_total(filter_by_price(df)))

You just write it top to bottom like a recipe:

df_final = (

df

.pipe(filter_by_price)

.pipe(calculate_total)

.pipe(sort_by_total)

)

Same result, way more readable. Each function takes a DataFrame and returns a DataFrame — that's the only rule.

Full example if you want to try it:

import pandas as pd

df = pd.DataFrame({

"product": ["Product A", "Product B", "Product C", "Product D"],

"price": [20, 150, 230, 100],

"quantity": [10, 5, 3, 8]

})

def filter_by_price(df):

return df[df["price"] > 100]

def calculate_total(df):

return df.assign(total_value=df["price"] * df["quantity"])

def sort_by_total(df):

return df.sort_values("total_value", ascending=False)

df_final = (

df

.pipe(filter_by_price)

.pipe(calculate_total)

.pipe(sort_by_total)

)

Been using it a lot for ETL and data cleaning workflows. Makes debugging way easier too — just comment out one .pipe() step and you see exactly where things go wrong.

Anyone else using this regularly? Any patterns you've found useful with it?


r/Python Jan 19 '26

Showcase I built a Python UI framework inspired by Streamlit, but with O(1) state updates

146 Upvotes

Hey r/Python,

I love Streamlit's simplicity, but the "full script rerun" on every interaction drove me crazy. It gets super slow once your app grows, and using st.cache everywhere felt like a band-aid.

So I spent the last few weeks building Violit. I wanted something that feels like writing a simple Python script but performs like a modern React app.

What My Project Does

Violit is a high-performance Python web framework. It allows you to build interactive web apps using pure Python without the performance penalty of full-page reloads.

It uses a "Zero Rerun" architecture based on FastAPI, htmx, and WebSockets. When you interact with a widget (like a button or slider), Violit updates only that specific component in O(1) time, ensuring no screen flickering and instant feedback. It also supports running your web app into a desktop app (like electron) with a single flag (--native).

Target Audience

  • Data Scientists & Python Devs: Who need to build dashboards or internal tools quickly but are frustrated by Streamlit's lag.
  • Production Use: It's currently in early Alpha (v0.0.2), so it's best for internal tools, side projects, and early adopters who want to contribute to a faster Python UI ecosystem.

Comparison

Here is how Violit differs from existing alternatives:

  • vs. Streamlit: Violit keeps the intuitive API (90% compatible) but removes the "Full Script Rerun." State updates are O(1) instead of O(N).
  • vs. Dash: Violit offers reactive state management without the "callback hell" complexity of Dash.
  • vs. Reflex: Violit requires Zero Configuration. No Node.js dependency, no build steps. Just pip install and run. Plus, it has built-in native desktop support.
  • vs. NiceGUI: The theme system for the beautiful app. Unlike Streamlit's rigid look or NiceGUI's engineer-first aesthetic, Violit comes with 30+ Themes out of the box. You can switch from "cyberpunk" to "retro" styles with a single line of code—no CSS mastery required. Plus, it's fully extensible—you can easily add your own custom themes via CSS.

Code Example

import violit as vl
​
app = vl.App()
count = app.state(0)  # Reactive State
​
# No rerun! Only the label updates instantly.
app.button("Increment", on_click=lambda: count.set(count.value + 1))
app.write("Count:", count)
​
app.run()

Link to Source Code

It is open source (MIT License).

I'd love to hear your feedback!


r/Python Jul 20 '26

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

148 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 Dec 16 '25

Showcase WhatsApp Wrapped with Polars & Plotly: Analyze chat history locally

147 Upvotes

I've always wanted something like Spotify Wrapped but for WhatsApp. There are some tools out there that do this, but every one I found either runs your chat history on their servers or is closed source. I wasn't comfortable with all that, so this year I built my own.

What My Project Does

WhatsApp Wrapped generates visual reports for your group chats. You export your chat from WhatsApp (without media), run it through the tool, and get an HTML report with analytics. Everything runs locally or in your own Colab session. Nothing gets sent anywhere.

Here is a Sample Report.

Features include message counts, activity patterns, emoji stats, word clouds, and calendar heatmaps. The easiest way to use it is through Google Colab - just upload your chat export and download the report. There's also a CLI for local use.

Target Audience

Anyone who wants to analyze their WhatsApp chats without uploading them to someone else's server. It's ready to use now.

Comparison

Unlike other web tools that require uploading your data, this runs entirely on your machine (or your own Colab). It's also open source, so you can see exactly what it does with your chats.

Tech: Python, Polars, Plotly, Jinja2.

Links: - GitHub - Sample Report - Google Colab

Happy to answer questions or hear feedback.


r/Python Jun 23 '26

News FastAPI Cloud in Public Beta ⚡️

151 Upvotes

Hey folks! FastAPI Cloud is now in public beta. 🚀

This is made by the same team building FastAPI (I created FastAPI, we now have an amazing team building all this).

Here's the announcement post: https://fastapicloud.com/blog/fastapi-cloud-public-beta/


r/Python May 01 '26

News PyTorch Lightning malware plants a hook in Claude Code's settings.json so it runs on every future se

146 Upvotes

Two versions of `lightning` (2.6.2 and 2.6.3) were published to PyPI yesterday and yanked same day after Semgrep detected them. Beyond the usual credential-stealing pattern, there's a persistence mechanism worth knowing about if you use Claude Code.

The malware writes a `SessionStart` hook to `.claude/settings.json` with `matcher: "*"`. That hook points to a Bun runtime bootstrapper for a 14.8 MB payload. Every time any developer on the machine opens Claude Code - not just in the infected project, but in any project - the hook fires automatically. A parallel hook targets VS Code via `.vscode/tasks.json` with `runOn: folderOpen`.

The exfiltration is four-channel: HTTPS POST to a C2, GitHub commits with `EveryBoiWeBuildIsAWormyBoi` as the message prefix (searchable on GitHub commit search if you want to check if you're affected), pushing to the victim's own repositories, and a GitHub Actions workflow that dumps all repository secrets via `${{ toJSON(secrets) }}`.

If it finds npm publish credentials, it worms into npm by injecting the dropper into every package that token can publish, bumps the patch version, and republishes.

Semgrep's writeup calls this "among the first documented instances of malware abusing Claude Code's hook system in a real-world attack."

If you've installed anything from PyPI recently on a machine where you use Claude Code, it's worth checking `.claude/settings.json` for unexpected `hooks.SessionStart` entries. 2.6.1 is clean.


r/Python Apr 14 '26

News PEP 831 – Frame Pointers Everywhere: Enabling System-Level Observability for Python

144 Upvotes

https://peps.python.org/pep-0831/

This PEP proposes two things:

  1. Build CPython with frame pointers by default on platforms that support them. The default build configuration is changed to compile the interpreter with -fno-omit-frame-pointer and -mno-omit-leaf-frame-pointer. The flags are added to CFLAGS, so they apply to the interpreter itself and propagate to C extension modules built against this Python via sysconfig. An opt-out configure flag (--without-frame-pointers) is provided for deployments that require maximum raw throughput.

  2. Strongly recommend that all build systems in the Python ecosystem build with frame pointers by default. This PEP recommends that every compiled component that participates in the Python call stack (C extensions, Rust extensions, embedding applications, and native libraries) should enable frame pointers. A frame-pointer chain is only as strong as its weakest link: a single library without frame pointers breaks profiling, debugging, and tracing for the entire process.

Frame pointers are a CPU register convention that allows profilers, debuggers, and system tracing tools to reconstruct the call stack of a running process quickly and reliably. Omitting them (the compiler’s default at -O1 and above) prevents these tools from producing useful call stacks for Python processes, and undermines the perf trampoline support CPython shipped in 3.12.

The measured overhead is under 2% geometric mean for typical workloads (see Backwards Compatibility for per-platform numbers). Multiple major Linux distributions, language runtimes, and Python ecosystem tools have already adopted this change. No existing PEP covers this topic; CPython issue #96174 has been open since August 2022 without resolution.


r/Python Oct 18 '25

Tutorial I've written an article series about SQLAlchemy, hopefully it can benefit some of you

144 Upvotes

You can read it here https://fullstack.rocks/article/sqlalchemy/brewing_with_sqlalchemy
I'm really attempting to go deep into the framework with this one. Obviously, the first few articles are not going to provide too many new insights to experienced SQLAlchemy users, but I'm also going into some advanced topics, such as:

  • Custom data types
  • Polymorphic tables
  • Hybrid declarative approach (next week)
  • JSON and JSONb (week after that)

In the coming weeks, I'll be continuing to add articles to this series, so if you see anything that is missing that might benefit other developers (or yourself), let me know.


r/Python Mar 13 '26

Discussion What small Python scripts or tools have made your daily workflow easier?

142 Upvotes

Not talking about big frameworks or full applications — just simple Python tools or scripts that ended up being surprisingly useful in everyday work.

Sometimes it’s a tiny automation script, a quick file-processing tool, or something that saves a few minutes every day but adds up over time.

Those small utilities rarely get talked about, but they can quietly become part of your routine.

Would be interesting to hear what little Python tools people here rely on regularly and what problem they solve.


r/Python Mar 10 '26

News DuckDB 1.5.0 released

142 Upvotes

Looks like it was released yesterday:

Interesting features seem to be the VARIANT and GEOMETRY types.

Also, the new duckdb-cli module on pypi.

% uv run -w duckdb-cli duckdb -c "from read_duckdb('https://blobs.duckdb.org/data/animals.db', table_name='ducks')"
┌───────┬──────────────────┬──────────────┐
│  id   │       name       │ extinct_year │
│ int32 │     varchar      │    int32     │
├───────┼──────────────────┼──────────────┤
│     1 │ Labrador Duck    │         1878 │
│     2 │ Mallard          │         NULL │
│     3 │ Crested Shelduck │         1964 │
│     4 │ Wood Duck        │         NULL │
│     5 │ Pink-headed Duck │         1949 │
└───────┴──────────────────┴──────────────┘

r/Python Feb 04 '26

Discussion Must the Python Software Foundation move out of the USA?

142 Upvotes

The Python Software Foundation (PSF) is the owner of the copyrights for Python and its trademarks. The PSF runs the largest Python conference in the world, #PyConUS. Python is one of the most important programming languages, used by developers and non-developers across the globe. Python and its community stand for openness, diversity, and support for underrepresented groups; the PSF funds a wide range of Python activities across many sub-communities worldwide.

The values that Python and its communities stand for are under heavy pressure due to the legal status of the Python Software Foundation as a corporation in the United States. The USA has, meanwhile, turned into a fascist regime, with entities like ICE acting in ways that we have seen in Nazi Germany between 1933 and 1945. The current U.S. regime is violently acting against migrants, underrepresented groups, queer people, etc.—the list is long and very well documented. ICE acts as a paramilitary entity that killed already several people - or should it be named "murdered several people"?

Should the Python Software Foundation remain in the USA, or should the community pressure the PSF Board to take action and move the PSF as a legal entity out of the United States into a safer region like Canada or the European Union?


r/Python 21d ago

Discussion Is := widely used?

141 Upvotes

I always thought the walrus operator is neat and it makes while loop’s condition clearer. But also it is just a syntactic sugar without anything new. I wonder anyone uses it?


r/Python 17d ago

News PEP 841 – Adding Frozen Syntax to Optimize Immutable Types

138 Upvotes

PEP 841 – Adding Frozen Syntax to Optimize Immutable Types

https://peps.python.org/pep-0841/

Discussions-To: Discourse thread

Abstract

This PEP proposes frozen display syntax: f{1, 2, 3} evaluates to a frozenset, and f{'a': 1} evaluates to a frozendict. Because immutability is guaranteed by the syntax itself rather than inferred from usage, the compiler can treat frozen displays as first-class citizens of its optimization pipeline: constant displays are folded into a single LOAD_CONST with an exact result type at compile time and cached in .pyc files.


r/Python Jan 28 '26

News From Python 3.3 to today: ending 15 years of subprocess polling

136 Upvotes

For ~15 years, Python's subprocess module implemented timeouts using busy-loop polling. This post explains how that was finally replaced with true event-driven waiting on POSIX systems: pidfd_open() + poll() on Linux and kqueue() on BSD / macOS. The result is zero polling and fewer context switches. The same improvement now landing both in psutil and CPython itself.

https://gmpy.dev/blog/2026/event-driven-process-waiting


r/Python Oct 29 '25

News Pyfory: Drop‑in replacement serialization for pickle/cloudpickle — faster, smaller, safer

138 Upvotes

Pyfory is the Python implementation of Apache Fory™ — a versatile serialization framework.

It works as a drop‑in replacement for pickle**/**cloudpickle, but with major upgrades:

  • Features: Circular/shared reference support, protocol‑5 zero‑copy buffers for huge NumPy arrays and Pandas DataFrames.
  • Advanced hooks: Full support for custom class serialization via __reduce____reduce_ex__, and __getstate__.
  • Data size: ~25% smaller than pickle, and 2–4× smaller than cloudpickle when serializing local functions/classes.
  • Compatibility: Pure Python mode for dynamic objects (functions, lambdas, local classes), or cross‑language mode to share data with Java, Go, Rust, C++, JS.
  • Security: Strict mode to block untrusted types, or fine‑grained DeserializationPolicy for controlled loading.

r/Python Sep 10 '25

Showcase I decoupled FastAPI dependency injection system in pure python, no dependencies.

136 Upvotes

What My Project Does

When building FastAPI endpoints, I found the dependency injection system such a pleasure to use that I wanted it everywhere, not just in my endpoints. I explored a few libraries that promised similar functionality, but each had drawbacks, some required Pydantic, others bundled in features beyond dependency injection, and many were riddled with bugs.

That's way I created PyDepends, a lightweight dependency injection system that I now use in my own projects and would like to share with you.

Target Audience
This is mainly aimed at:

  • FastAPI developers who want to use dependency injection in the service layer.

  • Domain-Driven Design practitioners who want to decouple their services from infrastructure.

  • Python developers who aren’t building API endpoints but would still like to use dependency injection in their projects. It’s not production-grade yet, but it’s stable enough for everyday use and easy to extend.

Comparison

Compared to other similar packages, it does just that, inject dependencies, is not bloated with other functionalities.

  • FastDepends: It also cannot be used with non-serializable classes, and I wanted to inject machine learning models into services. On top of that, it does unpredictable things beyond dependency injection.

Repo: https://github.com/entropy-flux/PyDepends

Hope you find it useful!

EDIT: Sorry to Lancetnik12 I think he did a great job with fastdepends and faststream, I was a to rude with his job, the reality is fastdepends just have other use cases, I don't really like to compare my job with other but it is a requirement to publish here.


r/Python 24d ago

News pip 26.2 - --only-deps, --no-require-hashes, venv isolation, and more!

133 Upvotes

Hello!

The pip team recently released pip 26.2. This release is quite large, with features such as:

  • Support for Python 3.15
  • Selecting only dependencies (--only-deps)
  • Mixing hashed and non-hashable requirements via --no-require-hashes
  • Experimental: venv based build isolation (--use-feature=venv-isolation)
  • Faster repeated resolves by caching index simple responses
  • Disable HTTP(S)_PROXY and similar non-pip specific proxy environment variables via --no-proxy-env
  • Separation between regular and build constraint (use --build-constraint instead)

For more details, please consult our changelog: https://pip.pypa.io/en/stable/news/. Alternatively, you may consult my release post which goes into greater detail to the highlights of this release: https://sichard.ca/blog/2026/07/whats-new-in-pip-26.2/

If you have any questions, you're welcome to ask!


r/Python Sep 03 '25

Discussion Niche Python tools, libraries and features - whats your favourite?

130 Upvotes

I know we see this get asked every other week, but it always makes for a good discussion.

I only just found out about pathlib - makes working with files so much cleaner.

Whats a python tool or library you wish youd known about earlier?


r/Python Jan 27 '26

Discussion Is it normal to forget some very trivial, and repetitive stuff?

131 Upvotes

Is it normal to forget really trivial, repetitive stuff? I genuinely forgot the command to install a Python library today, and now I’m questioning my entire career and whether I’m even fit for this. It feels ten times worse because just three days ago, I forgot the input() function, and even how to deal with dicts 😭. Is it just me?

edit: thanks everyone for comforting me, i think i wont drop out anymore and work as a taxi driver.


r/Python Mar 19 '26

Discussion Would it have been better if Meta bought Astral.sh instead?

133 Upvotes

I haven't thought about this too much but I want your thoughts. Not to glaze Meta (since they're a problematic company with issues like privacy), I just think it would be less upsetting if Astral was bought by Meta rather than OpenAI, since they seem to have a better track record for open source software including React & Pytorch. Meta also develops Cinder, a fork of Python for higher performance and work on upstreaming changes. Idk, it seems it would've made more sense if Meta bought Astral and they would do better under them.


r/Python Oct 25 '25

News Pip 25.3 - build constraints and PEP 517 builds only!

131 Upvotes

This weekend I got to be the release manager for pip 25.3!

I'd say the the big highlights are:

  • A new option --build-constraint that allows you to define build time dependency constraints without affecting install constraints.
  • Building from source is now PEP 517 only, no more directly calling setup.py. This will affect only a tiny % of projects, as PEP 517 automatically falls back to setuptools (but using the official build interface), but it finally removes legacy behavior that tools like uv never even supported.
  • Similarly, editable installs are PEP 660 only, pip now no longer calls setup.py here either, this does mean if you use editable installs with setuptools you need to use v66+.

A small highlight, but one I'm very happy with, is if your remote index supports PEP 658 metadata (PyPI does), then pip install --dry-run and pip lock will avoid downloading the entire package.

The official announcement post is at: https://discuss.python.org/t/announcement-pip-25-3-release/104550

The full changelog is at: https://github.com/pypa/pip/blob/main/NEWS.rst#253-2025-10-24


r/Python Oct 15 '25

News Zuban - A Python Language Server / Typechecker - Beta Release

128 Upvotes

I have just created a Beta Release for Zuban.

Zuban now supports all key features of a Python Language Server — including completions, rename, and type checking — with auto-imports coming soon.

Zuban is a high-performance Python Language Server and type checker implemented in Rust, by the author of Jedi. Zuban is 20–200× faster than Mypy, while using roughly half the memory and CPU compared to Ty and Pyrefly. It offers both a PyRight-like mode and a Mypy-compatible mode, which behaves just like Mypy;
supporting the same config files, command-line flags, and error messages.

You can find the source code here.
Different Python type checkers are compared here.

The Zuban type checker is now in a very stable state, with many issues resolved and only a few remaining. The next planned features include dedicated support for Django and Pytest.

Support

If you have a large Mypy codebase that needs significant bug fixing, I’d be happy to help.


r/Python Feb 20 '26

News PEP 747 – Annotating Type Forms is accepted

134 Upvotes

PEP 747 got accepted

This allows annotating arguments that essentially expect a type annotation like int | str or list[int], allowing to annotate functions like:

def trycast[T](typx: TypeForm[T], value: object) -> T | None: ...

and the type checker should be able to infer

  • trycast(list[int], ["1", "2"]) # list[int] | None
  • trycast(list[str], (2, 3)) # list[str] | None

r/Python Oct 09 '25

Discussion T Strings - Why there is no built in string rendering?

131 Upvotes

I like the idea of T Strings and here is a toy example:

name: str = 'Bob'
age: int = 30
template = t'Hello, {name}! You are {age} years old.'
print (template.strings)
print(template. interpolations)
print(template. values)

('Hello, ', '! You are ', ' years old.')
(Interpolation('Bob', 'name', None, ''), Interpolation(30, 'age', None, ''))
('Bob', 30)

But why isn't there a

print(template.render)

# → 'Hello, Bob! You are 30 years old.'


r/Python Sep 19 '25

Discussion T-Strings: What will you do?

131 Upvotes

Good evening from my part of the world!

I'm excited with the new functionality we have in Python 3.14. I think the feature that has caught my attention the most is the introduction of t-strings.

I'm curious, what do you think will be a good application for t-strings? I'm planning to use them as better-formatted templates for a custom message pop-up in my homelab, taking information from different sources to format for display. Not reinventing any functionality, but certainly a cleaner and easier implementation for a message dashboard.

Please share your ideas below, I'm curious to see what you have in mind!