Python
- Python 3.14.0 alpha 2discuss.python.org Python 3.14.0 alpha 2
Alpha 2? But Alpha 1 only just came out! This is an early developer preview of Python 3.14 Major new features of the 3.14 series, compared to 3.13 Python 3.14 is still in development. This release, 3.14.0a2 is the second of seven planned alpha releases. Alpha releases are intended to make it ea...
- Python-related happenings for the week of 14 October 2024
Events
- 14 October
- CLEpy meetup - via https://fosstodon.org/@clepy/113311328924148486
Releases
- 14 October
pyparsing
3.2.0 - via https://fosstodon.org/@ptmcg/113302603878074247
- 15 October
eve
2.2 - via https://fosstodon.org/@nicola/113310333550705121pillow
11.0.0 - via https://mastodon.social/@hugovk/113312137194438039 (and https://fosstodon.org/@pillow/113312110767354794)validate-pyproject
0.21 - via https://fosstodon.org/@henryiii/113312246938821428
- 14 October
- Python 3.13.0 (final) has been releaseddiscuss.python.org Python 3.13.0 (final) has been released
After all the shenanigans two weeks ago – everyone discovering nasty little problems in release candidate 2 – the last week was suspiciously quiet, and therefore I can finally say: Python 3.13.0 is now available This is the stable release of Python 3.13.0 Python 3.13.0 is the newest major release...
- Python 3.12.7 and 3.13.0rc3 releaseddiscuss.python.org Python 3.12.7 and 3.13.0rc3 released
This is not the release you’re looking for… (unless you’re looking for 3.12.7.) Because no plan survives contact with reality, instead of the actual Python 3.13.0 release we have a new Python 3.13 release candidate today. Python 3.13.0rc3 rolls back the incremental cyclic garbage collector (GC), wh...
- Is Python Really That Slow?blog.miguelgrinberg.com Is Python Really That Slow?
My standard response when someone asks me how I deal with Python being such a slow language is that Python is by far the fastest to write, cleanest, more maintainable programming language I know, and…
via https://mstdn.social/@miguelgrinberg/113504754524264965
- Python's pathlib modulewww.pythonmorsels.com Python's pathlib module
Python's pathlib module is the tool to use for working with file paths. See pathlib quick reference tables and examples.
via https://mastodon.social/@treyhunner/113504959975116212
- What's new in pip 24.3ichard26.github.io What's new in pip 24.3
pip 24.3 is a small release with a truststore bugfix, error QoL improvements, and one minor deprecation of noncompliant wheel filenames.
via https://fosstodon.org/@ichard26/113494296968334680
- All About Decorators in Pythonwww.pythonmorsels.com All About Decorators in Python
Screencasts, exercises, and talks all about decorators in Python.
- Sending cross-email-client-compatible emails with MJML and Pythonrkblog.dev Sending cross-email-client-compatible emails with MJML and Python
Sending a good-looking email is not easy due to limited and varying HTML support by email clients. MJML can however help with this problem.
- PUG ( web template engine ) for Python 🐍
Hi,
I've discover haml and pug [^1] ( both web template engine )
It's totally Pytonic ! ( and make even more sense to use it with python rather than JS 🤮 )
I've look, if it exist for Python, but so far, I've found only
The first, only convert
pug
into another template :/ \ The second, didn't pass the alpha version. \ The third, require dependence, not maintained etc.. \So I didn't found a Python package that could do haml/pug to html directly, without too much dependence...
For example:
From
pug html head title Example for Python discuss body h1 Hello world p This is a paragraph.
Tohtml <html> <head> <title>Example for Python discuss</title> </head> <body> <h1>Hello world</h1> <p>This is a paragraph.</p> </body> </html>
Do you know if such thing exist ? \ If not, I will build my own (FLOSS). ( I'm open to any advice to do so :) )
Thanks
[^1]:Pug is a template engine heavily influenced by Haml and implemented with JavaScript 🤮 for Node.js
- How encrypt email title ? ( GnuPG )
Hi,
I'm following my previous post \ How encrypt email with a GnuPG public key ? [ solved ]
So I managed to encrypt the email body with GnuPG public key.. But I don't figure how I can do the same for the title ?! \ ThunderBird manage it.. any idea how ? \ asked on Official Thunderbird forum
Thanks.
- What would Enaml 2.0 look like? | nucleic/enaml | Declarative UIgithub.com What would Enaml 2.0 look like? · nucleic enaml · Discussion #558
Hi Everyone! I've been thinking lately that it might be time for me to devote some real effort into an Enaml version "2.0". I'd like some feedback from the community about that should look like. He...
From Enaml's docs:
> Enaml brings the declarative UI paradigm to Python in a seamlessly integrated fashion. The grammar of the Enaml language is a strict superset of Python. This means that any valid Python file is also a valid Enaml file, though the converse is not necessary true. The tight integration with Python means that the developer feels at home and uses standard Python syntax when expressing how their data models bind to the visual attributes of the UI.
> . . .
> Enaml’s declarative widgets provide a layer of abstraction on top of the widgets of a toolkit rendering library. Enaml ships with a backend based on Qt5/6 and third-party projects such as enaml-web and enaml-native provides alternative backends.
---
A maintainer of Enaml has just opened a brainstorm discussion on the next major development goals.
It's a project I've long admired, though rarely used, and I'd love to see it get some attention and a revamp. I think the bar these days has been raised by projects like QML and Slint, which provide a great context in which to set new goals.
- Python Overtakes JavaScript as Most Popular Language on GitHubwww.omgubuntu.co.uk Python Overtakes JavaScript as Most Popular Language on GitHub
Python has overtaken JavaScript as the most-used language on GitHub, according to the code-hosting platform's latest Octoverse report. The company
- Confused about logical operators (i.e. "comparison operators", or "boolean operators") in Python
Note: The attached image is a screenshot of page 31 of Dr. Charles Severance's book, Python for Everybody: Exploring Data Using Python 3 (2024-01-01 Revision).
---
I thought
=
was a mathematical operator, not a logical operator; why does Python use>=
instead of>==
, or<=
instead of<==
, or!=
instead of!==
?Thanks in advance for any clarification. I would have posted this in the help forums of FreeCodeCamp, but I wasn't sure if this question was too.......unspecified(?) for that domain.
Cheers!
--- Edit: I think I get it now! Thanks so much to everyone for helping, and @FizzyOrange@programming.dev and @itslilith@lemmy.blahaj.zone in particular! \_\
- 🧵 Free-Threaded Wheels
via https://mastodon.social/@hugovk/113385974873569374
>hugovk.github.io/free-threaded-wheels/ tracks how many of the top 360 PyPI packages have free-threaded wheels. > >Green packages (currently 3%) offer has free-threaded wheels > >Uncoloured packages (82%) offer pure-Python wheels > >Orange packages (16%) have no wheels ready for free-threading (yet!) > >See also Quansight Labs' https://py-free-threading.github.io/tracking/ for a smaller yet fine-grained tracker that also includes build tools.
- PyBay 2024 talks on YouTubewww.youtube.com PyBay 2024
PyBay is an annual conference gathering of Pythonistas put on by the Bay Area Python Association. PyBay 2024 was our 9th annual event, held on September 21, ...
via https://fosstodon.org/@pybay/113368608503005830
- Python Big O: the time complexities of different data structures in Pythonwww.pythonmorsels.com Python Big O: the time complexities of different data structures in Python
The time complexity of common operations on Python's many data structures.
via https://mastodon.social/@treyhunner/113367936771761302
- Updating pip in a FUSE cryptomator vault breaks venv
I store my programs in a cryptomator vault which uses a fuse virtual drive (The default on Linux), but when trying to update pip inside a venv I get an error, then any subsequent use of pip also throws an error and {path_to_venv}/lib/python3.12/site-packages/pip/ becomes empty.
I imagine this is an issue that would happen in any FUSE drive although I don't know how to test that.
- OS : Fedora 40
- pip version: 23.3.2 updating to 24.2
- python version: 3.12.7
I already made a bug report on the github
Does anyone know a temporary workaround for this ?
- Started a Simulation with Python Blogquantasticjourney.blogspot.com First Post: Personality Based Simulator
The initial python program, written with Pydroid3, outputted a string (either Jimmy was insulting or Jimmy wasn't insulting) and an associat...
The first post of a new python blog I started if anyone is interested.
- Functional Programming Tips in Pythonbitscomplicated.com Functional Programming Tips in Python
These features will allow you to create code that flows when writing and reads effortlessly
I am including the full text of the post
---
Despite not being a pure functional language, a lot of praise that python receives are for features that stem from functional paradigms. Many are second nature to python programmers, but over the years I have seen people miss out on some important features. I gathered a few, along with examples, to give a brief demonstration of the convenience they can bring.
Replace
if/else
withor
With values that might be
None
, you can useor
instead ofif/else
to provide a default. I had used this for years with Javascript, without knowing it was also possible in Python.python def get_greeting_prefix(user_title: str | None): if user_title: return user_title return ""
Above snippet can shortened to this:
python def get_greeting_prefix(user_title: str | None): return user_title or ""
Pattern Matching and Unpacking
The overdue arrival of
match
to python means that so manyswitch
style statements are expressed instead with convolutedif/else
blocks. Usingmatch
is not even from the functional paradigm, but combining it with unpacking opens up new possibilities for writing more concise code.Let's start by looking at a primitive example of unpacking. Some libraries have popularised use of
[a, b] = some_fun()
, but unpacking in python is much powerful than that.```python [first, *mid, last] = [1, 2, 3, 4, 5]
first -> 1, mid -> [2, 3, 4], last -> 5
```
Matching Lists
Just look at the boost in readability when we are able to name and extract relevant values effortlessly:
python def sum(numbers: [int]): if len(numbers) == 0: return 0 else: return numbers[0] + sum(numbers[1:])
python def sum(numbers: [int]): match numbers: case []: return 0 case [first, *rest]: return first + sum(rest)
Matching Dictionaries
Smooth, right? We can go even further with dictionaries. This example is not necessarily better than its
if/else
counterpart, but I will use it for the purpose of demonstrating the functionality.```python sample_country = {"economic_zone": "EEA", "country_code": "AT"}
def determine_tourist_visa_requirement(country: dict[str, str]): match country: case {"economic_zone": "EEA"}: return "no_visa" case {"country_code": code} if code in tourist_visa_free_countries: return "non_tourist_visa_only" case default: return "visa_required" ```
Matching
Dataclasses
Let’s write a function that does a primitive calculation of an estimated number of days for shipment
python @dataclass class Address: street: str zip_code: str country_code: str
python def calculate_shipping_estimate(address: Address) -> int: match address: case Address(zip_code=zc) if close_to_warehouse(zc): return 1 case Address(country_code=cc) if cc in express_shipping_countries: return 2 case default: return provider_estimate(city.coordinates)
Comprehensions
List comprehensions get their deserved spotlight, but I’ve seen cases where dictionary comprehension would’ve cut multiple lines. You can look at examples on this page on python.org
- First time using the walrus operator!
I am working on a rudimentary Breakout clone, and I was doing the wall collision. I have a function that I initially treated as a Boolean, but I changed it to return a different value depending on which wall the ball hit. I used the walrus operator to capture this value while still treating the function like a bool. I probably could have just defined a variable as the function's return value, then used it in an if statement. But it felt good to use this new thing I'd only heard about, and didn't really understand what it did. I was honestly kind of surprised when it actually worked like I was expecting it to! Pretty cool.
- Python 3.14.0 alpha 1discuss.python.org Python 3.14.0 alpha 1
It’s now time for a new alpha of a new version of Python! This is an early developer preview of Python 3.14 Major new features of the 3.14 series, compared to 3.13 Python 3.14 is still in development. This release, 3.14.0a1 is the first of seven planned alpha releases. Alpha releases are intend...
- Replace `pyenv` with `uv` - Franck Pommereau - Blog
Via https://mamot.fr/@fp/113311994869600315
- Migrating a Python library to uv
Via https://fosstodon.org/@quentinpradet/113311962538364238
- Multiple process or threads? And, why?
(For context, I'm basically referring to Python 3.12 "multiprocessing.Pool Vs. concurrent.futures.ThreadPoolExecutor"...)
Today I read that multiple cores (parallelism) help in CPU bound operations. Meanwhile, multiple threads (concurrency) is due when the tasks are I/O bound.
Is this correct? Anyone cares to elaborate for me?
At least from a theorethical standpoint. Of course, many real work has a mix of both, and I'd better start with profiling where the bottlenecks really are.
If serves of anything having a concrete "algorithm". Let's say, I have a function that applies a map-reduce strategy reading data chunks from a file on disk, and I'm computing some averages from these data, and saving to a new file.
- I know Python basics, what next?learnbyexample.github.io I know Python basics, what next?
Programmers often wonder what to do after learning the basics. This blog post will help you take the next step in your Python learning journey.
- Join the Python Developers Survey 2024: Share your experience!pyfound.blogspot.com Join the Python Developers Survey 2024: Share your experience!
This year we are conducting the eighth iteration of the official Python Developers Survey. The goal is to capture the current state of the l...
- How encrypt email with a GnuPG public key ? [ solved ]
Hi,
I'm already using
python from smtplib import SMTP_SSL from email.message import EmailMessage
To send emails.Now I would like to be able to encrypt them with the public key of the recipient. (
PublicKey.asc
)an A.I provide me this
```python import smtplib from email.message import EmailMessage from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.ciphers.aead import AESGCM
Load the ECC public key from the .asc file
with open('recipient_public_key.asc', 'rb') as key_file: public_key_bytes = key_file.read() public_key = ec.EllipticCurvePublicKey.from_public_bytes( ec.SECP384R1(), public_key_bytes )
Create the email message
msg = EmailMessage() msg.set_content('This is the encrypted email.') msg['Subject'] = 'Encrypted Email' msg['From'] = 'you@example.com' msg['To'] = 'recipient@example.com'
Encrypt the email message using the ECC public key
nonce = bytes.fromhex('000102030405060708090a0b0c0d0e0f') cipher = AESGCM(public_key.public_key().secret_key_bytes) ciphertext = cipher.encrypt(nonce, msg.as_bytes(), None)
Send the encrypted email
server = smtplib.SMTP('smtp.example.com') server.send_message(msg, from_addr='you@example.com', to_addr='recipient@example.com') server.quit()
Save the encrypted email to a file
with open('encrypted_email.bin', 'wb') as f: f.write(ciphertext)
```
I like the approach, only one "low level" import cryptography
but the code seem wrong. if the body has been encrypted as
ciphertext
I don't see this one included while sending the email.How are you doing it ? or do you have good tutorial, documentations ? because I found nothing "pure and simple" meaning not with of unnecessary stuff.
Thanks.
- The Ultimate Guide to Error Handling in Pythonblog.miguelgrinberg.com The Ultimate Guide to Error Handling in Python
I often come across developers who know the mechanics of Python error handling well, yet when I review their code I find it to be far from good. Exceptions in Python is one of those areas that have a…
via https://mstdn.social/@miguelgrinberg/113266572735273155
- Having problems over installing and running py2wasm
I am trying to follow this tutorial (Announcing py2wasm: A Python to Wasm compiler · Blog · Wasmer) and run py2wasm but I am getting this weird problem.
First is that I believe py2wasm might be just an executable like other pip packages I install, or a bat file. (I am fairly new to python and I just want to convert a python code to wasm). But when I head over to
C:\Users\USER\AppData\Local\Programs\Python\Python312\Scripts
where the pip packages are located, I can't seem to find any file related to py2wasm.Running
dir C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages\py2wasm*
to check any related files about the py2wasm folder only leads to this```powershell Directory: C:\Users\USER\AppData\Local\Programs\Python\Python312\Lib\site-packages
Mode LastWriteTime Length Name
---
d----- 04-10-2024 19:54 py2wasm-2.6.2.dist-info ```
Also, before you could ask yeah I could run other pip packages such as yt-dlp.
- The EuroPython 2024 videos and playlist is now live on YouTubewww.youtube.com EuroPython 2024
Welcome to EuroPython 2024, held in Prague, the Czech Republic from 08 - 14 July 2024! Here are all the videos for the conference, brought to you by the Euro...
via https://fosstodon.org/@europython/113242551122295216
- Every dunder method in Pythonwww.pythonmorsels.com Every dunder method in Python
An explanation of all of Python's 100+ dunder methods and 50+ dunder attributes, including a summary of each one.
via https://mastodon.social/@treyhunner/113230504133387015
- uv IS the Future of Python Packaging 🐍📦
YouTube Video
Click to view this content.
via https://mastodon.social/@hynek/113227146595211210
- Developing with Dockerdanielquinn.org Developing with Docker
You'd think that this topic would have been done to death, but given that *every* job I've started in the past 10+ years has used …
I've been writing code professionally for 24 years, 15 of which has been Python and 9 years of that with Docker. I got tired of running into the same complications every time I started a new job, so I wrote this. Maybe you'll find it useful, or it could even start a conversation, but this post has been a long time coming.
Update: I had a few requests for a demo repo as a companion to this post, so I wrote one today. It includes a very small Django demo user Docker, Compose, and GitLab CI.
- New PondRAT Malware Hidden in Python Packages Targets Software Developersthehackernews.com New PondRAT Malware Hidden in Python Packages Targets Software Developers
North Korean hackers use poisoned Python packages from PyPI to spread PondRAT malware, targeting developers in a supply chain attack.
- Github - QuickApiClient: Create fully typed and declarative API clients easilygithub.com GitHub - martinn/quickapiclient: Create fully typed declarative API clients quickly and easily.
Create fully typed declarative API clients quickly and easily. - martinn/quickapiclient
A library for creating fully typed and declarative API clients, quickly and easily.
What would an API client with this library look like?
For a single API endpoint over HTTP GET, it could look something like this:
``` from dataclasses import dataclass import quickapi
An example type that will be part of the API response
@dataclass class Fact: fact: str length: int
What the API response should look like
@dataclass class ResponseBody: current_page: int data: list[Fact]
Now we can define our API
class MyApi(quickapi.BaseApi[ResponseBody]): url = "https://catfact.ninja/facts" response_body = ResponseBody ```
And you would use it like this:
``` response = MyApi().execute()
That's it! Now
response
is fully typed (including IDE support) and conforms to ourResponseBody
definitionassert isinstance(response.body, ResponseBody) assert isinstance(response.body.data[0], Fact) ```
It also supports
attrs
orpydantic
(ordataclasses
as above) for your model/type definitions, including validation and types/data conversion.I have a lot more examples (e.g. POST requests, query string params, authentication, error handling, model validation and conversion, multiple API endpoints) on the repo's README.
I've shared this one here before but it's been a while and I've added a lot of features since.
Github repo: https://github.com/martinn/quickapiclient
- Python: my new uv setup for developmentadamj.eu Python: my new uv setup for development - Adam Johnson
uv is a new, fast Python packaging tool. (I believe it is pronounced as written, “uhv”, rather than spelt out like “you-vee”. This saves a syllable, fitting the tool’s ethos of speed.)
via https://fosstodon.org/@adamchainz/113158552844057284