April 2022 saw the return of the PyCon US conference in person in Salt Lake City. During the conference, Python developers met for the annual Language Summit, and Anaconda announced PyScript, a way to write Python directly inside HTML. Earlier in the month, the Python Software Foundation (PSF) welcomed its new executive director.
Read on to dive into the biggest Python news from the past month!
During his keynote at PyCon US, Anaconda CEO Peter Wang unveiled the PyScript project. PyScript allows you to write Python directly inside HTML and run it in your browser. Consider the following example:
<html> <head> <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /> <script defer src="https://pyscript.net/alpha/pyscript.js"></script> </head> <body> <py-script> print('Hello, World!') </py-script> </body> </html>
<py-script> tag, which can contain any valid Python code. In this case, this is the traditional
Hello, World! greeting.
This is functioning code. You can copy the above code block into a file, such as
hello.html, and save that file to your computer. Then you can open it in your browser, for example by using Ctrl+O or Cmd+O and selecting
hello.html. Alternatively, you can test a similar example immediately on the PyScript demos page.
PyScript provides custom HTML tags, including
<py-script>, which you saw above. There are several other tags as well, with many still in development. However, here are a couple that are immediately useful:
<py-env>lists packages that should be made available in the environment.
<py-repl>creates a working Python REPL to interact with the environment.
The following, slightly more involved, example shows how you can use these features:
<html> <head> <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" /> <script defer src="https://pyscript.net/alpha/pyscript.js"></script> <py-env> - numpy </py-env> </head> <body> <h1 id="title">Magic Squares - Loading ...</h1> <py-script> import numpy as np # Initialize a magic square magic = np.array([[6, 7, 2], [1, 5, 9], [8, 3, 4]]) # Update title to indicate that the page has finished loading pyscript.write("title", "Magic Squares") </py-script> <py-repl id="magic-repl" auto-generate="true"> magic.sum(axis=0) </py-repl> </body> </html>
In this example, you declare that you want to use
numpy in your environment. Then you import
numpy, create an array that represents a magic square, and update the title on the page to indicate that the page is done loading. The REPL will be populated with code that you can run interactively on the web page that you’ve specified with the HTML. A typical session can look like the following:
pyscript.write() can interact with the Document Object Model (DOM) and update the contents of named HTML elements. Additionally, code you write in the REPL can use variables initialized in earlier code.
PyScript is still very much experimental, but the possibilities of this new framework are very exciting. We’re looking forward to following the development of PyScript going forward.
The PyCon US conference is the largest annual gathering in the Python community. It’s been happening every year since 2003, but for the previous two years, the conference went virtual due to the COVID-19 pandemic.
From April 27 to May 3, about 1800 people attended PyCon in Salt Lake City. While the conference was back to an in-person event, the effects of the pandemic were notable: attendence was down compared to 2019, strong health and safety guidelines were in place, and an online option was offered.
As at any PyCon conference, the talks covered a diverse range of topics and were of great quality. All talks were recorded and will be posted on the PyCon Youtube channel once postprocessing is done. This year, there were five keynotes:
- Łukasz Langa on typing and complexity
- Sara Issaoun about the imaging of black holes
- Peter Wang announcing PyScript
- Thomas Wouters and Pablo Galindo Salgado about Python 3.11 and the work of the steering council
- Naomi Ceder on building a great community
Additionally, Georgi Ker, Reuven Lerner, Anthony Shaw, and Lorena Mesa participated in a panel discussion about diversity and inclusion in Python:
The conference was held at the Salt Palace Convention Center. With ample space and long hallways, the venue provided many opportunities to meet with sponsors and other attendees. We at Real Python had our own booth this year, and it was great to meet many of our readers and members.
Although the doors have been closed for this year’s PyCon US, the planning has already started for the next edition. It’ll also be hosted in Salt Lake City, from April 19 to April 27, 2023.
The Python Language Summit is an annual meeting where Python developers can share information and discuss challenges related to CPython and other implementations. This important event for the language typically takes place during the PyCon conference.
This year’s language summit discussed topics such as the future of the global interpreter lock (GIL), optimizations coming out of the faster-cpython and Cinder projects, and a possible change in how f-strings are parsed.
We’re looking forward to learning more about the topics that were presented at the language summit. As in earlier years, the PSF will summarize the discussions on their blog. This year, Alex Waygood will cover the presentations at the summit in a series of upcoming blog posts.
On April 7, the PSF announced that Deb Nicholson would take the reins as PSF executive director. Nicholson has a wealth of experience from other open-source and nonprofit organizations, including the Open Source Initiative, OpenHatch, and the local Boston Python User Group.
We at Real Python welcome Deb Nicholson and are excited to see the continued development of the PSF.
This month, Python news has been dominated by the excitement of PyCon US and the joy of being able to attend in-person conferences again. As the world is slowly returning to normal, more and more user groups, meetups, and conferences will go back to meeting in person. Are there any conferences you’re looking forward to?
What’s your favorite Python news story from April? Let us know in the comments. Happy Pythoning!