Planet Python

Subscribe to Planet Python feed
Planet Python -
Updated: 11 hours 46 min ago

Python Bytes: #376 Every dunder method in a Python Lockbox

Tue, 2024-03-26 04:00
<strong>Topics covered in this episode:</strong><br> <ul> <li><a href=""><strong>🤖</strong></a> <a href=""><strong>On Robots.txt</strong></a></li> <li><a href=""><strong>niquests</strong></a></li> <li><a href=""><strong>Every dunder method in Python</strong></a></li> <li><a href=""><strong>Lockbox</strong></a></li> <li><strong>Extras</strong></li> <li><strong>Joke</strong></li> </ul><a href='' style='font-weight: bold;'data-umami-event="Livestream-Past" data-umami-event-episode="376">Watch on YouTube</a><br> <p><strong>About the show</strong></p> <p>Sponsored by ScoutAPM: <a href=""><strong></strong></a></p> <p><strong>Connect with the hosts</strong></p> <ul> <li>Michael: <a href=""><strong></strong></a></li> <li>Brian: <a href=""><strong></strong></a></li> <li>Show: <a href=""><strong></strong></a></li> </ul> <p>Join us on YouTube at <a href=""><strong></strong></a> to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too.</p> <p><strong>Brian #1:</strong> <a href=""><strong>🤖</strong></a> <a href=""><strong>On Robots.txt</strong></a></p> <ul> <li>Jeff Triplett</li> <li>“In theory, this file helps control what search engines and AI scrapers are allowed to visit, but I need more confidence in its effectiveness in the post-AI apocalyptic world.”</li> <li>Resources to get started <ul> <li><a href="">Block the Bots that Feed “AI” Models by Scraping Your Website</a></li> <li><a href="">Go ahead and block AI web crawlers</a></li> <li><a href="">Dark Visitors</a></li> <li>Django <ul> <li><a href="">Add robots.txt to a Django website</a></li> <li><a href="">How to add a robots.txt to your Django site</a></li> </ul></li> <li>Hugo <ul> <li><a href="">Hugo robots.txt</a></li> </ul></li> </ul></li> <li>Podcast questions: <ul> <li>Should content creators block AI from our work?</li> <li>Should’t we set up a standard way to do this?</li> <li>I still haven’t found a way to block GitHub repositories. <ul> <li>Is there a way?</li> <li>Licensing is one thing (not easy), but I don’t think any bots respect any protocol for repos.</li> </ul></li> </ul></li> </ul> <p><strong>Michael #2:</strong> <a href=""><strong>niquests</strong></a></p> <ul> <li>Requests but with HTTP/3, HTTP/2, Multiplexed Connections, System CAs, Certificate Revocation, DNS over HTTPS / TLS / QUIC or UDP, Async, DNSSEC, and (much) pain removed!</li> <li><strong>Niquests</strong> is a simple, yet elegant, HTTP library. It is a drop-in replacement for <strong>Requests</strong>, which is under feature freeze.</li> <li><strong>See why you should switch:</strong> <a href="">Read about 10 reasons why</a></li> </ul> <p><strong>Brian #3:</strong> <a href=""><strong>Every dunder method in Python</strong></a></p> <ul> <li>Trey Hunner</li> <li>Sure, there’s <code>__repr__()</code>, <code>__str__()</code>, and <code>__init__()</code>, but how about dunder methods for: <ul> <li>Equality and hashability</li> <li>Orderability</li> <li>Type conversions and formatting</li> <li>Context managers</li> <li>Containers and collections</li> <li>Callability</li> <li>Arithmetic operators</li> <li>… and so much more … even a cheat sheet.</li> </ul></li> </ul> <p><strong>Michael #4:</strong> <a href=""><strong>Lockbox</strong></a></p> <ul> <li>Lockbox is a forward proxy for making third party API calls.</li> <li>Why? Automation or workflow platforms like Zapier and IFTTT allow "webhook" actions for interacting with third party APIs.</li> <li>They require you to provide your third party API keys so they can act on your behalf. You are trusting them to keep your API keys safe, and that they do not misuse them.</li> <li>How Lockbox helps: When a workflow platform needs to make a third party API call on your behalf, it makes a Lockbox API call instead. Lockbox makes the call to the third party API, and returns the result to the workflow platform.</li> </ul> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li><a href=""><strong>Django: Join the community on Mastodon</strong></a> - Adam Johnson</li> <li><a href=""><strong>No maintenance intended</strong></a> - Sent in from Kim van Wyk</li> </ul> <p>Michael:</p> <ul> <li>US sues Apple <ul> <li><a href="">Good video on pluses and minuses</a></li> <li><a href="">The hot water just the day before</a> [<a href="">and this one</a>]</li> <li><a href=""></a> </li> </ul></li> <li><a href="">PyPI Support Specialist job</a></li> <li><a href="">VS Code AMA</a>, please <a href="">submit your question here</a> </li> <li><a href="">PyData Eindhoven 2024</a> has a date and open CFP</li> </ul> <p><strong>Joke:</strong> <a href=""><strong>Windows Certified</strong></a></p>
Categories: FLOSS Project Planets

Armin Ronacher: On Tech Debt: My Rust Library is now a CDO

Mon, 2024-03-25 20:00

You're probably familiar with tech debt. There is a joke that if there is tech debt, surely there must be derivatives to work with that debt? I'm happy to say that the Rust ecosystem has created an environment where it looks like one solution for tech debt is collateralization.

Here is how this miracle works. Say you have a library stuff which depends on some other library learned-rust-this-way. The author of learned-rust-this-way at one point lost interest in this thing and issues keep piling up. Some of those issues are feature requests, others are legitimate bugs. However you as the person that wrote stuff never ran into any of those problems. Yet it's hard to argue that learned-rust-this-way isn't tech debt. It's one that does not bother you all that much, but it's debt nonetheless.

At one point someone else figures out that learned-rust-this-way is debt. One of the ways in which this happens is because the name is great. Clearly that's not the only person that learned Rust this way and someone else also wants that name. Except the original author is unreachable. So now there is one more reason for that package to get added to the RUSTSEC database and all the sudden all hell breaks lose. Within minutes CI will start failing for a lot of people that directly or indirectly use learned-rust-this-way notifying them that something happened. That's because RUSTSEC is basically a rating agency and they decided that your debt is now junk.

What happens next? As the maintainer of stuff your users all the sudden start calling you out for using learned-rust-this-way and you suffer. Stress levels increase. You gotta unload that shit. Why? Not because it does not work for you, but someone called you out of that debt. If we really want to stress the financial terms this is your margin call. Your users demand action to deal with your debt.

So what can you do? One option is to move to alternatives (unload the debt). In this particular case for whatever reason all the alternatives to learned-rust-this-way are not looking very appealing either. One is a fork of that thing which also only has a single maintained, but all the sudden pulls in 3 more dependencies, one of which already have a "B-" rating. Another option in the ecosystem just decided to default before they are called out.

Remember you never touched learned-rust-this-way actively. It worked for you in the unmaintained way of the last four years. If you now fork that library (and name it learned-rust-this-way-and-its-okay) you are now subject to the same demands. Forking that library is putting cash on the pile of debt. Except if you don't act up on the bug reports there, you will eventually be called out like learned-rust-this-way was. So while that might buy you time, it does not really solve the issue.

However here is what actually does work: you just merge that code into your own library. Now that junk tech debt is suddenly rated “AAA”. For as long as you never touch that code any more, you never reveal to anyone that you did that, and you just keep maintaining your library like you did before, the world keeps spinning on.

So as of today: I collateralized yaml-rust by vendoring it in insta. It's now an amalgamation of insta code and yaml-rust. And by doing so, I successfully upgraded this junk tech debt to a perfect AAA.

Who won? I think nobody really.

Categories: FLOSS Project Planets

PyCharm: PyCharm 2024.1 Release Candidate Is Out!

Mon, 2024-03-25 18:02

The PyCharm 2024.1 RC is now available!

You can get the latest build from our website, through the free Toolbox App, or via snaps for Ubuntu.

Download PyCharm 2024.1 RC

To use this build, you need to have an active subscription to PyCharm Professional.

With the major release on the horizon, there’s no better time to explore the newly introduced features before the official launch.

Our latest build integrates all of the significant updates introduced during the PyCharm 2024.1 Early Access Program. Here’s a short recap of the new features aimed at enhancing various aspects of your development workflows: 

  • Full line code completion, now for Python, JavaScript, and TypeScript
  • A revamped Terminal tool window
  • Sticky lines in the editor 
  • In-editor code reviews
  • Enriched support for GitHub Actions
  • WireMock server support 
  • And many more 

To learn more about these and other improvements, check out the posts tagged under the PyCharm 2024.1 EAP section on our blog.

Although the addition of new features has finished and the team is now refining those included in v2024.1, we still have updates to share. Take a closer look!

AI Assistant 

Beginning with the Beta version of PyCharm 2024.1, AI Assistant has been unbundled and is now available as a separate plugin. This change is driven by the need to offer greater flexibility and control over your various preferences and requirements, enabling you to choose if and when you’d like to use AI-powered technologies in your working environments.

That’s a wrap! For the full list of updates in the latest build, please refer to the release notes.

As we put the final touches to ensure a flawless release, we’d like to thank all participants who actively contributed to the Early Access Program for version 2024.1.

You can drop us a line in the comments below or reach out to us on X (formerly Twitter) – we’re always looking to benefit from your input. Finally, if you happen to spot any bugs, please report them using our issue tracker.

Categories: FLOSS Project Planets

Real Python: Prompt Engineering: A Practical Example

Mon, 2024-03-25 10:00

You’ve used ChatGPT, and you understand the potential of using a large language model (LLM) to assist you in your tasks. Maybe you’re already working on an LLM-supported application and have read about prompt engineering, but you’re unsure how to translate the theoretical concepts into a practical example.

Your text prompt instructs the LLM’s responses, so tweaking it can get you vastly different output. In this tutorial, you’ll apply multiple prompt engineering techniques to a real-world example. You’ll experience prompt engineering as an iterative process, see the effects of applying various techniques, and learn about related concepts from machine learning and data engineering.

In this tutorial, you’ll learn how to:

  • Work with OpenAI’s GPT-3.5 and GPT-4 models through their API
  • Apply prompt engineering techniques to a practical, real-world example
  • Use numbered steps, delimiters, and few-shot prompting to improve your results
  • Understand and use chain-of-thought prompting to add more context
  • Tap into the power of roles in messages to go beyond using singular role prompts

You’ll work with a Python script that you can repurpose to fit your own LLM-assisted task. So if you’d like to use practical examples to discover how you can use prompt engineering to get better results from an LLM, then you’ve found the right tutorial!

Get Your Code: Click here to download the sample code that you’ll use to get the most out of large language models through prompt engineering.

Take the Quiz: Test your knowledge with our interactive “Practical Prompt Engineering” quiz. Upon completion you will receive a score so you can track your learning progress over time:

Take the Quiz »

Understand the Purpose of Prompt Engineering

Prompt engineering is more than a buzzword. You can get vastly different output from an LLM when using different prompts. That may seem obvious when you consider that you get different output when you ask different questions—but it also applies to phrasing the same conceptual question differently. Prompt engineering means constructing your text input to the LLM using specific approaches.

You can think of prompts as arguments and the LLM as the function to which you pass these arguments. Different input means different output:

Python >>> def hello(name): ... print(f"Hello, {name}!") ... >>> hello("World") Hello, World! >>> hello("Engineer") Hello, Engineer! Copied!

While an LLM is much more complex than the toy function above, the fundamental idea holds true. For a successful function call, you’ll need to know exactly which argument will produce the desired output. In the case of an LLM, that argument is text that consists of many different tokens, or pieces of words.

Note: The analogy of a function and its arguments has a caveat when dealing with OpenAI’s LLMs. While the hello() function above will always return the same result given the same input, the results of your LLM interactions won’t be 100 percent deterministic. This is currently inherent to how these models operate.

The field of prompt engineering is still changing rapidly, and there’s a lot of active research happening in this area. As LLMs continue to evolve, so will the prompting approaches that will help you achieve the best results.

In this tutorial, you’ll cover some prompt engineering techniques, along with approaches to iteratively developing prompts, that you can use to get better text completions for your own LLM-assisted projects:

There are more techniques to uncover, and you’ll also find links to additional resources in the tutorial. Applying the mentioned techniques in a practical example will give you a great starting point for improving your LLM-supported programs. If you’ve never worked with an LLM before, then you may want to peruse OpenAI’s GPT documentation before diving in, but you should be able to follow along either way.

Get to Know the Practical Prompt Engineering Project

You’ll explore various prompt engineering techniques in service of a practical example: sanitizing customer chat conversations. By practicing different prompt engineering techniques on a single real-world project, you’ll get a good idea of why you might want to use one technique over another and how you can apply them in practice.

Imagine that you’re the resident Python developer at a company that handles thousands of customer support chats on a daily basis. Your job is to format and sanitize these conversations. You also help with deciding which of them require additional attention.

Collect Your Tasks

Your big-picture assignment is to help your company stay on top of handling customer chat conversations. The conversations that you work with may look like the one shown below:

Text [support_tom] 2023-07-24T10:02:23+00:00 : What can I help you with? [johndoe] 2023-07-24T10:03:15+00:00 : I CAN'T CONNECT TO MY BLASTED ACCOUNT [support_tom] 2023-07-24T10:03:30+00:00 : Are you sure it's not your caps lock? [johndoe] 2023-07-24T10:04:03+00:00 : Blast! You're right! Copied!

You’re supposed to make these text conversations more accessible for further processing by the customer support department in a few different ways:

  • Remove personally identifiable information.
  • Remove swear words.
  • Clean the date-time information to only show the date.
Read the full article at »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Zato Blog: Systems Automation in Python

Mon, 2024-03-25 04:00
Systems Automation in Python 2024-03-25, by Dariusz Suchojad

How to automate systems in Python and how the Zato Python integration platform differs from a network automation tool, how to start using it, along with a couple of examples of integrations with Office 365 and Jira, is what the latest article is about.

➤ Read it here: Systems Automation in Python.

More blog posts
Categories: FLOSS Project Planets

Kay Hayen: Nuitka Release 2.1

Sat, 2024-03-23 06:40

This is to inform you about the new stable release of Nuitka. It is the extremely compatible Python compiler, “download now”.

This release had focus on new features and new optimization. There is a also a large amount of compatibility with things newly added to support anti-bloat better, and workaround problems with newer package versions that would otherwise need source code at run-time.

Bug Fixes
  • Windows: Using older MSVC before 14.3 was not working anymore. Fixed in 2.0.1 already.

  • Compatibility: The dill-compat plugin didn’t work for functions with closure variables taken. Fixed in 2.0.1 already.

    def get_local_closure(b): def _local_multiply(x, y): return x * y + b return _local_multiply fn = get_local_closure(1) fn2 = dill.loads(dill.dumps(fn)) print(fn2(2, 3))
  • Windows: Fix, sometimes kernel32.dll is actually reported as a dependency, remove assertion against that. Fixed in 2.0.1 already.

  • UI: The help output for --output-filename was not formatted properly. Fixed in 2.0.1 already.

  • Standalone: Added support for the scapy package. Fixed in 2.0.2 already.

  • Standalone: Added PonyORM implicit dependencies. Fixed in 2.0.2 already.

  • Standalone: Added support for cryptoauthlib, betterproto, tracerite, sklearn.util, and qt_material packages. Fixed in 2.0.2 already.

  • Standalone: Added missing data file for scipy package. Fixed in 2.0.2 already.

  • Standalone: Added missing DLLs for speech_recognition package. Fixed in 2.0.2 already.

  • Standalone: Added missing DLL for gmsh package. Fixed in 2.0.2 already.

  • UI: Using reporting path in macOS dependency scan error message, otherwise these contain home directory paths for no good reason. Fixed in 2.0.2 already.

  • UI: Fix, could crash when compiling directories with trailing slashes used. At least on Windows, this happened for the “/” slash value. Fixed in 2.0.2 already.

  • Module: Fix, convenience option --run was not considering --output-dir directory to load the result module. Without this, the check for un-replaced module was always triggering for module source in current directory, despite doing the right thing and putting it elsewhere. Fixed in 2.0.2 already.

  • Python2: Avoid values for __file__ of modules that are unicode and solve a TODO that restores consistency over modules mode __file__ values. Fixed in 2.0.2 already.

  • Windows: Fix, short paths with and without dir name cached wrongly, which could lead to shorted paths even where not asked for them. Fixed in 2.0.2 already.

  • Fix, comparing list values that changed could segfault. This is a bug fix Python did, that we didn’t follow yet and that became apparent after using our dedicated list helpers more often. Fixed in 2.0.2 already.

  • Standalone: Added support for tiktoken package. Fixed in 2.0.2 already.

  • Standalone: Fix, namespace packages had wrong runtime __path__ value. Fixed in 2.0.2 already.

  • Python3.11: Fix, was using tuples from freelist of the wrong size

    • CPython changed the index for the size, to not use zero, which was wasteful when introduced with 3.10, but to size-1 but we did not follow that and then used a tuple one bit larger than necessary.

    • As a result, code producing a lot short living tuples could end up creating new ones over and over, causing bad memory allocations and slow performance.

    Fixed in 2.0.2 already.

  • macOS: Fix, need to allow non-existent and versioned dependencies of DLLs to themselves. Fixed in 2.0.2 already.

  • Windows: Fix PGO (Profile Guided Optimization) build errors with MinGW64, this feature is not yet ready for general use, but these errors shouldn’t happen. Fixed in 2.0.2 already.

  • Plugins: Fix, do not load importlib_metadata unless really necessary.

    The pkg_resources plugin used to load it, and that then had harmful effects for our handling of distribution information in some configurations. Fixed in 2.0.3 already.

  • Plugins: Avoid warnings from plugin evaluated code, it could happen that a UserWarning would be displayed during compilation. Fixed in 2.0.3 already.

  • Fix, loading pickles with compiled functions in module mode was not working. Fixed in 2.0.3 already.

  • Standalone: Added data files for h2o package. Fixed in 2.0.3 already.

  • Fix, variable assignment from variables that started to raise were not recognized.

    When a variable assignment from a variable became a raise expression, that wasn’t caught and propagated as it should have been. Fixed in 2.0.3 already.

  • Make the NUITKA_PYTHONPATH usage more robust. Fixed in 2.0.3 already.

  • Fix, PySide2/6 argument name for slot connection and disconnect should be slot, wasn’t working with keyword argument calls. Fixed in 2.0.3 already.

  • Standalone: Added support for paddle and paddleocr packages. Fixed in 2.0.4 already.

  • Standalone: Added support for diatheke. Fixed in 2.0.4 already.

  • Standalone: Added support for zaber-motion package. Fixed in 2.0.4 already.

  • Standalone: Added support for plyer package. Fixed in 2.0.4 already.

  • Fix, added handling of OSError for metadata read, otherwise corrupt packages can have Nuitka crashing. Fixed in 2.0.4 already.

  • Fix, need to annotate potential exception exit when making a fixed import from hard module attribute. Fixed in 2.0.4 already.

  • Fix, didn’t consider Nuitka project options with --main and --script-path. This is of course the only way Nuitka-Action does call it, so they didn’t work there at all. Fixed in 2.0.4 already.

  • Scons: Fix, need to close progress bar when about to error exit. Otherwise error outputs will be garbled by incomplete progress bar. Fixed in 2.0.4 already.

  • Fix, need to convert relative from imports to hard imports too, or else packages needed to be followed are not included. Fixed in 2.0.5 already.

  • Standalone: Added pygame_menu data files. Fixed in 2.0.6 already.

  • Windows: Fix, wasn’t working when compiling on network mounted drive letters. Fixed in 2.0.6 already.

  • Fix, the .pyi parser was crashing on some comments with a leading from in the line, recognize these better. Fixed in 2.0.6 already.

  • Actions: Fix, some yaml configs could fail to load plugins. Fixed in 2.0.6 already.

  • Standalone: Added support for newer torch packages that otherwise require source code.

  • Fix, inline copies of tqdm etc. left sub-modules behind, removing only the top level sys.modules entry may not be enough.

New Features
  • Plugins: Added support for constants in Nuitka package configurations. We can now using when clauses, define variable values to be defined, e.g. to specify the DLL suffix, or the DLL path, based on platform dependent properties.

  • Plugins: Make relative_path, suffix, prefix in DLL Nuitka package configurations allowed to be an expression rather than just a constant value.

  • Plugins: Make not only booleans related to the python version available, but also strings python_version_str and python_version_full_str, to use them when constructing e.g. DLL paths in Nuitka package configuration.

  • Plugins: Added helper function iterate_modules for producing the submodules of a given package, for using in expressions of Nuitka package configuration.

  • macOS: Added support for Tcl/Tk detection on Homebrew Python.

  • Added module attribute to __compiled__ values

    So far it was impossible to distinguish non-standalone, i.e. accelerated mode and module compilation by looking at the __compiled__ attribute, so we add an indicator for module mode that closes this gap.

  • Plugins: Added appdirs and importlib for use in Nuitka package config expressions.

  • Plugins: Added ability to specify modules to not follow when a module is used. This nofollow configuration is for rare use cases only.

  • Plugins: Added values extension_std_suffix and extension_suffix for use in expressions, to e.g. construct DLL suffix patterns from it.

  • UI: Added more control over caching with per cache category environment variables, as documented in the User Manual..

  • Plugins: Added support for reporting module detections

    The delvewheel plugin now puts the version of that packaging tool used by a particular module in the report rather than tracing it to the user, that in the normal case won’t care. This is more for debugging purposes of Nuitka.

  • Scalability: Do not make loop analysis at all for very trusted value traces, their point is to not change, and waiting for that to be confirmed has no point.

  • Use very trusted value traces in functions not just as mere assign traces or else expected optimization will not be done on them in many cases. With this a lot more cases of hard values are optimized leading also to generally more compact and correct results in terms of imports, metadata, code avoided on the wrong OS, etc.

  • Scalability: When specializing assignments, make sure to have the proper value trace immediately.

    When changing to a hard value, the value trace was still an assign trace and not very trusted for one for micro pass of the module.

    This had the effect to need one more micro pass to get to benefiting of the unescapable nature of those values, which meant more micro passes than necessary and those being more complex due to escaped traces, and therefore taking longer for affected modules.

  • Scalability: The code trying avoid merge traces of merge traces, and to instead flatten merge traces was only handling part of these correctly, and correcting it reduced optimization time for some functions from infinite to instant. Less memory usage should also come out of this, even where this was not affecting compile time as much. Added in 2.0.1 already.

  • Scalability: Some codes that checked for variables were testing for temporary variable and normal variable both one after another, making some optimization steps and code generation slower than necessary due to the extra calls.

  • Scalability: A variable assignment from variable that were later recognized to become a raise was not recognized as such, and this then wasn’t caught and propagated as it should, preventing more optimization of the affected code. Make sure to convert more directly when observing things to change, rather than doing it one pass later.

  • The fix proper reuse of tuples released to the freelist with matching sizes causes less memory usage and faster performance for the 3.11 version. Added in 2.0.2 already.

  • Statically optimize sys.exit into exception raise of SystemExit.

    This should make a bunch of dead code obvious to Nuitka, it can now tell this aborts execution of a branch, potentially eliminating imports, etc.

  • macOS: Enable python static link library for Homebrew too. Added in 2.0.1 already. Added in 2.0.3 already.

  • Avoid compiling bloated module namespace of altair package. Added in 2.0.3 already.

  • Anti-Bloat: Avoid including kubernetes for tensorflow unless used otherwise. Added in 2.0.3 already.

  • Anti-Bloat: Avoid including setuptools for tqdm. Added in 2.0.3 already.

  • Anti-Bloat: Avoid IPython in fire package. Added in 2.0.3 already.

  • Anti-Bloat: Avoid including Cython for pydantic package. Added in 2.0.3 already.

  • Anti-Bloat: Changes to avoid triton in newer torch as well. Added in 2.0.5 already.

  • Anti-Bloat: Avoid setuptools via setuptools_scm in pyarrow.

  • Anti-Bloat: Made more packages equivalent to using setuptools which we want to avoid, all of Cython, cython, pyximport, paddle.utils.cpp_extension, torch.utils.cpp_extension were added for better reports of the actual causes.

  • Moved the changelog of Nuitka to the website, just point to there from Nuitka repo.

  • UI: Proper error message from Nuitka when scons build fails with a detail mnemonic page. Read more on the info page for detailed information.

  • Windows: Reject all MinGW64 that are not are not the winlibs that Nuitka itself downloaded. As these packages break very easily, we need to control if it’s a working set of ccache, make, binutils and gcc with all the necessary workarounds and features like LTO working on Windows properly.

  • Quality: Added auto-format of PNG and JPEG images. This aims at making it simpler to add images to our repositories, esp. Nuitka Website. This now makes optipng and jpegoptim calls as necessary. Previously this was manual steps for the website to be applied.

  • User Manual: Be more clear about compiler version needs on Windows for Python 3.11.

  • User Manual: Added examples for error message with low C compiler memory, such that maybe they can be found via search by users.

  • User Manual: Removed sections that are unnecessary or better maintained as separate pages on the website.

  • Quality: Avoid empty no-auto-follow values, for silently ignoring it there is a dedicated string ignore that must be used.

  • Quality: Enforce normalized paths for dest_path and relative_path. Users were uncertain if a leading dot made sense, but we now disallow it for clarity.

  • Quality: Check more keys with expressions for syntax errors, to catch these mistakes in configuration sooner.

  • Quality: Scanning through all files with the auto-format tool should now be faster, and CPython test suite directories (test submodules) if present are ignored.

  • Release: Remove month from manpage generation, that’s only noise in diffs.

  • Removed digital art folders, these were only making checkouts larger for no good reason. We will have better ones on the website in the future.

  • Scons: Allow C warnings when compiling for running in debugger automatically.

  • UI: The macOS app bundle option is not experimental at all. This has been untrue for years now, remove that cautioning.

  • macOS: Discontinue support for PyQt6.

    With newer PyQt6 we would have to package frameworks properly, and we don’t have that yet and it will be a lot of developer time to get it.

    Instead point people to PySide6 which is the better choice and is perfectly supported by Qt company and Nuitka.

  • Removed version numbering, month of creation, etc. from the man pages generated.

  • Moved Credits.rst file to be on the website and maintain it there rather than syncing of from the Nuitka repository.

  • Bumped copyright year and split the license text such that it is now at the bottom of the files rather than eating up the first page, this is aimed at making the code more readable.

  • With sys.exit being optimized, we were able to make our trick to avoid following nuitka because of accidentally finding the setup as an import more simple.

    # Don't allow importing this, and make recognizable that # the above imports are not to follow. Sometimes code imports # setup and then Nuitka ends up including itself. if __name__ != "__main__": sys.exit("Cannot import 'setup' module of Nuitka")
  • Scons: Don’t scan for ccache on Windows, the winlibs package contains it nowadays, and since it’s now required to be used, there is no point for this code anymore.

  • Minor cleanups coming from trying out ruff as a linter on Nuitka, it found a few uses of not using not in, but that was it.

  • Removed test with chinese filenames, we need to avoid chinese names in the repo. These have been seen as preventing installation on some systems that are not capable of handling them in the git, zip, pip tooling, so lets avoid them entirely now that Nuitka handles these just fine.

  • Tests: More macOS standalone tests that need to be bundles were getting the project configuration to do it.


This release added much needed tools for our Nuitka Package configuration, but also cleans up scalability and optimization that was supposed to work, but did not yet, or not anymore.

The usability improved again, as it does always, but the big improvements for scalability that will implement existing algorithms more efficient, are yet to come, this release was mainly driven by the need to get torch to work in its latest version out of the box with stable Nuitka, but this couldn’t be done as a hotfix

Categories: FLOSS Project Planets

Python Morsels: Unnecessary else statements

Fri, 2024-03-22 18:00

When your function ends in an else block with a return statement in it, should you remove that else?

Table of contents

  1. A function where both if and else return
  2. Is that else statement unnecessary?
  3. Sometimes else improves readability
  4. When should you remove an else statement?
  5. Considering readability with if-else statements

A function where both if and else return

This earliest_date function uses the python-dateutil third-party library to parse two strings as dates:

from dateutil.parser import parse def earliest_date(date1, date2): """Return the string representing the earliest date.""" if parse(date1, fuzzy=True) < parse(date2, fuzzy=True): return date1 else: return date2

This function returns the string which represents the earliest given date:

>>> earliest_date("May 3 2024", "June 5 2025") 'May 3 2024' >>> earliest_date("Feb 3 2026", "June 5 2025") 'June 5 2025'

Note that this function uses an if statement that returns, and an else that also returns.

Is that else statement unnecessary?

We don't necessarily need that …

Read the full article:
Categories: FLOSS Project Planets

Django Weblog: Welcome our new Fellow - Sarah Boyce

Fri, 2024-03-22 12:54

The DSF Board and Fellows Committee are pleased to introduce Sarah Boyce as our new Django Fellow. Sarah will be joining Natalia Bidart who is continuing her excellent tenure as a Fellow.

Sarah is a senior developer and developer advocate with 5 years of experience developing with Django under her belt. She graduated with a first class honours degree in Mathematics from the University of Bath, and transitioned in software development in her first job out of school.

Sarah first worked as a client project focused developer, where she gained experience directly dealing with requests from clients as well as managing our own internal ticketing system for feature/bug reports. A stint as a backend developer using Django and DRF provided a grounding in working on long term challenges on a single project. Most recently Sarah has been a developer advocate focused on creating content on and about Django and Django development.

For the past several years, Sarah has been a very active member of the Django community. She has a history of producing well researched and written patches for Django, as well as on a number of highly used third party packages. Sarah is a member of the Django Review and Triage team, helping others to get their patches over the line and into Django. She also finds time to participate in and create content for Django meetups, conferences, and the Django News newsletter.

Sarah is also a Co-Founder and Co-Organiser of Djangonaut Space, the mentorship program developing future contributors to Django and other Django related packages. Djangonaut Space was awarded the 2023 Malcolm Tredinnick Memorial Prize.

Please join me in welcoming and wishing Sarah well as the new Fellow.

Thank you to all of the applicants to the Fellowship. We hope that we will be able to expand the Fellowship program in the future, and knowing that there are more excellent candidates gives us confidence in working towards that goal.

Finally our deepest thanks and gratitude goes to Mariusz Felisiak. Mariusz is stepping down from the Fellowship after 5 years of dedicated service in order to focus on other areas of the Django and wider world. We wish you well Mariusz.

Categories: FLOSS Project Planets

Daniel Roy Greenfeld: Keynote at PyCon Lithuania 2024

Fri, 2024-03-22 09:00

From April 2nd to April 6th I'll be at PyCon Lithuania 2024 in Vilnius to present a keynote about 25 years of glorious coding mistakes (mostly in Python). Audrey and Uma will be accompanying me, making us the first members of the Lithuanian side of my family to return there in over 100 years!

At the conference I'll be joined by my old friend Tom Christie, author of HTTPX, Starlette, and Django REST Framework. I hope to meet many new friends, specifically everyone there. At the sprints I'll be joined by my awesome wife, Audrey, author of Cookiecutter.

Come and join us!

Categories: FLOSS Project Planets

Real Python: The Real Python Podcast – Episode #197: Using Python in Bioinformatics and the Laboratory

Fri, 2024-03-22 08:00

How is Python being used to automate processes in the laboratory? How can it speed up scientific work with DNA sequencing? This week on the show, Chemical Engineering PhD Student Parsa Ghadermazi is here to discuss Python in bioinformatics.

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

PyCharm: PyCharm 2023.3.5 Is Out!

Fri, 2024-03-22 02:52

PyCharm 2023.3.5 is an important bug-fix update.

You can update to this version from inside the IDE, using the Toolbox App, or via snaps, if you’re using Ubuntu. You can also download it directly from our website.

Here are some of the notable fixes in v2023.3.5: 

  • The “Problems” tool window no longer displays outdated project errors that have already been resolved. [PY-71058]
  • PyCharm now supports Docker 2.25, eliminating errors that occurred when attempting to create a Docker-compose interpreter with Docker 2.25. [PY-71131]
  • We’ve introduced a workaround to reduce the likelihood of IDE crashes following an update to macOS Sonoma 14.4. [JBR-6802]
  • We’ve fixed the issue causing erratic screen scaling on Linux. [IDEA-341318]

For the full list of issues addressed in PyCharm 2023.3.5, please see the release notes.

Categories: FLOSS Project Planets

Amjith Ramanujam: Rapid Prototyping in Python

Thu, 2024-03-21 09:35

I was recently assigned to a new project at work. Like any good software engineer I started writing the pseudocode for the modules. We use C++ at work to write our programs.

I quickly realized it's not easy to translate programming ideas to English statements without a syntactic structure. When I was whining about it to Vijay, he told me to try prototyping it in Python instead of writing pseudocode. Intrigued by this, I decided to write a prototype in Python to test how various modules will come together.

Surprisingly it took me a mere 2 hours to code up the prototype. I can't emphasize enough, how effortless it was in Python.

What makes Python an ideal choice for prototyping:

Dynamically typed language:

Python doesn't require you to declare the datatype of a variable. This lets you write a function that is generic enough to handle any kind of data. For eg:

def max_val(a,b): return a if a >b else b

This function can take integers, floats, strings, a combination of any of those, or lists, dictionaries, tuples, whatever.

A list in Python need not be homogenous. This is a perfectly good list:

[1, 'abc', [1,2,3]]

This lets you pack data in unique ways on the fly which can later be translated to a class or a struct in a statically typed language like C++.

class newDataType { int i; String str; Vector vInts; };

Rich Set to Data-Structures:

Built-in support for lists, dictionaries, sets, etc reduces the time involved in hunting for a library that provides you those basic data-structures.

Expressive and Succinct:

The algorithms that operate on the data-structures are intuitive and simple to use. The final code is more readable than a pseudocode.

For example: Lets check if a list has an element

>>> lst = [1,2,3] # Create a list >>> res = 2 in lst # Check if 2 is in 'lst' True

If we have to do it in C++.

list lst; lst.push_back(3); lst.push_back(1); lst.push_back(7); list::iterator result = find(lst.begin(), lst.end(), 7); bool res = (result != lst.end())

Python Interpreter and Help System:

This is a huge plus. The presence of interpreter not only aids you in testing snippets of code, but it acts as an help system. Lets say we want to look up the functions that operate on a List.

>>> dir([]) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> help([].sort) Help on built-in function sort: sort(...) L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; cmp(x, y) -> -1, 0, 1

Advantages of prototyping instead of pseudocode:

  • The type definition of the datastructures emerge as we code.
  • The edge cases start to emerge when you prototype.
  • A set of required supporting routines.
  • A better estimation of the time required to complete a task.
Categories: FLOSS Project Planets

Talk Python to Me: #454: Data Pipelines with Dagster

Thu, 2024-03-21 04:00
Do you have data that you pull from external sources or is generated and appears at your digital doorstep? I bet that data needs processed, filtered, transformed, distributed, and much more. One of the biggest tools to create these data pipelines with Python is Dagster. And we are fortunate to have Pedram Navid on the show this episode. Pedram is the Head of Data Engineering and DevRel at Dagster Labs. And we're talking data pipelines this week at Talk Python.<br/> <br/> <strong>Episode sponsors</strong><br/> <br/> <a href=''>Talk Python Courses</a><br> <a href=''>Posit</a><br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Rock Solid Python with Types Course</b>: <a href="" target="_blank" rel="noopener"></a><br/> <br/> <b>Pedram on Twitter</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Pedram on LinkedIn</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Ship data pipelines with extraordinary velocity</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>dagster-open-platform</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>The Dagster Master Plan</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>data load tool (dlt)</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>DataFrames for the new era</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Apache Arrow</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>DuckDB is a fast in-process analytical database</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Ship trusted data products faster</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Watch this episode on YouTube</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Episode transcripts</b>: <a href="" target="_blank" rel="noopener"></a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="" target="_blank" rel="noopener"></a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>mkennedy</a><br/></div>
Categories: FLOSS Project Planets

Programiz: Python Program to Capitalize the First Character of a String

Thu, 2024-03-21 01:19
In this example, you will learn to capitalize the first character of a string.
Categories: FLOSS Project Planets

Matt Layman: Post-launch Punchlist - Building SaaS with Python and Django #186

Wed, 2024-03-20 20:00
In this episode, we had a bunch of issues to resolve post-launch. I set the code that causes trials to expire, made updates to who receives prompt emails, and added some polish to the sign up process and interface to make it clear what will happen in the flow. After those modifications, we worked through a set of smaller changes like setting up Dependabot and adding a missing database index.
Categories: FLOSS Project Planets

Python⇒Speed: The wrong way to speed up your code with Numba

Wed, 2024-03-20 20:00

If your NumPy-based code is too slow, you can sometimes use Numba to speed it up. Numba is a compiled language that uses the same syntax as Python, and it compiles at runtime, so it’s very easy to write. And because it re-implements a large part of the NumPy APIs, it can also easily be used with existing NumPy-based code.

However, Numba’s NumPy support can be a trap: it can lead you to missing huge optimization opportunities by sticking to NumPy-style code. So in this article we’ll show an example of:

  • The wrong way to use Numba, writing NumPy-style full array transforms.
  • The right way to use Numba, namely for loops.
Categories: FLOSS Project Planets

EuroPython: EuroPython 2024: Community Voting is now live! Go Vote!

Wed, 2024-03-20 18:00

Hey hey,

With 110 days remaining until the big day, the EuroPython programme team is working full steam ahead to put together a power-packed schedule. And what *YOU* want to see at the conference is our guiding light in the process.

With that, we are excited to announce the EuroPython 2024 Community Voting: &#x1F389;

All past EuroPython attendees between 2015-2024 & prospective speakers from this year are eligible to vote.

You can help us spread the word by forwarding this email to your fellow EuroPython friends.

The more votes we have, the better informed decisions the programme team can make!

Head over to to make your voice heard!

Thank you for your continued support,
EuroPython 2024 Organisers

Categories: FLOSS Project Planets

Python Software Foundation: Announcing a PyPI Support Specialist

Wed, 2024-03-20 11:08

We launched the Python Package Index (PyPI) in 2003 and for most of its history a robust and dedicated volunteer community kept it running. Eventually, we put a bit of PSF staff time into the maintenance of the Index, and last year with support from AWS we hired Mike Fiedler to work full-time on PyPI’s urgent security needs.

PyPI has grown enormously in the last 20+ years, and in recent years it has reached a truly massive scale with growth only continuing upward. In 2022 alone, PyPI saw a 57% growth and as of this writing, there are over a half a million packages on PyPI. The impact PyPI has these days is pretty breathtaking. Running a free public service of that size has come with challenges, too. As PyPI has grown, the work of communicating with users and solving account issues here has grown in tandem and out-stripped our current volunteer plus one tenth of a staff person capacity. We also know that some community members have noticed and expressed frustration with the time-frame that goes with tasks that don't have sufficient staffing.

Much of this work is sensitive and complex such that it needs to be performed by a PSF staff person. It involves personal information and verification processes to make sure we’re giving access and names to the correct entities. Work like this needs to be done by a person who is here day after day to carry out multi-step verification procedures and is accountable to the PSF. 

We are very happy to share the news that we are hiring a person to help us manage the increased capacity and allow us to keep pace with PyPI’s seemingly unstoppable growth. This is an associate role that is 100% remote. Please take a look at this posting for a PyPI Support Specialist and share it with your networks.

Categories: FLOSS Project Planets

Real Python: Build a Python Turtle Game: Space Invaders Clone

Wed, 2024-03-20 10:00

In this tutorial, you’ll use Python’s turtle module to build a Space Invaders clone. The game Space Invaders doesn’t need any introduction. The original game was released in 1978 and is one of the most recognized video games of all time. It undeniably defined its own video game genre. In this tutorial, you’ll create a basic clone of this game.

The turtle module you’ll use to build the game is part of Python’s standard library, and it enables you to draw and move sprites on the screen. The turtle module is not a game-development package, but it gives instructions about creating a turtle game, which will help you understand how video games are built.

In this tutorial, you’ll learn how to:

  • Design and build a classic video game
  • Use the turtle module to create animated sprites
  • Add user interaction in a graphics-based program
  • Create a game loop to control each frame of the game
  • Use functions to represent key actions in the game

This tutorial is ideal for anyone who is familiar with the core Python topics and wants to use them to build a classic video game from scratch. You don’t need to be familiar with the turtle module to work through this tutorial. You can download the code for each step by clicking on the link below:

Get Your Code: Click here to download the free sample code that shows you how to build a Python turtle game.

In the next section, you can have a look at the version of the game you’ll build as you follow the steps outlined in this tutorial.

Demo: A Python Turtle Space Invaders Game

You’ll build a simplified version of the classic Space Invaders game and control the laser cannon with the keys on your keyboard. You’ll shoot lasers from the cannon by pressing the spacebar, and aliens will appear at regular intervals at the top of the screen and move downwards. Your task is to shoot the aliens before they reach the bottom of the screen. The game ends when one alien reaches the bottom.

This is what your turtle game will look like when you complete this tutorial:

Here you can see the main game play for this game, as the laser cannon moves back and forth and shoots the falling aliens. The game also displays the elapsed time and the number of aliens shot down on the screen.

Project Overview

In this project, you’ll start by creating the screen that will contain the game. In each step, you’ll create game components such as the laser cannon, lasers, and aliens, and you’ll add the features required to make a functioning game.

To create this turtle game, you’ll work through the following steps:

  1. Create the game screen and the laser cannon
  2. Move the cannon left and right using keys
  3. Shoot lasers with the spacebar
  4. Create aliens and move them towards the bottom of the screen
  5. Determine when a laser hits an alien
  6. End the game when an alien reaches the bottom
  7. Add a timer and a score
  8. Improve the cannon’s movement to make the game smoother
  9. Set the game’s frame rate

You’ll start with a blank screen, and then see the game come to life one feature at a time as you work through each step in this tutorial.


To complete this tutorial, you should be comfortable with the following concepts:

You don’t need to be familiar with Python’s turtle to start this tutorial. However, you can read an overview of the turtle module to find out more about the basics.

If you don’t have all of the prerequisite knowledge before you start, that’s okay! In fact, you might learn more by going ahead and getting started! You can always stop and review the resources linked here if you get stuck.

Step 1: Set Up the Turtle Game With a Screen and a Laser Cannon

You can’t have a game without a screen where all the action happens. So, the first step is to create a blank screen. Then, you can add sprites to represent the items in the game. In this project, you can run your code at any point to see the game in its current state.

You can download the code as it’ll look at the end of this step from the folder named source_code_step_1/ in the link below:

Read the full article at »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Python Morsels: Every dunder method in Python

Tue, 2024-03-19 17:30

An explanation of all of Python's 100+ dunder methods and 50+ dunder attributes, including a summary of each one.

Table of contents

  1. The 3 essential dunder methods 🔑
  2. Equality and hashability 🟰
  3. Orderability ⚖️
  4. Type conversions and string formatting ⚗️
  5. Context managers 🚪
  6. Containers and collections 🗃️
  7. Callability ☎️
  8. Arithmetic operators ➗
  9. In-place arithmetic operations ♻️
  10. Built-in math functions 🧮
  11. Attribute access 📜
  12. Metaprogramming 🪄
  13. Descriptors 🏷️
  14. Buffers 💾
  15. Asynchronous operations 🤹
  16. Construction and finalizing 🏭
  17. Library-specific dunder methods 🧰
  18. Dunder attributes 📇
  19. Every dunder method: a cheat sheet ⭐

The 3 essential dunder methods 🔑

There are 3 dunder methods that most classes should have: __init__, __repr__, and __eq__.

Operation Dunder Method Call Returns T(a, b=3) T.__init__(x, a, b=3) None repr(x) x.__repr__() str x == y x.__eq__(y) Typically bool

The __init__ method is the initializer (not to be confused with the constructor), the __repr__ method customizes an object's string representation, and the __eq__ method customizes what it means for objects to be equal to one another.

The __repr__ method is particularly helpful at the the Python REPL and when debugging.

Equality and hashability 🟰

In addition to the __eq__ …

Read the full article:
Categories: FLOSS Project Planets