My favorite new features in Python 3.14
Posted by treyhunner@reddit | Python | View on Reddit | 48 comments
I have been using Python 3.14 as my primary version while teaching and writing one-off scripts for over 6 months. My favorite features are the ones that immediately impact newer Python users.
My favorite new features in Python 3.14:
- All the color (REPL & PDB syntax highlighting, argparse help, unittest, etc.)
- pathlib's copy & move methods: no more need for shutil
- date.strptime: no more need for datetime.strptime().date()
- uuid7: random but also orderable/sortable
- argparse choice typo suggestions
- t-strings: see awesome-t-strings for libraries using them
- concurrent subinterpreters: the best of both threading & multiprocessing
- import tab completion
I recorded a 6 minute demo of these features and wrote an article on them.
tomz17@reddit
Mehhhhhhhhh. AFAIK (and correct me if I am reading this wrong), even though multiple interpreters can now share they same process they still cannot share the same python objects in memory, even if those objects are fundamentally immutable (e.g. strings). So the only thing you are really saving vs. multiprocessing is the overhead of starting another OS process, which is fairly minimal on modern systems and only occurs when you are setting up the pool. Meanwhile you are losing the actual process isolation by going this route (e.g. segfaulting in a thread will now take down the entire process)
The thing that might actually be cool would be a way to give a thread a zero-overhead (i.e. no pickle, no queue/pipe, etc.) immutable view of the current global/local namespace.
Brian@reddit
Also potentially the cost of marshalling data. It'll still need to create new python objects on each interpreter, but sharing certain primitives in-process means it's essentially a memcpy rather than having to marshall it through some IPC mechanism, so could be cheaper if you need to pass a lot of data between interpreters. Though anything more complicated (ie. not just int/str/bytes etc) is still likely going to need to go through something like pickle to transfer it.
Another advantage might be better portability - multiprocessing works a bit differently on windows vs linux due to the fork vs spawn model, so might avoid certain cross-platform complications.
But yeah, I'm not sure it ultimately buys you that much over processes currently.
tomz17@reddit
So I have not looked at the source code, but the documentation made it sound like all inter-interpreter coms were still marshaled.
Brian@reddit
They are, but primitives like int/str etc have a protocol to copy them across. It's still marshalled, but it's somewhat cheaper (basically a memcpy rather than pickle/ipc/unpickle)
BasedAndShredPilled@reddit
It's funny how much color can make a difference in readability. That's the main reason I like sublime text editor.
spinwizard69@reddit
If all 3.14 got was color that would have justified the new version number. From my perspective this is huge. I'm old enough to remember writing code on monochrome screens, color is a revelation in clarity. Things just pop out at 3 in the morning that can hide forever in a monochrome world.
treyhunner@reddit (OP)
It really is. Even ignoring readability, it's interesting how much friendlier argparse CLIs, pdb, etc. feel just due to a little bit of color.
Gingehitman@reddit
As a computational biologist I hear pdb and immediately think that they’ve added syntax highlighting for protein data bank files. Sad to hear it’s just the niche python debugger :P
big-papito@reddit
In the year of our Lord 2025, one would think out interfaces would not be black and white, eh.
spinwizard69@reddit
Color will be huge. It often breaks up text in the way formatting, indenting and the like can't. At least with my mind it does. Often color is the thing that triggers this isn't what I thought it was in my head due to not matching what should be the same type data. I'm sure some will not like it, but I see it as a way to keep Python uncluttered yet improved. One the flip side more clutter was added.
By the way Trey - thanks for the contribution. Remember it isn't the size but how you use it.
ZeeBeeblebrox@reddit
Can't wait to start using these in my library in 2027.
Spitfire1900@reddit
Jokes on you. Since we want to stay on a ”supported” version of Python but also have to deploy to Windows we upgrade about ~2-4 months after a new release.
Scypio@reddit
Sad 3.7 support noises...
flooberoo@reddit
Genuinly curious: Python 3.7 security support ended years ago. How does your company/clients afford to take such risks?
Scypio@reddit
Internal solution, no outside access to it. Sure, changing version to something supported is not a big task (and already in the backlog) but "business cases" take precedent, so it is a bottom of the barrel when it comes to priority.
flooberoo@reddit
I'm still amazed that your business doesn't see value in security. Is it maybe a small business with no/limited security policies? Genuinly curious about the use case and logic behind it.
Scypio@reddit
Oh no, big multinational. And - hold on to your hat - there is still a framework used that is 2.7 based. It is not actively developed and only bug fixes are made for it.
flooberoo@reddit
Which country is this in? I strongly suspect it's probably violating some internal policy that you maybe just aren't aware of?
Scypio@reddit
A multinational? It exists across multiple countries in Scandinavia, it has some parts in India, used to do business in US before Trump got all stupid and tariffed everything.
How nice and condescending of you. Policies are not my job, I can only suggest changing versions once a sprint. Will it ever be taken into one? Maybe some day.
flooberoo@reddit
Following company policies is not your job? What a terrible attitude. And are you sure you don't need to follow policies? Does your company handbook really have an exception carved out for you?
Jrix@reddit
Most company policies are retarded.
Scypio@reddit
Don't put your words in my mouth. You deliberately pretend not to understand what I wrote.
georgehank2nd@reddit
"internal". 'nuff said.
If you have an inside attacker, you have a bigger problem than a new Python version could solve.
flooberoo@reddit
Defence in depth. Nuff said.
gobitecorn@reddit
Haven't used Python to code anything since 3.7 to be real. I still stick to around the range 3.5 to 3.7 and the only new feature I bothered with was f-strings. So I'm not sure what new features there are but is the syntax highlighting is like ipython? Also I need to look more bout this import tabcomplete
treyhunner@reddit (OP)
The new REPL isn't quite as feature-rich as IPython but in terms of block-level editing, pasting text, history mode, etc. it mostly "just works" the same way that IPython does. Here's an article I wrote on the new REPL. It was by far my favorite feature in Python 3.13.
forgotpw3@reddit
Oh, the Multi interpreter and datetime and t strings :D
lukerm_zl@reddit
The
suggest_on_error
parameter in ArgumentParser seems really useful! Shouldn't it be True but default in a future version? Are there any downsides to having this always active? (I don't think it would affect automated pipelines 🤔)treyhunner@reddit (OP)
It's possible that someone is parsing the output of a command-line utility and a change in the output. That was the primary reason for defaulting it to False.
You can start using it even before dropping support for older Python versions with
parser.suggest_on_error = True
(noted in the docs).lukerm_zl@reddit
Great video by the way!!
treyhunner@reddit (OP)
Thanks!
I hate 20 minute videos that could be 3 minute videos, so I try to keep them all short and to the point.
Professor_Entropy@reddit
You guys are sleeping on `python -m pdb -p $pid`
Ebisure@reddit
Is there any way for pathlib to auto create parent dirs when saving a filepath?
treyhunner@reddit (OP)
Not exactly, but also kind of. You can do this when creating a directory and you can also tell pathlib to not complain if the directory already exists:
from pathlib import Path
path = Path("some_directory/some_file.txt")
path.parent.mkdir(exist_ok=True, parents=True)
path.write_text("...")
Ebisure@reddit
That's how I do it too. Though I often forget to create the parent dirs. Would be nice if path.write_text has option to auto create intermediate paths
MrMxylptlyk@reddit
Don't get how t strings differ from f strings
TheGS@reddit
The output of an f-string is the final string. A t-string can be passed to another utility that can further modify the parts of the t-string, doing validation, inserting things like tags, further formatting, etc
treyhunner@reddit (OP)
They have exactly the same syntax, but t-strings return the not-yet-assembled parts of the string. You won't use a t-string except to pass one to a utility which is specifically designed to accept them.
cgoldberg@reddit
Syntax highlighting in the REPL is 🔥🔥🔥
Quirky-Cap3319@reddit
Hmmm… I use argparse quite lot and that sounds interesting
treyhunner@reddit (OP)
If you run your script on python3.14, it'll automatically have colorized
--help
output. No code changes needed.bulletmark@reddit
I write a lot of Python CLI apps using
argparse
so this is my favorite 3.14 feature.styyle@reddit
I barely use the repl, but looking forward to sprinkling uuid7 in the codebase
treyhunner@reddit (OP)
Just keep in mind that mixing
uuid4
anduuid7
in an existing codebase doesn't do much good (since only the new UUIDs will be orderable).chub79@reddit
uuid7 is such a welcome feature.
kimjongun-69@reddit
Nice
Blue_Dude3@reddit
There is an awesome repo for t strings already?
treyhunner@reddit (OP)
The folks who wrote the PEP started it shortly after t-strings were merged.
There aren't many libraries accepting t-strings yet, but I imagine that will gradually change now that 3.14 is released.