r/Python Oct 07 '24

News Python 3.13 released

https://www.python.org/downloads/release/python-3130/

This is the stable release of Python 3.13.0

Python 3.13.0 is the newest major release of the Python programming language, and it contains many new features and optimizations compared to Python 3.12. (Compared to the last release candidate, 3.13.0rc3, 3.13.0 contains two small bug and some documentation and testing changes.)

Major new features of the 3.13 series, compared to 3.12

Some of the new major new features and changes in Python 3.13 are:

New features

  • A new and improved interactive interpreter, based on PyPy's, featuring multi-line editing and color support, as well as colorized exception tracebacks.
  • An experimental free-threaded build mode, which disables the Global Interpreter Lock, allowing threads to run more concurrently. The build mode is available as an experimental feature in the Windows and macOS installers as well.
  • A preliminary, experimental JIT, providing the ground work for significant performance improvements.
  • The locals() builtin function (and its C equivalent) now has well-defined semantics when mutating the returned mapping, which allows debuggers to operate more consistently.
  • A modified version of mimalloc is now included, optional but enabled by default if supported by the platform, and required for the free-threaded build mode.
  • Docstrings now have their leading indentation stripped, reducing memory use and the size of .pyc files. (Most tools handling docstrings already strip leading indentation.)
  • The dbm module has a new dbm.sqlite3 backend that is used by default when creating new files.
  • The minimum supported macOS version was changed from 10.9 to 10.13 (High Sierra). Older macOS versions will not be supported going forward.
  • WASI is now a Tier 2 supported platform. Emscripten is no longer an officially supported platform (but Pyodide continues to support Emscripten).
  • iOS is now a Tier 3 supported platform.
  • Android is now a Tier 3 supported platform.

Typing

  • Support for type defaults in type parameters.
  • A new type narrowing annotation, typing.TypeIs.
  • A new annotation for read-only items in TypeDicts.
  • A new annotation for marking deprecations in the type system.

Removals and new deprecations

  • PEP 594 (Removing dead batteries from the standard library) scheduled removals of many deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, lib2to3.
  • Many other removals of deprecated classes, functions and methods in various standard library modules.
  • C API removals and deprecations. (Some removals present in alpha 1 were reverted in alpha 2, as the removals were deemed too disruptive at this time.)
  • New deprecations, most of which are scheduled for removal from Python 3.15 or 3.16.

More details at https://docs.python.org/3.13/whatsnew/3.13.html

621 Upvotes

97 comments sorted by

69

u/whatsnewintech Oct 07 '24

I'm excited to try out ReadOnly properties.

I'm less enthusiastic about TypeIs, since like TypeGuards they can produce unsoundness when implemented incorrectly (or worse, when implemented correctly but then later the type in question changes).

75

u/sitric28 Ignoring PEP 8 Oct 08 '24

As someone new to Python, I have no idea what any of this means but it sounds good so... Nice 👍

46

u/BostonBaggins Oct 08 '24

I'll tell you one fun fact

The people behind this are changing the world

You wanna know how I know? I got a dam job using python and they asked nothing in return

Bravo Python core team

22

u/sonobanana33 Oct 08 '24

The entire concept was pioneered by GNU and gcc. Before that you had to buy something to be a developer

15

u/marios1861 Oct 08 '24

the world would be such a dark place if free open source software hadn't proliferated. You'd need to be a big company to write a basic C program, a simple GUI, a small website. The monopolies that would have formed make my head spin.

2

u/nikvid Oct 08 '24

Buy what?

5

u/sonobanana33 Oct 08 '24

A compiler?

5

u/BostonBaggins Oct 08 '24

A Hyundai Sonata

1

u/AR_SM Nov 07 '24

Yeah, by yet again doing dependency breaking changes no one asked for. So fucking tired of Python.

1

u/BostonBaggins Nov 07 '24

Re platform it

3

u/jbudemy Oct 08 '24

I'm new to Python and a former Perl programmer. I like Python much more than Perl. Python makes it much easier to connect to databases, which I do a lot.

Perl on Linux required me to set up an ODBC and some other drive at the OS level which was tedious and prone to errors and had lots of misinformation on the internet where examples just didn't work.

47

u/riklaunim Oct 07 '24

Curious what actually changed for iOS and Android?. Those PEPs don't say it directly ;)

143

u/malcolm_smith Oct 07 '24

Hi, I'm the author of the Android PEP. The main significance of "tier 3 support" is that Python 3.13 now passes its test suite on iOS and Android, is automatically re-tested after every change, and the development team will make a reasonable effort to maintain this.

There's still no official Python download for these platforms, so the recommended way to embed Python in a mobile app is to use one of the third-party tools linked in the documentation:

3

u/7Shinigami Oct 08 '24

Thank you! :)

1

u/darthwalsh Oct 08 '24

It was also unclear to me if the change was from tier 2 to tier 3, or from Unsupported to tier 3. Maybe they can change the release note wording

3

u/malcolm_smith Oct 09 '24

In Python 3.13:

  • iOS and Android went from unsupported to tier 3.
  • WASI went from tier 3 to tier 2.
  • Emscripten went from tier 3 to unsupported, but we're planning to reverse that in Python 3.14.

6

u/Atlamillias Oct 07 '24 edited Oct 07 '24

I think the only "change" was adding them to the list of "supported platforms". They're on the bottom rung of the latter though, so they don't have official build support (yet, i think?). Releases won't be blocked due to issues on those platforms, either.

50

u/chub79 Oct 07 '24

Congratulations to the core dev team!

16

u/spidLL Oct 07 '24

Is there a list of the libraries supporting the no GIL mode? Or for the moment it’s safe to assume none does.

16

u/james_pic Oct 07 '24 edited Oct 07 '24

It's unlikely there are any with official support, and last I heard the packaging authority hadn't yet agreed a way for libraries to signal support on PyPI.

In terms of what will happen if you just install them and run them with a free threaded interpreters anyway:

Pure Python modules will run in no-GIL mode and in theory they should Just Work. The GIL offered few usable guarantees to pure Python code. The only usable guarantee it offered was linearizability (which it still does guarantee), so any pure Python code that breaks in no-GIL mode probably has a bug without it too (albeit a bug that would be triggered much less frequently, or that might not be triggerable on Python 3.10 or above due changes to which opcodes are GIL release points). In practice, it's experimental and there will be teething issues even with pure Python code. 

Libraries with native code will run in "with GIL" mode unless their binaries flag that they're no-GIL compatible. Native code was able to rely on the GIL more strongly than pure Python code, so it's required to explicitly opt out of the GIL.

10

u/martinkoistinen Oct 07 '24

Yea. Someone needs to setup a website tracking this like we had during the big migration to 2.7 -> 3.5 days.

2

u/FlowLab99 Oct 09 '24

This GitHub project has a tracker: https://py-free-threading.github.io

49

u/LessonStudio Oct 07 '24 edited Oct 07 '24

Really juicy releases like this one make me cry as I just know that a few key libraries will take eons to catch up.

I'm usually looking at you tensorflow.

31

u/QueasyEntrance6269 Oct 07 '24

Tensorflow? Just let it go bro, even Google is using JAX these days

10

u/accforrandymossmix Oct 07 '24

Tensorflow? Just let it go bro

this sounds like a don't do drugs campaign. combine it with

squeeze an orange

2

u/LessonStudio Oct 10 '24

While I normally ignore anyone who uses "bro" or worse "brah"; your comment is on top of someone I respect yelling JAX JAX JAX. So, I dug into it, and happy days. It also didn't complain about 3.13.

But, today, I just went back to 3.12 as esp-idf is the version bastard of the week.

I'm not a fan of virtual environments in this sort of system as it ends up being a giant pain in the ass; and 3.12 is still really good.

While some people crap on keras, I am very much enjoying how it keeps things simple, and uses jax, torch, and tensorflow as desired.

5

u/david0aloha Oct 07 '24

Is pytorch better in this regard?

3

u/MardiFoufs Oct 09 '24

In my experience, yes. Very much so. Not sure if it's just me but it feels like they have gotten a lot better at it too, 1.0x releases of pytorch were a bit slower to catch up. But pytorch has supported 3.12 very quickly.

8

u/michaelhoffman Oct 07 '24

What is a juice release?

34

u/Grove_street_home Oct 07 '24

Happens when you squeeze an orange

3

u/DuckDatum Oct 07 '24

I’m supposed to be using an orange?

8

u/chinnu34 Oct 07 '24

If you're not squeezing an orange while coding, are you even coding?

2

u/tehdlp Oct 08 '24

Do you know what happens when you squeeze a python?

2

u/odaiwai Oct 08 '24

In coding, Python squeezes you!

27

u/cybaritic Oct 07 '24

Am I missing something or are we all overlooking the removal of the GIL? That's a major change.

26

u/orad Oct 07 '24

It’s not fully there yet, but it’s still exciting

12

u/martinkoistinen Oct 07 '24 edited Oct 07 '24

Yes, that’s exciting for stdlib only projects, lol. This is where it starts, but it really gets moving when the dependencies start supporting it, like Numpy, and Pandas.

20

u/caks Oct 08 '24

Numpy and Pandas probably are the least GIL-dependent libraries tbh. They release the GIL for computations.

3

u/[deleted] Oct 08 '24 edited Oct 12 '24

[deleted]

1

u/FlowLab99 Oct 09 '24

Sam Gross, the main developer working on free threaded python already had made wheels for numpy and others key libs.

I’m not sure when official releases from the project teams will come.

https://github.com/colesbury/nogil

If you want to go spelunking, you can probably find no-gil compatible forks of various projects in his repositories

https://github.com/colesbury?tab=repositories

12

u/jryan14ify Oct 07 '24

Can anyone tell me what the tier 2 and tier 3 releases mean? I’d like to read more about that

12

u/commy2 Oct 07 '24

The __replace__ protocol and the strict keyword for itertools.batched are underrated.

6

u/k_z_m_r Oct 07 '24

Does anybody have a recommendation for a library to replace telnetlib? We use this one regularly. Unfortunately, the async nature of telnetlib3 doesn’t fit in our architecture.

8

u/nicholashairs Oct 07 '24

I don't have a replacement, however, assuming that the library is pure python, you'd be able to vendorise it based on the last version in the source tree.

3

u/k_z_m_r Oct 08 '24

Yeah, it's written primarily with socket. Cannibalizing the code seems very possible.

3

u/cdrt Oct 08 '24

Why not just pull the library out of an old release and vendor it? It’s only one extra file in your codebase

Or you could try this: https://pypi.org/project/standard-telnetlib/

3

u/k_z_m_r Oct 08 '24

It’s just company policy when it boils down to it. But I appreciate this link! Thanks!

1

u/sblinn Oct 12 '24

Might be better imho to wrap telnetlib3 than vendorize telnetlib. Plus you’ll learn how to deal with asyncio from your code base. (This is basically what I did to embed a telnet server in a Pygame app.)

3

u/No-Statistician-2771 Oct 07 '24

Now that iOS and Android are Tier 3 supported platform, it would be nice that it would be possible to have a github runner for those to run some test and see if our librarie break on it

3

u/verus54 Oct 08 '24

W for GIL release

3

u/ragnartheaccountant Oct 08 '24

Sounds like the biggest features are experimental/preparatory for big updates in the future. These sound like they will be great eventually, but currently uncharted waters for most users.

With all these upcoming features, is there any bloat concern with the dev team?

9

u/commandlineluser Oct 07 '24

Shame about no vi editing mode in the new interpreter.

The new REPL will not be implementing inputrc support, and consequently there won't be a vi editing mode.

4

u/ThiefMaster Oct 07 '24

No inputrc support... does that also mean:

  • no ^W to delete a word
  • no ctrl+left/right to jump over words

If yes: Who will want to use that?

4

u/commandlineluser Oct 07 '24 edited Oct 07 '24

^w works.

ctrl left/right appear to do nothing for me.

I can't seem to locate any documentation on what bindings there are.

(^r / ^s are backward/forward history, for example)

3

u/bulletmark Oct 07 '24

Damn, that means the new 3.13 REPL has gone backwards from my perspective. :(

2

u/commandlineluser Oct 07 '24

Yeah :-/

Thought it may be able to replace ptpython for me, but apparently not.

The "old repl" is also still available.

1

u/Ran4 Oct 07 '24

That's... horrible :(

Does c-a/c-e work at least?

1

u/commandlineluser Oct 07 '24

Yep, those work.

2

u/VovaViliReddit Oct 08 '24

An experimental free-threaded build mode, which disables the Global Interpreter Lock, allowing threads to run more concurrently. The build mode is available as an experimental feature in the Windows and macOS installers as well.

A preliminary, experimental JIT, providing the ground work for significant performance improvements.

I will live to see Python become not awfully slow, nice.

2

u/IAMARedPanda Oct 08 '24

I feel like the JIT will in the end be more impactful than no GIL.

2

u/sblinn Oct 12 '24

Is this basically looking to apply something like Numba automatically everywhere?

1

u/IAMARedPanda Oct 12 '24

That's my understanding

2

u/Critlist Oct 10 '24

Unlocked GIL and a JIT??? WOW

1

u/EmployeeIndependent6 Oct 08 '24

How to install on Bookworm? I get a "package not found" error?

3

u/[deleted] Oct 08 '24

[deleted]

1

u/EmployeeIndependent6 Oct 08 '24

Ok, thanks.

2

u/gmes78 Oct 08 '24

Look into Rye or Pyenv if you want to use a version of Python other than the one provided by your system for your projects.

1

u/Attair Oct 08 '24

Awesome Sauce!

1

u/Exciting-Ad2203 Oct 09 '24

so what about the per interpreter feature which will be native to python?

1

u/behitek Oct 10 '24

When testing, I see Python3.13t a bit slower than Python3.13 on Single thread test. Can anyone know the reason?

python3.13 gil_test.py 
Python version :  3.13.0 (main, Oct  8 2024, 08:51:28) [GCC 11.4.0]
Single Thread:  1.4370562601834536 seconds
Multi Thread:  1.3681392602156848 seconds
-----
python3.13t gil_test.py 
Python version :  3.13.0 experimental free-threading build (main, Oct  8 2024, 08:51:28) [GCC 11.4.0]
Single Thread:  1.862126287072897 seconds
Multi Thread:  0.3931183419190347 seconds

2

u/classy_barbarian Oct 10 '24

The free threaded build is slower in single-thread performance. That's been tested and confirmed by several people. Something to do with the added overhead they needed to make it work. It can be significantly faster in multi-threaded workloads, but only if you're actually trying to split CPU-bound work across 3 or more cores. (At 1 core its slower, at 2 cores its on par)

1

u/behitek Oct 10 '24

This is my code for the test

import sys
import threading
import time

print("Python version : ", sys.version)

def worker():
    sum = 0
    for i in range(10000000):
        sum += i


n_worker = 5
# Single thread

start = time.perf_counter()
for i in range(n_worker):
    worker()
print("Single Thread: ", time.perf_counter() - start, "seconds")


# Multi thread
start = time.perf_counter()
threads = []
for i in range(n_worker):
    t = threading.Thread(target=worker)

    threads.append(t)
    t.start()

for t in threads:
    t.join()
print("Multi Thread: ", time.perf_counter() - start, "seconds")

1

u/sblinn Oct 11 '24

And now we wait for our favorite libraries to support 3.13-nogil awwwww yeaahhhhh

2

u/theXpanther Oct 07 '24

RIP CGI, guess php is once again the only option. Usually the type of servers to support CGI will not allow installing modules.

3

u/[deleted] Oct 08 '24

[deleted]

1

u/theXpanther Oct 08 '24

They tend to run a few years behind on python, that's true. It will be an issue in a few years

1

u/sblinn Oct 12 '24

Is the cgi module documentation wrong:

The FieldStorage class can typically be replaced with urllib.parse.parse_qsl() for GET and HEAD requests, and the email.message module or multipart for POST and PUT.

1

u/vivainio Oct 07 '24

I wonder if the new Android support means pygame will be more convenient to run

2

u/MyreMyalar Oct 08 '24

Not yet, for one there is no official android python release, for two we'd have to get SDL building natively for android and then there would be all the testing and fixing of the native pygame C code.

Maybe brought it closer though.

-4

u/jmreagle Oct 07 '24

On the interactive interpreter, doesn't everyone use iPython anyway?

24

u/mrcaptncrunch Oct 07 '24

Nope. Not at all.

2

u/jryan14ify Oct 07 '24

Why would I use the python default interactive interpreter rather than IPython?

12

u/mrcaptncrunch Oct 07 '24

I personally use the default one and not ipython.

A couple of reasons, but the big one is that I have the exact same things as in my code.

I sometimes have to get into environments where I can't install other packages. I also had an issue on a small system where it just wouldn't install or run (can't remember).

There are some nice things in it, but if I'm doing anything complex for testing, I'm usually also working on a bigger piece and have all my tools and ide's available.

Not saying it should be done my way and one shouldn't look at it. But if you need the exact same things, you get the exact same things using the built-in one vs ipython.

7

u/catcint0s Oct 07 '24

extra deps

1

u/david0aloha Oct 07 '24

This was my impression too, but I may be wrong.

1

u/mok000 Oct 08 '24

I always have a session of iPython running, and use it extensively when coding and debugging.

-21

u/Difficult_West_5126 Oct 07 '24

Which backend framework will be benefit from this update ? Django flask or fastapi? Which ui framework will be receiving a performance boost? pyqt or tkinter or …? And does it mean python is more powerful in 3D rendering?

32

u/TSM- 🐱‍💻📚 Oct 07 '24

If the brief and informal overview is too hard to read, you don't need to worry about the changes. They won't affect you

8

u/WJMazepas Oct 07 '24

Which backend framework will be benefit from this update ? Django flask or fastapi?

For now, none of them.

Which ui framework will be receiving a performance boost? pyqt or tkinter or …?

None of them posted benchmarks tests with those frameworks

And does it mean python is more powerful in 3D rendering?

Most likely no

1

u/Fernando7299 Oct 07 '24

Why so many down votes?

12

u/mrcaptncrunch Oct 07 '24

Because this is a python release. Those things would be supported by those packages and projects and would be handled by releases on their side. None of them have said anything.

These are also behind experimental flags. If you're asking on reddit like OP, they shouldn't be messing with these.

-3

u/Difficult_West_5126 Oct 07 '24

I am sorry if my questions pissed off someone. I just wonder about after those platforms adopted the new version of python in the future, maybe they will be more competitive, right?

5

u/Ran4 Oct 07 '24

There's not really anything in this update that will have a major impact on most libraries.

The one exception is the option to remove the GIL, which might have some performance impact on some multithreading code.