Planet Python

Subscribe to Planet Python feed
Planet Python - http://planetpython.org/
Updated: 7 hours 5 min ago

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.

Optimization
  • 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.

Organisational
  • 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.

Cleanups
  • 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.

Tests
  • 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.

Summary

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: https://www.pythonmorsels.com/unnecessary-else-statements/
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='https://talkpython.fm/training'>Talk Python Courses</a><br> <a href='https://talkpython.fm/posit'>Posit</a><br/> <br/> <strong>Links from the show</strong><br/> <br/> <div><b>Rock Solid Python with Types Course</b>: <a href="https://training.talkpython.fm/courses/python-type-hint-course-with-hands-on-examples?ref=podcast" target="_blank" rel="noopener">training.talkpython.fm</a><br/> <br/> <b>Pedram on Twitter</b>: <a href="https://twitter.com/pdrmnvd" target="_blank" rel="noopener">twitter.com</a><br/> <b>Pedram on LinkedIn</b>: <a href="https://linkedin.com/in/pedramnavid" target="_blank" rel="noopener">linkedin.com</a><br/> <b>Ship data pipelines with extraordinary velocity</b>: <a href="https://dagster.io" target="_blank" rel="noopener">dagster.io</a><br/> <b>dagster-open-platform</b>: <a href="https://github.com/dagster-io/dagster-open-platform" target="_blank" rel="noopener">github.com</a><br/> <b>The Dagster Master Plan</b>: <a href="https://dagster.io/blog/dagster-master-plan" target="_blank" rel="noopener">dagster.io</a><br/> <b>data load tool (dlt)</b>: <a href="https://dlthub.com" target="_blank" rel="noopener">dlthub.com</a><br/> <b>DataFrames for the new era</b>: <a href="https://pola.rs" target="_blank" rel="noopener">pola.rs</a><br/> <b>Apache Arrow</b>: <a href="https://arrow.apache.org" target="_blank" rel="noopener">arrow.apache.org</a><br/> <b>DuckDB is a fast in-process analytical database</b>: <a href="https://duckdb.org" target="_blank" rel="noopener">duckdb.org</a><br/> <b>Ship trusted data products faster</b>: <a href="https://www.getdbt.com" target="_blank" rel="noopener">www.getdbt.com</a><br/> <b>Watch this episode on YouTube</b>: <a href="https://www.youtube.com/watch?v=vRVhDfQPHBM" target="_blank" rel="noopener">youtube.com</a><br/> <b>Episode transcripts</b>: <a href="https://talkpython.fm/episodes/transcript/454/data-pipelines-with-dagster" target="_blank" rel="noopener">talkpython.fm</a><br/> <br/> <b>--- Stay in touch with us ---</b><br/> <b>Subscribe to us on YouTube</b>: <a href="https://talkpython.fm/youtube" target="_blank" rel="noopener">youtube.com</a><br/> <b>Follow Talk Python on Mastodon</b>: <a href="https://fosstodon.org/web/@talkpython" target="_blank" rel="noopener"><i class="fa-brands fa-mastodon"></i>talkpython</a><br/> <b>Follow Michael on Mastodon</b>: <a href="https://fosstodon.org/web/@mkennedy" 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.
Read more...
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: https://ep2024.europython.eu/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 https://ep2024.europython.eu/voting 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.

Prerequisites

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 https://realpython.com/build-python-turtle-game-space-invaders-clone/ »

[ 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: https://www.pythonmorsels.com/every-dunder-method/
Categories: FLOSS Project Planets

Python Insider: Python 3.10.14, 3.9.19, and 3.8.19 is now available

Tue, 2024-03-19 16:39

Howdy!
Those are the boring security releases that aren’t supposed to bring anything new. But not this time! We do have a bit of news, actually. But first things first: go update your systems!

Python 3.10.14

Get it here: Python Release Python 3.10.14

26 commits since the last release.

Python 3.9.19

Get it here: Python Release Python 3.9.19

26 commits since the last release.

Python 3.8.19

Get it here: Python Release Python 3.8.19

28 commits since the last release.

Security content in this release
  • gh-115399 & gh-115398: bundled libexpat was updated to 2.6.0 to address CVE-2023-52425, and control of the new reparse deferral functionality was exposed with new APIs. Thanks to Sebastian Pipping, the maintainer of libexpat, who worked with us directly on incorporating those fixes!
  • gh-109858: zipfile is now protected from the “quoted-overlap” zipbomb to address CVE-2024-0450. It now raises BadZipFile when attempting to read an entry that overlaps with another entry or central directory
  • gh-91133: tempfile.TemporaryDirectory cleanup no longer dereferences symlinks when working around file system permission errors to address CVE-2023-6597
  • gh-115197: urllib.request no longer resolves the hostname before checking it against the system’s proxy bypass list on macOS and Windows
  • gh-81194: a crash in socket.if_indextoname() with a specific value (UINT_MAX) was fixed. Relatedly, an integer overflow in socket.if_indextoname() on 64-bit non-Windows platforms was fixed
  • gh-113659: .pth files with names starting with a dot or containing the hidden file attribute are now skipped
  • gh-102388: iso2022_jp_3 and iso2022_jp_2004 codecs no longer read out of bounds
  • gh-114572: ssl.SSLContext.cert_store_stats() and ssl.SSLContext.get_ca_certs() now correctly lock access to the certificate store, when the ssl.SSLContext is shared across multiple threads
Stay safe and upgrade!

Upgrading is highly recommended to all users of affected versions.

Source builds are moving to GitHub Actions

It’s not something you will notice when downloading, but 3.10.14 here is the first release we’ve done where the source artifacts were built on GHA and not on a local computer of one of the release managers. We have the Security Developer in Residence @sethmlarson to thank for that!

It’s a big deal since public builds allow for easier auditing and repeatability. It also helps with the so-called bus factor. In fact, to test this out, this build of 3.10.14 was triggered by me and not Pablo, who would usually release Python 3.10.

The artifacts are later still signed by the respective release manager, ensuring integrity when put on the downloads server.

Python now manages its own CVEs

The security releases you’re looking at are the first after the PSF became a CVE Numbering Authority. That’s also thanks to @sethmlarson. What being our own CNA allows us is to ensure the quality of the vulnerability reports is high, and that the severity estimates are accurate. Seth summarized it best in his announcement here.

What this also allows us to do is to combine announcement of CVEs with the release of patched versions of Python. This is in fact the case with two of the CVEs listed above (CVE-2023-6597 and CVE-2024-0450). And since Seth is now traveling, this announcement duty was fulfilled by the PSF’s Director of Infrastructure @EWDurbin. Thanks!

I’m happy to see us successfully testing bus factor resilience on multiple fronts with this round of releases.

Thank you for your support

Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation.

Python.org - the official home of the Python Programming Language.


Łukasz Langa @ambv
on behalf of your friendly release team,

Ned Deily @nad
Steve Dower @steve.dower
Pablo Galindo Salgado @pablogsal
Łukasz Langa @ambv
Thomas Wouters @thomas

Categories: FLOSS Project Planets

PyCoder’s Weekly: Issue #621 (March 19, 2024)

Tue, 2024-03-19 15:30

#621 – MARCH 19, 2024
View in Browser »

Visualizing Data in Python With Seaborn

In this tutorial, you’ll learn how to use the Python seaborn library to produce statistical data analysis plots to allow you to better visualize your data. You’ll learn how to use both its traditional classic interface and more modern objects interface.
REAL PYTHON

Does Python Have Pointers?

Depending on how you’re using the term “pointer” changes the answer to the question. Read on to better understand the programming terminology and whether Python has pointers.
NED BATCHELDER

GPT Pilot Is an OSS Dev Tool That Builds Apps From Scratch by Talking to You

GPT Pilot is a collection of AI agents that automate developer workflows to try offloading 95% of coding tasks from you to the AI. Right now, it can build apps up to ~3000 lines of code see examples here →
PYTHAGORA TECHNOLOGIES INC. sponsor

The Python Memory Model

This article introduces you to how Python stores things in memory. Learn about the heap, the stack, and how the interpreter sees Python objects.
PEPIJN BAKKER

Python 3.13.0 Alpha 5 Released

CPYTHON DEV BLOG

New Malware Reporting Tool on PyPI

PYPI

Articles & Tutorials Build an LLM RAG Chatbot With LangChain

Large language models (LLMs) have taken the world by storm, demonstrating unprecedented capabilities in natural language tasks. In this step-by-step tutorial, you’ll leverage LLMs to build your own retrieval-augmented generation (RAG) chatbot using synthetic data with LangChain and Neo4j.
REAL PYTHON

Use Weird Tests to Capture Tacit Knowledge

Sometimes adding code in one place means configuration elsewhere also needs to be updated. One way of ensuring this is happening properly in a large project is to use unit tests. This post covers a few examples, complete with pytest code.
JUSTIN DUKE

Blocked by Slow Code Reviews? Here’s How to Stop Waiting

Code reviews are great - but they shouldn’t slow down your development. Sourcery can automatically review every one of your PR’s so your team can keep moving fast →
SOURCERY sponsor

Insecurity and Python Pickles

The pickle module allows you to serialize arbitrary Python objects. Serializing them back means executing code, which has potential security issues. Read on to discover what they are and what software may be impacted.
DAROC ALDEN

Python Basics Exercises: Installing Packages With pip

In this Python Basics Exercises video course, you’ll practice installing packages with pip. You’ll also practice creating virtual environments, making lists of requirements, and recreating a development environment.
REAL PYTHON course

How to Create a Dashboard in Python From PostgreSQL

Accessing a database in a terminal is not the best solution for everyone. Mljar lets you build a dashboard from scratch using only Python.
MLJAR • Shared by Piotr

Regex Character “$” Doesn’t Mean “End-of-String”

Regular expression syntax is only somewhat uniform across programming languages. Seth ran into a surprise with “$” and Python.
SETH LARSON

Feature Flags Are Ruining Your Codebase

An opinion piece on feature flags and the dangers of letting PMs control them. Includes suggestions on what to do instead.
ANTON ZAIDES

The 2038 Problem

Learn how “The 2038 problem” could impact software, hardware, and more - and what can be done to prepare.
CODE RELIANT

Add Magic Link Sign-in Using Django

This is a step-by-step guide to adding email sign-in (and verification) to Django using Gmail and others.
PHOTON DESIGNER

Email Testing With Python’s smtpd Module

This post dives deep into Python’s smtpd module and explores how it can used for local testing.
MUHAMMAD

Projects & Code zakuchess: Chess Challenge Game

GITHUB.COM/OLIVIERPHI

mountaineer: Web Framework for Python and React

GITHUB.COM/PIERCEFREEMAN

magika: Detect File Content Types With Deep Learning

GITHUB.COM/GOOGLE

hyperdiv: Build Reactive Web UIs in Python

GITHUB.COM/HYPERDIV

UFO: A UI-Focused Agent for Windows OS Interaction

GITHUB.COM/MICROSOFT

Events Weekly Real Python Office Hours Q&A (Virtual)

March 20, 2024
REALPYTHON.COM

PyData Bristol Meetup

March 21, 2024
MEETUP.COM

PyLadies Dublin

March 21, 2024
PYLADIES.COM

Python Barcamp Karlsruhe

March 23 to March 25, 2024
BARCAMPS.EU

PyDelhi User Group Meetup

March 23, 2024
MEETUP.COM

Happy Pythoning!
This was PyCoder’s Weekly Issue #621.
View in Browser »

[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]

Categories: FLOSS Project Planets

Real Python: SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files

Tue, 2024-03-19 10:00

All programs process data in one form or another, and many need to be able to save and retrieve that data from one invocation to the next. Python, SQLite, and SQLAlchemy give your programs database functionality, allowing you to store data in a single file without the need for a database server.

You can achieve similar results using flat files in any number of formats, including CSV, JSON, XML, and even custom formats. Flat files are often human-readable text files—though they can also be binary data—with a structure that can be parsed by a computer program. You’ll explore using SQL databases and flat files for data storage and manipulation and learn how to decide which approach is right for your program.

In this video course, you’ll learn how to use:

  • Flat files for data storage
  • SQL to improve access to persistent data
  • SQLite for data storage
  • SQLAlchemy to work with data as Python objects

[ 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

Robin Wilson: One reason for getting a ‘No HTTP triggers found’ error when using Azure Functions with Python V2 programming model

Tue, 2024-03-19 06:38

Summary: It might be because there is an exception raised when importing your function_app.py – for example, caused by one of your import statements raising an exception, or a parsing error caused by a syntax error.

I was deploying a FastAPI app to Azure Functions recently. Azure Function is the equivalent of AWS Lambda – it provides a way to run serverless functions.

Since I’d last used Azure Functions, Microsoft have introduced the Azure Functions Python V2 programming model which makes it easier and cleaner to do a number of common tasks, such as hooking up a FastAPI app to run on Functions.

However, it also led to an error that I hadn’t seen before, and that I couldn’t find documented very well online.

Specifically, I was getting an error at the end of my function deployment saying No HTTP triggers found. I was confused by this because I had followed the documented pattern for setting up a FastAPI app. For reference, my function_app.py file looked a bit like this:

import azure.functions as func from complex_fastapi_app import app app = func.AsgiFunctionApp(app=app, http_auth_level=func.AuthLevel.ANONYMOUS)

This was exactly as documented. But I kept getting this error – why?

I replaced the import of my complex_fastapi_app with a basic FastAPI app defined in function_app.py, this time copied directly from the documentation:

import azure.functions as func from fastapi import FastAPI, Request, Response fast_app = FastAPI() @fast_app.get("/return_http_no_body") async def return_http_no_body(): return Response(content="", media_type="text/plain") app = func.AsgiFunctionApp(app=fast_app, http_auth_level=func.AuthLevel.ANONYMOUS)

Everything worked fine now and I didn’t get the error.

After a lot of debugging, it turns out that if there is an exception raised when importing your function_app.py file then Functions won’t be able to establish what HTTP triggers you have, and will give this error.

In this case, I was getting an exception raised when I imported my complex_fastapi_app, and that stopped the whole file being processed. Unfortunately I couldn’t find anywhere that this error was actually being reported to me – I must admit that I find Azure logging/error reporting systems very opaque. I assume it would have been reported somewhere – if anyone reading this can point me to the right place then that’d be great!

I’m sure there are many other reasons that this error can occur, but this was one that I hadn’t found documented online – so hopefully this can be useful to someone.

Categories: FLOSS Project Planets

Pages