r/Python • u/ForeignVariety7037 • Aug 04 '26
Discussion Is := widely used?
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 • u/ForeignVariety7037 • Aug 04 '26
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 • u/Prime_Director • Aug 04 '26
I’ve always hated environment management. It always feels like this time-consuming hurdle between me and whatever I actually want to work on. But every so often a new thing comes out that promises to solve the problem once and for all, and it’s usually at least a little better than the last thing. So, what are you using today? venv? conda? pipenv? poetry? dev containers? uv? or something else?
r/Python • u/Ill_Campaign294 • Aug 03 '26
Quick question, are any of you running fastAPI in production with a high volume of users or heavy traffic? How has your experience with FastAPI been, and how do you handle it?
r/Python • u/AutoModerator • Aug 04 '26
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
Let's deepen our Python knowledge together. Happy coding! 🌟
r/Python • u/AutoModerator • Aug 03 '26
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.
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
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
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 • u/AutoModerator • Aug 02 '26
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!
Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟
r/Python • u/Leyper • Aug 01 '26
I wrote a practical guide to Celery, a distributed task queue for Python. It starts with the basics and then covers recipes for timeouts, retries, async/await integration, and more. Most of these recipes came from problems I ran into while using Celery in actual projects. No prior knowledge of Celery is required.
I'd really appreciate any feedback!
r/Python • u/ichard26 • Jul 31 '26
Hello!
The pip team recently released pip 26.2. This release is quite large, with features such as:
--only-deps)--no-require-hashes--use-feature=venv-isolation)HTTP(S)_PROXY and similar non-pip specific proxy environment variables via --no-proxy-env--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 • u/poppy_92 • Jul 31 '26
https://peps.python.org/pep-0842/
Not the author, but this seems interesting, specially for library authors. Thoughts?
Discussion here - https://discuss.python.org/t/pep-842-module-exports/108353
r/Python
•
u/zsol
•
Jul 31 '26
We recently released wheels.astral.sh, which is a repository of gpu-enabled wheels of popular packages from the pytorch ecosystem. These are useful because building them is super annoying - you have to align versions of pytorch, cuda, python, etc.
The pre-built wheels were part of the package of pyx, our paid service, and was a major reason many customers subscribed. We decided to open source the build pipelines and host the wheels for free while we sunset the rest of pyx.
The pipelines are available under the astral-sh-build github organization.
While these plug a genuine UX hole around cuda/pytorch wheels, we hope that wheel variants (PEP 817 and 825) will get accepted and implemented soon, which will let these pytorch wheels be hosted properly on PyPI and "just work" out of the box for everyone, making wheels.astral.sh obsolete.
Fingers crossed.
r/Python • u/Voxelith3D • Aug 01 '26
If someone adds a new function to the code six months later, they would be unaware of the rule and nothing will complain because code will still work and tests will pass. Linters will not help here because these are not style rules, but project-specific invariants. "All user-visible strings must go through translation." "This whitelist must match what is stated in the privacy documents." A linter does not know what your translation is. Therefore, create tests that check the code:
=
=
assert not , f
That's the whole pattern. Everything below is just violates().
Example 1: no untranslated UI strings
Every string the user sees should come from t("some.key"), never a literal. Easy to enforce, easy to forget.
=
"""(lineno, text) for every literal passed straight into a UI setter."""
=
continue
continue
return
self.btn.setText(t("btn.save")) is not reported, since the argument is a Call and not a Constant. self.lbl.setText("Save changes") is reported.
This one revealed the bug to me which unit tests could never see, that is, a warning message that had been completely developed, correct, and tested for the application, but only in one language out of the six ones that were supposed to be used.
Example 2: make the naming convention be the rule
This is the one I'd actually argue for. Say you have a dict of operations that cost the user money:
=
The naive guardian compares the dict against a known-good copy of itself, which is self-defeating because you are only claiming that the list equals the list, and whoever adds an entry just updates both places.
Instead do it by coding the rule into the name where everything that one can bill is cloud_* and the guardian does only the check for the prefix without checking for what follows.
=
continue
continue
return
The guardian now applies even when operations are not yet present. Usage of "local_export": 2 does not work. Billing something local would force you to name it cloud_export instead — a lie simple enough for a human reviewer to catch.
The overall point is to use the naming scheme that would allow for the rule to be checked automatically as the test checks the property instead of the exact data.
Example 3: a constant that will not deviate from the document
You state in your privacy statement that these exact fields will be collected. The information is coded elsewhere. The latter will inevitably differ, not because anyone did anything wrong, but more likely because of an ordinary Tuesday afternoon.
return
return
return
Then assert both directions:
assert ==
Both directions matters. One direction catches "we collect something undocumented" - the compliance problem. The other catches "we document something we no longer collect" - the trust problem, and the one people forget.
When this is the wrong tool:
The niche is narrow but real: project-specific structural invariants that no off-the-shelf tool knows about.
Two gotchas that bit me:
Make a guardian that finds nothing loudly report that it found nothing. A typo in the path means it's not scanning any files, and silently succeeding. Assert that you scanned a reasonable number of files, or that the one known-bad fixture is indeed being caught by the guardian. A guardian nobody runs is not a guardian at all, and one that scans zero files is even worse than that, because it reports success.
Do not have a comment-based disablement of checks. I had a case where writing a comment in a certain way caused the line to be ignored, and it was propagated around the codebase. If a check needs exceptions, list them in the test as paths to scan, so that adding a new exception is visible in the git diff.
Curious if anyone else does something similar, and what they tend to check. The only somewhat similar thing I've seen in the wild is import-linter with rules for layering, which is more or less the same idea but for a narrower class of checks.
r/Python • u/AutoModerator • Aug 01 '26
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!
Share the knowledge, enrich the community. Happy learning! 🌟
r/Python • u/Pleasant-Aardvark258 • Aug 01 '26
Had this discussion the other day and figured I’d throw it to the masses to get thoughts on the best/most pythonic way of approach.
Need to map old column names to new column names as a copy from a json config.
My thoughts are iterate over a dict with
‘’’ {“old_col_name”:”new_col_name”}’’’
And access as
‘’’for k,v in dict.items()
Df.with_columns(k).alias(v)’’’
Colleague things this isn’t clear enough and should be a list of dicts with explicit keys
‘’’ [{“old_col_name”:”old_col_value”
“New_col_name”:”new_col_value”}]’’’
And the access as
‘’’for dict in list_of_dicts:
Old_col = dict[“old_col_name”]
New_col = dict[“new_col_name”]’’’
I’ve got a good few reasons why I think mine is the better option but thought I’d get some other opinions to see if I’m missing anything obvious? Which would you choose and why?
Edit: shouldn’t write these things while on the toilet in a rush. The description is wrong, it should be renaming via a copy so that the original column is left unchanged.
r/Python • u/nathan12343 • Jul 30 '26
NumPy is the foundational array library in the scientific Python ecosystem. Every numerical, machine learning, and data analysis library in Python either depends on NumPy directly or interoperates with it. As the free-threaded build of CPython matures, NumPy is one of the first libraries that users reach for when trying to scale CPU-bound numerical workloads across multiple cores using threads.
In this blog post, I will walk through the work I did over the last few months in both NumPy and CPython to eliminate the multi-threaded scaling bottlenecks that were preventing NumPy from scaling on free-threaded Python.
https://labs.quansight.org/blog/scaling-numpy-on-free-threaded-python
r/Python • u/ernestrc • Jul 30 '26
Author here. This is a nine-year account of building Rune, a new IDE (1.1 added support for Python). It started when my Vim's go-to-definition broke in 2017 and I decided to build my own editor rather than adopt an IDE: https://rune.build/blog/the-rise-of-the-command-line
r/Python • u/AutoModerator • Jul 31 '26
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!
Let's keep the conversation going. Happy discussing! 🌟
r/Python • u/crmaureir • Jul 30 '26
Hey there,
for the people using PySide for UI applications, after having solely Android support, there was a new announcement that iOS is now supported, and will be available in the upcoming PySide release:
https://www.qt.io/blog/python-mobile-app-development-bringing-pyside6-on-ios
I have been following the work by the BeeWare project, which has been providing iOS support for some time now: https://toga.beeware.org/en/latest/reference/platforms/iOS/ and recently the work from the Flet team as well: https://flet.dev/blog/flet-for-ios/
What I wanted to achieve with this post, is to know any project that you know is currently on iOS and developed with Python and some UI framework, because time to time we see nice "calculator app" being showcases in places, but a more official application of something is what I have been failing to find.
Of course, the goal of "I have my code here, and I just want to deploy it to iOS" is completely understandable, but I see haven't found some very cool apps somewhere, that we know are based on Python.
Last but not least, I guess you have been noticed that starting from 3.15 we will be able to download Python for iOS from python.org: https://www.python.org/downloads/ios/
r/Python • u/AutoModerator • Jul 30 '26
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.
Let's help each other grow in our careers and education. Happy discussing! 🌟
r/Python • u/BeamMeUpBiscotti • Jul 28 '26
attrs is a package that helps you write classes quickly by automatically generating boilerplate methods like __init__.
While some of the features from attrs has been standardized in the form of dataclass and dataclass_transform, dataclasses only support a subset of features and attrs is still widely used today.
It's very tricky to type check dynamic code that synthesizes & transform fields and methods, so historically attrs users that want type checking have either had to:
dataclass_transformThis summer, my intern has built out dedicated support for attrs in Pyrefly, allowing attrs users to finally have fast and accurate type checking for the full range of attrs features.
You can read more about what we added here: https://pyrefly.org/blog/pyrefly-attrs/
This feature will be available in the upcoming 1.2.0 stable release of Pyrefly. You can try it out today in development releases starting from 1.2.0-dev1 (early feedback is appreciated!)
r/Python • u/AutoModerator • Jul 28 '26
Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.
Let's deepen our Python knowledge together. Happy coding! 🌟
r/Python • u/abitrolly • Jul 28 '26
I can go next/prev pages in Rust documentation with right/left arrow keys, but not in Python docs (including Sphinx and devguide). Python developers seem to be strictly against it. They say it affects accessibility and horizontal scrolling. Downvote me if I am wrong, but accessibility it not just for impaired users.
r/Python • u/AutoModerator • Jul 27 '26
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.
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
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
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 • u/BTWigley • Jul 27 '26
Spent an evening a couple of weeks ago working out why cache hits were zero and webhook idempotency was falling through to the database. Redis was fine. Up, reachable, ping succeeded.
The connect method was roughly this:
try:
client.ping()
self._connected = True
logger.info("redis_connected", host=parsed.hostname, port=parsed.port, db=parsed.path)
return True
except Exception as e:
logger.warning(f"Redis connection failed: {e}")
self._connected = FalseThat logger call is structlog style. The logger is a stdlib logging.Logger, which doesn't take arbitrary kwargs, so it raises TypeError: Logger._log() got an unexpected keyword argument 'host'.
It raises after ping succeeds and after _connected is set to True. So it lands in the except, logs "Redis connection failed", flips _connected back to False, and Redis is off for the whole app. Caching disabled, idempotency on the DB.
The fix was one line, an f-string instead of kwargs.
What still bugs me is that every signal pointed away from it. Redis itself was healthy. The connection genuinely worked. The only artifact was a log message saying it had failed, which is the last thing you distrust when you're trying to find out why something failed.
Anyone else had one where the logging was the bug?
r/Python • u/PastEar9661 • Jul 27 '26
Error handling in Python usually means nested try/except blocks or if error: checks littering code.
Us programmers, though, are notoriously lazy, and for a good reason: we don't want to waste any more time writing boilerplate than we have to.
The solution?
Monads, a really neat functional programming pattern that provides an easier way to handle things like errors, optional values, or even asynchronous results.
I wrote a short guide that builds up the idea of a Monad from scratch using a Python game inventory example, free to read here: https://dev.to/ein-monarch/what-the-are-monads-a-beginners-guide-3pdo
Any comments on the guide? Have you ever used a Monad in Python before, and did it make things better?