Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.

Similar Podcasts

24H24L

24H24L
Evento en línea, de 24 horas de duración que consiste en la emisión de 24 audios de diversas temáticas sobre GNU/Linux. Estos son los audios del evento en formato podcast.

The Infinite Monkey Cage

The Infinite Monkey Cage
Brian Cox and Robin Ince host a witty, irreverent look at the world through scientists' eyes.

Talking Kotlin

Talking Kotlin
A bimonthly podcast that covers the Kotlin programming language by JetBrains, as well as related technologies. Hosted by Hadi Hariri

#300 A Jupyter merge driver for git

September 06, 2022 00:55:21 46.74 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Special guest: Seth Larson Brian #1: Test your packages and wheels I’ve been building some wheels the last couple of weeks with various tools: flit, flit-core, and flit build hatch, hatchling, and hatch build setuptools, build_meta, and python -m build There are a few projects I’ve used to make sure my projects are in good shape wheel-inspect - you can inspect within Python code through inspect_wheel() function that converts to json. Or use on the command line with wheel2json check-wheel-contents - a linter for wheels tox - easily test the building, installation, and running of a package locally I actually start here, then utilize the other two tools Should have been obvious, but it wasn’t to me Projects saved on git (such as gitHub) don’t keep wheels in git. (this was obvious) When installing from git using pip install git+https://path/to/git/repo.git Your local pip will run the packaging backend to build the wheel before installing. Yet another way to test packaging. Michael #2: The Jupyter+git problem is now solved Jupyter notebooks don’t work with git by default (they inherently have meaningless conflicts). With nbdev2, the Jupyter+git problem has been totally solved. Uses a set of hooks which provide clean git diffs, solve most git conflicts automatically, and ensure that any remaining conflicts can be resolved entirely within the standard Jupyter notebook environment. The techniques used to make the merge driver work are quite fascinating Seth #3: Help us test system trust stores in Python Package aiming to replace certifi called “truststore”, use system trust stores for HTTPS instead of a static list of certificates. Problem truststore is solving usually manifests in corporate networks: “unable to get local issuer certificate”. Experimental support added to pip to prove the implementation Users can try out the functionality and report issues. Brian #4: Making plots in your terminal with plotext Bob Belderbos Tutorial on using plotext - that’s one t in the middle With the rise of CLI usage, plots are a nice addition. Bob’s plot is great, but check out the options in the plotext docs lots-o-plots streaming data images subplots so fun Michael #5: jinja2-fragments Carson from HTMX (see podcast and course) wrote about template fragments. My jinja_partials project sorta fulfills this, but not really. I had a nice discussion with Sergi Pons Freixes who uses jinja_partials about this. He created Jinja2 fragments Seth #6: SLSA 3 Generic Builder for GitHub Actions GA Supply chain Levels for Software Artifacts, or SLSA (“salsa”) Tools to attest to and verify “provenance” of artifacts, ie “where it came from” Prove cryptographically that artifacts are built from a specific GitHub repository, commit, tag. Another future defense against stolen PyPI credentials/accounts. Generic builder means you can sign anything, like wheels/sdists Extras Brian: Bring your pytest books to PyBay, if you want them signed. I’m only bringing a small amount. I’ll be presenting "Sharing is Caring - pytest fixture edition” at 3:05 “Experts Panel on Testing in Python” at 7:00 And be a zombie on my 8 am flight back unless I can change my reservation. That’s this weekend, Sat Sept 10, in SF Michael: Heroku announces plans to eliminate free plans Banned paywalls PyPI phisher identified: Actor Phishing PyPI Users Identified and Actors behind PyPI supply chain attack have been active since late 2021 Major Python CVE: CVE-2020-10735: Prevent DoS by large int[HTML_REMOVED]str conversions Seth: Pyxel, retro game engine for Python, v1.8.0 added experimental web support with WASM Joke: Dev just after work

#299 Will McGugan drops by

September 03, 2022 00:46:07 38.96 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by the IRL Podcast from Mozilla Michael #1: Careful with that PyPI email via John Hagen There is a widespread Phishing attack going on against PyPI users. The PyPA is currently tweeting about it: https://twitter.com/pypi/status/1562442188285308929 Brian #2: IEEE Top Programming Languages 2022 : Python’s still No. 1, but employers love to see SQL skills by Stephen Cass Related: The Rise of SQL It’s become the second programming language everyone needs to know by Rina Diane Caballar Good to see Python on top for Spectrum and Trending But interesting to see growth and strength in SQL SQL is actually top for Jobs SQL is a skill you can’t ignore. Not only are relational databases just as important for large systems, they’re increasingly more important for small and even local systems, and are ever growing the responsibility of developers, not left to database specialists. Will #3: Using Mypy in production at Spring by Charlie Marsh Michael #4: Django 4.1 Yes, I’m a bit slow to notice this, from August 3, 2022. Big deal for us async folks! Asynchronous ORM interface: QuerySet now provides an asynchronous interface for all data access operations. Asynchronous handlers for class-based views: View subclasses may now define async HTTP method handlers: Also: Validation of Constraints: Check, unique, and exclusion constraints defined in the Meta.constraints option are now checked during model validation. Check out Chris’ Django: Getting Started course at Talk Python. Brian #5: You Should Be Using Python's Walrus Operator - Here’s Why by Martin Heinz A fun look at some places where I’ve never considered using := Examples reusing a value while building a list regular expression match results cleaning up while loops (ok, that I’m using already, but it’s great) accumulating data in place named values in f-strings for multiple formatting. wow, super cool. … Will #6: Humre By Al Sweigart Author of "Automate the Boring Stuff with Python" Human readable regular expressions§ Joke: Password PR

#298 "Unstoppable" Python

August 24, 2022 00:32:22 27.32 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Brian #1: Uncommon Uses of Python in Commonly Used Libraries by Eugene Yan Specifically, Using relative imports Example from sklearn’s base.py from .utils.validation import check_X_y from .utils.validation import check_array “Relative imports ensure we search the current package (and import from it) before searching the rest of the PYTHONPATH. “ For relative imports, we have to use the from .something import thing form. We cannot use import .something since later on in the code .something isn’t valid. There’s a good discussion of relative imports in pep 328 Michael #2: Skyplane Cloud Transfers Skyplane is a tool for blazingly fast bulk data transfers in the cloud. Skyplane manages parallelism, data partitioning, and network paths to optimize data transfers, and can also spin up VM instances to increase transfer throughput. You can use Skyplane to transfer data: Between buckets within a cloud provider Between object stores across multiple cloud providers (experimental) Between local storage and cloud object stores Skyplane takes several steps to ensure the correctness of transfers: Checksums, verify files exist and match sizes. Data transfers in Skyplane are encrypted end-to-end. Security: Encrypted while in transit and over TLS + config options Brian #3: 7 things I've learned building a modern TUI framework by Will McGugan Specifically, DictViews are amazing. They have set operations. Example of using items() to get views, then ^ for symmetric difference (done at the C level): # Get widgets which are new or changed print(render_map.items() ^ new_render_map.items()) Lots of other great topics in the article lru_cache is fast Unicode art in addition to text in doc strings The fractions module and a cool embedded video demo of some of the new css stuff in Textual Python’s object allocator ascii art Michael #4: ‘Unstoppable’ Python Python popularity still soaring: ‘Unstoppable’ Python once again ranked No. 1 in the August updates of both the Tiobe and Pypl indexes of programming language popularity. Python first took the top spot in the index last October, becoming the only language besides Java and C to hold the No. 1 position. “Python seems to be unstoppable,” said the Tiobe commentary accompanying the August index. In the alternative Pypl Popularity of Programming Language index, which assesses language popularity based on Google searches of programming language tutorials, Python is way out front. Extras Brian: Matplotlib stylesheets can make your chart look awesome with one line of code. But it never occurred to me that I could write my own style sheet. Here’s an article discussing creation of custom matplotlib stylesheets The Magic of Matplotlib Stylesheets XKCD Plots Michael: Back on 295 we talked about Flet. We now have a Talk Python episode on it (live and polished versions). Joke: Rakes and AWS

#297 I AM the documentation

August 16, 2022 00:22:36 19.66 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by the IRL Podcast from Mozilla Michael #1: SQLCodeGen via Josh Thurston This is a tool that reads the structure of an existing database and generates the appropriate SQLAlchemy model code, using the declarative style if possible. This tool was written as a replacement for sqlautocode, which was suffering from several issues (including, but not limited to, incompatibility with Python 3 and the latest SQLAlchemy version). Features: Supports SQLAlchemy 1.4.x Produces declarative code that almost looks like it was hand written Produces PEP 8 compliant code Accurately determines relationships, including many-to-many, one-to-one Automatically detects joined table inheritance Excellent test coverage Brian #2: The death of setup.py*, long live pyproject.toml for Python-only projects Juan Luis Cano Rodriguez tweet pip install --``editable . now works with setuptools, as of version 64.0.0 To be clear, setup.cfg also not required. So everything can be in pyproject.toml The * part: projects with non-Python bits may still need setup.py See also the newly updated tutorial by the PyPA: Packaging Python Projects Now with absolutely no mention of setup.py or setup.cfg It’s all pyproject.toml Commentary: For Python only projects, is setuptools a decent flit contender??? stay tuned Michael #3: aiocache via Owen Lamont In the same vein as async-cache you might also be interested in aiocache. It has some cool functionality like an optional Redis backend for multi process caching. his library aims for simplicity over specialization. All caches contain the same minimum interface which consists on the following functions: add: Only adds key/value if key does not exist. get: Retrieve value identified by key. set: Sets key/value. multi_get: Retrieves multiple key/values. multi_set: Sets multiple key/values. exists: Returns True if key exists False otherwise. increment: Increment the value stored in the given key. delete: Deletes key and returns number of deleted items. clear: Clears the items stored. raw: Executes the specified command using the underlying client. Brian #4: Hatch : a modern, extensible Python project manager Another flit contender? While reading Packaging Python Projects tutorial update, I noticed some examples for hatchling, as an alternative to setuptools, flit-core, and pdm. Played with it some, but still have some exploring to do. features Standardized build system with reproducible builds by default Robust environment management with support for custom scripts Easy publishing to PyPI or other sources includes --repo flag to be able to publish to alternative indices. Awesome for internal systems. Version management Configurable project generation with sane defaults Responsive CLI, ~2-3x faster than equivalent tools This sounds great. I haven’t verified this Commentary: Good to see more packaging tools and user workflow explorations around packaging. Extras Michael: M1 Support for PyPy Announced (via PyCoders) Joke: I am the docs

#296 pip: Constrain your excitement

August 09, 2022 00:32:31 31.44 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by the IRL Podcast from Mozilla Brian #1: Pip constraints files by luminousmen You can put some constraints on your dependencies with a constraints file. “Constraints files are requirements files that only control which version of a requirement is installed, not whether it is installed or not. “ Syntax is a subset of requirements.txt syntax but all the restrictions seem reasonable, considering must have a name can’t be editable can’t specify extras (that one is maybe slightly weird) You can put --constraint constraints.txt right at the top of your requirements.txt file or specify it on command line, pip install --constraint constraints.txt -r requirements.txt Or, my favorite, stick it at the top of requirements.in file. yes. pip-compile correctly handles constraints when generating requirements.txt. Example requirements.in --constraint constraints.txt typer constraints.txt click<8.1.3 Output from pip-compile requirements.in # # This file is autogenerated by pip-compile with python 3.10 # To update, run: # # pip-compile requirements.in # click==8.1.2 # via # -c constraints.txt # typer typer==0.6.1 # via -r requirements.in Michael #2: async-cache A caching solution for asyncio Quite simple but looks effective and flexible too Example: # TTL Cache from cache import AsyncTTL @AsyncTTL(time_to_live=60, maxsize=1024) async def func(*args, **kwargs): """ time_to_live : max time for which a cached result is valid maxsize : max number of results that are cached. if max limit is reached the oldest result is deleted. """ pass Brian #3: Organize Python code like a PRO Guilherme Latrova Yes, this is one author’s opinion. but… lots of great advice nothing too weird no tool recommendations Recommendations of note keep a src dir. A cool and simple reason: it keeps your source code together in alphabetized IDEs. file/module names: plural except for config, main, core, or similar slightly weird tangent that there are no files, there are modules. ok, whatever. Also talking about directories as main modules. odd. but ok. functions/methods should be verbs variables/constants should be nouns Class names should be singular, unless the class really represents a container The __name__ == "__main__" trick for modules. The __main__.py entry point trick for modules/packages so that -m mymodule does something. - Michael #4: keyring via Trent The Python keyring library provides an easy way to access the system keyring service from python. It can be used in any application that needs safe password storage. It’s also helpful in that it allows you to write your own backends. Useful for testing. Basically create a dummy keychain that stores to a pytest temp_path fixture instead of cluttering the real keychain. You could potentially write a backend to interact with any service such as 1Password. Extras Brian: I’m taking a class on FastAPI. The instructor is awesome! Also, editing some pytest course video. Michael: Gitlab, you alright?? Joke: from a dad-jokes repo Q: How do programming pirates pass method parameters? A: Varrrrarrrgs. Q: How do you get the code for the bank vault? A: You checkout their branch. "Unfortunately these jokes only work if you git them." Screw driver

#295 Flutter + Python GUI Apps?

August 04, 2022 00:36:16 30.6 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Michael #1: Faster routing for Flask & Quart Flask and Quart both utilise Werkzeug's HTTP route With the upcoming 2.2 release of Werkzeug this router will be significantly faster, with up to a factor of 5. Better for large sets of routes Micro-benchmarks are unaffected and are unlikely to show a speedup. Started with tree-based radix algorithm Moved to state machine algorithm because of wild cards Brian #2: Quarto: an open-source scientific and technical publishing system built on Pandoc suggested by Paul Mackenzie Power of Pandoc and Jupyter Build documents - html, pdf, word presentations - Revealjs, PowerPoint, Beemer websites books - html, pdf, word, epub journal articles - acm, plos, elsevier, acs, jss Publish GitHub pages, Netlify, … kinda related - Kindle to support ePub Michael #3: Flet UI via Mikael Honkala New and upcoming UI framework by Feodor Fitzner: flet. It has a very interesting stack - a Python client driving a Flutter front-end via a Go server. That sounds complicated, but the developer experience is incredibly simple. Installation is just pip install flet. Here's a quick and stupid but working sample: import time import flet from flet import Column, ElevatedButton, Page, Row, TextField def main(page: Page): text_field = TextField() def clear_field(event): text_field.value = "CLEARING" page.update() time.sleep(1) text_field.value = "" page.update() clear_button = ElevatedButton("Clear the field", on_click=clear_field) page.add(Row([Column([text_field, clear_button])], alignment="center")) page.update() flet.app(target=main) # If you run this, you get a native app window on Mac, Windows or Linux, looking something like this: While the example is simple, it shows the handling of an event, updating the UI, and even doing a little sleeping between the updates, without having to worry about threads and such. What's more important, if you change the last line to: flet.app(target=main, view=WEB_BROWSER) You get the exact same functionality, but as a web application in a browser, with support for multiple users and deep linking to different parts of the app. All without leaving the comfortable Python world, with its access to all Python libraries, and without having to learn 3 extra, completely different languages (yes, HTML, CSS and JavaScript). As this is Flutter, mobile support is in the works, after the basic UI functionality is all there. Check the project front page here: flet.dev Jump directly to the currently available controls: flet.dev/docs/controls Check couple of tutorials here: flet.dev/docs/tutorials Or read the plans for the mobile support here: flet.dev/blog/flet-mobile-strategy Brian #4: Building an authenticated Python CLI Project that uses click, rich, and OAth for using Twitter API Persistent authentication requests secret information from user using getpass and input Client ID, Client Secret, App name fetches bearer token from Twitter API stores token in netrc file I’m not familiar with netrc, so I don’t know if this is a good idea or not. So I figured I’d ask Michael Extras Michael: New course: Django - Getting Started Joke: Light touches kingdom

#294 Specializing Adaptive Interpreters in Full Color

July 26, 2022 00:35:26 30.0 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Michael #1: Specialist: Python 3.11 perf highlighter via Alex Waygood Visualize CPython 3.11's specializing, adaptive interpreter. 🔥 PEP 659 – Specializing Adaptive Interpreter Specialist uses fine-grained location information to create visual representations of exactly where and how CPython 3.11's new specializing, adaptive interpreter optimizes your code. Dark, rich colors indicate code with many quickened instructions (and, therefore, high specialization potential), while light, pale colors indicate code with relatively few specialization opportunities. Brian #2: tomli “A lil’ TOML parser” Fully compatible with TOML spec 1.0.0 This is the library that tomllib from Python 3.11 is based on, so great to use for Python 3.7-3.10 applications. We discussed Python 3.11 and PEP 680 on episode 273 Real Python has a great introduction for TOML in Python: Python and TOML: New Best Friends TOML as a config format, key-value pairs, data types using both tomli and tomllib Loading TOML documents into Python And like, writing, and updating toml docs programatically, which, although cool, I think the bulk of users can kinda skip over. But the the first 3 sections are an excellent reference. Tables are cool, with [name] and [name.subsection] syntax, as well as arrays of tables with [[name]] syntax. I didn’t know how to do that before this article. Michael #3: Pydantic V2 Plan via Douglas Nichols and John Thagen A very detailed plan Goal to have all this done by the end of October, definitely by the end of the year. Samuel Colvin take a sabbatical to work on this (sound familiar?) Some details highlighted by John: Moving the core logic to Rust to drastically increase performance (17x) https://pydantic-docs.helpmanual.io/blog/pydantic-v2/#performance Strict mode (something I've wanted for a long time): https://pydantic-docs.helpmanual.io/blog/pydantic-v2/#strict-mode Cleaning up required vs nullable: https://pydantic-docs.helpmanual.io/blog/pydantic-v2/#required-vs-nullable-cleanup Naming cleanup: https://pydantic-docs.helpmanual.io/blog/pydantic-v2/#model-namespace-cleanup This is a huge change, but overall it looks very promising for the community. It will likely require refactors by downstream users, so pinning pydantic using Poetry/pip-tools etc like always is a good idea. Many things have Pydantic at the core, so this matters, including: FastAPI Beanie SQLModel Pydastic … Brian #4: pikepdf a Python library for reading and writing PDF files Based on QPDF, which is written in C++. Features: Supports password protected PDFs Creates linearized ("fast web view") PDFs Integrates with Jupyter and IPython notebooks for rapid development Some cool uses copy pates from one PDF into another split and merge PDFs extract content replace content, such as replacing images, without altering the rest of the file. Documentation mentions that if you only want to write PDFs, consider other libs, such as reportlab. Extras Brian: pytest-check I’ve set up 2fa for my account, so now I have no excuse for not looking into feature requests and merge requests for pytest-check, other than like all the other things I’m doing. I don’t have data for the top 3,500 for the last 6 months, but there is a list of the top 5,000 for last 30 days. pytest-check is #1677 in the last 30 days. pytest is #72 on the same list. pydantic is #117 There are 57 pytest plugins that show up in the top 3,500 python packages. (packages that start with “pytest-”) pytest-check is #20 of those. I guess it’s time to do another top plugins episode of Test & Code. Joke: Error, OK, I’ll check the logs

#293 And if I pull this open source Jenga block...

July 20, 2022 00:47:34 40.2 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Special guest: Ashley Anderson Ashley #1: PSF security key giveaway for critical package maintainers Giving away 4000 2FA hardware keys Surely a team effort but I found it via @di_codes twitter (Dustin Ingram) links to previous talks on PyPI/supply chain security Interesting idea for helping with supply-chain vulnerabilities At least one dev pulled a critical package in response Previously: <add some links to prior discussions> I don’t have any critical projects Armin Ronacher has an interesting take Michael #2: PyLeft-Pad via Dan Bader Markus Unterwaditzer was maintaining atomicwrites More on how this relates to a project (Home Assistant) I wonder if PyPI will become immutable once an item is published Brian #3: FastAPI Filter Suggested and created by Arthur Rio “I loved using django-filter with DRF and wanted an equivalent for FastAPI.” - Arthur Add query string filters to your api endpoints and show them in the swagger UI. Supports SQLAlchemy and MongoEngine. Supports operators: gt, gte, in, isnull, it, lte, not/ne, not_in/nin Ashley #4: Tools for building Python extensions in Rust PyO3 pyo3 - Python/Rust FFI bindings nice list of examples people might recognize in the PyO3 README Pydantic V2 will use it for pydantic-core maturin - PEP 621 wheel builder (pyproject.toml) pretty light weight, feels like flit for Rust or python/Rust rust-numpy (+ndarray) for scientific computing setuptools-rust for integrating with existing Python projects using setuptools Rust project and community place high value on good tooling, relatively young language/community with a coherent story from early on Rust macro system allows for really nice ergonomics (writing macros is very hard, using them is very easy) The performance/safety/simplicity tradeoffs Python and Rust make are very different, but both really appeal to me - Michael #5: AutoRegEx via Jason Washburn Enter an english phrase, it’ll try to generate a regex for you You can do the reverse too, explain a regex You must sign in and are limited to 100 queries / [some time frame] Related from Simon Willison: Using GPT-3 to explain how code works Brian #6: Anaconda Acquires PythonAnywhere Suggested by Filip Łajszczak See also Anaconda Acquisition FAQs from PythonAnywhere blog From announcement: “The acquisition comes on the heels of Anaconda’s release of PyScript, an open-source framework running Python applications within the HTML environment. The PythonAnywhere acquisition and the development of PyScript are central to Anaconda’s focus on democratizing Python and data science.” My take: We don’t hear a lot about PA much, even their own blog has had 3 posts in 2022, including the acquisition announcement. Their home page boasts “Python versions 2.7, 3.5, 3.6, 3.7 and 3.8”, although I think they support 3.9 as well, but not 3.10 yet, seems like from the forum. Also, no ASGI, so FastAPI won’t work, for example. Still, I think PA is a cool idea, and I’d like to see it stay around, and stay up to date. Hopefully this acquisition is the shot in the arm it needed. Extras Michael: Python becomes the most sought after for employers hiring (by some metric) Ashley: PEP691 JSON Simple API for PyPI Rich Codex - automatic terminal “screenshots” Joke: Neta is a programmer

#292 Thursday, it's always a Thursday

July 11, 2022 00:28:36 24.26 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by Microsoft for Startups Founders Hub. Brian #1: rich-codex by Phil Ewels suggested by Will McGugan “A GitHub Action / command-line tool which generates screen grab images of a terminal window, containing command outputs or code snippets.” Generate images from commands embedded in markdown files, like README.md, for example. Searches through markdown files for stuff like: ![cat cat.txt | lolcat -S 1](img/cat.svg) then runs the command, and generates the image. Can be done within a GitHub action Can also send code snippets or json to rich-cli, then generate an image. You can also have commands in a config file, Very easy to use, makes very professional looking images for documentation, that’s always up to date. Michael #2: Pydastic via Roman Right, by Rami Awar Pydastic is an elasticsearch python ORM based on Pydantic. Core Features Simple CRUD operations supported Sessions for simplifying bulk operations (a la SQLAlchemy) Dynamic index support when committing operations More on Elasticsearch here Brian #3: 3 Things to Know Before Building with PyScript by Braden Riggs Package indentation matters Local file access is possible. [HTML_REMOVED] - numpy - pandas - paths: - /views.csv [HTML_REMOVED] DOM manipulation has interesting conventions For buttons, you can include pys-onClick=”your_function” parameter to trigger python functions when clicked. For retrieving user input from within the [HTML_REMOVED] tag document.getElementById(‘input_obj_id’).value can retrieve the input value. And Finally pyscript.write(“output_obj_id”, data) can write output to a tag from within the [HTML_REMOVED] tag. Michael's Pyscript videos Python + pyscript + WebAssembly: Python Web Apps, Running Locally with pyscript Python iOS Web App with pyscript and offline PWAs Michael #4: disnake via Sean Koenig disnake is a modern, easy to use, feature-rich, and async-ready API wrapper for Discord. Features: Modern Pythonic API using async/await syntax Sane rate limit handling that prevents 429 errors Command extension to aid with bot creation Easy to use with an object oriented design Optimized for both speed and memory Quickstart Commands API Extras Michael: Scholarships for upcoming FastAPI + MongoDB live course Humble Bundle for Python 2022 Michael's crazy earbuds (UE Fits) Joke: Better than a wage increase

#291 Wait, you have how many licenses?!?

July 06, 2022 00:32:27 27.38 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Michael #1: Python License tracker by Tom Nijhof/Nyhof Every package depends on other package with sometimes different licenses. Tom made a tool to find out what licenses you all need for a project: PyTest alone needs 4 different licenses for itself and its dependencies. Tensorflow is even worst Brian #2: undataclass Trey Hunner As a teaching aid, and to show how much dataclasses do for you, this is a module and an application that converts dataclasses to normal classes, and fills in all of the dunder methods you need. Example in app: from dataclasses import dataclass @dataclass() class Point: x: float y: float z: float Converts to class Point: __match_args__ = ('x', 'y', 'z') def __init__(self, x: float, y: float, z: float) -> None: self.x = x self.y = y self.z = z def __repr__(self): cls = type(self).__name__ return f'{cls}(x={self.x!r}, y={self.y!r}, z={self.z!r})' def __eq__(self, other): if not isinstance(other, Point): return NotImplemented return (self.x, self.y, self.z) == (other.x, other.y, other.z) Note on NotImplemented: It just means, “I don’t know how to compare this”, and Python will try __eq__ on the other object. If that also raises NotImplemented, a False is returned. The default is the above with @dataclass(frozen=True, slots=True) and adds the methods: fronzen=True gives you implementations of __hash__, __setattr__, __delattr__, __getstate__, __setstate__, Essentially raises exception if you try to change the contents, and makes your objects hashable. slots=True adds the line: __slots__ = (``'``x', '``y``'``, '``z``'``). This disallows adding new attributes to objects at runtime. See Python docs Trey wrote two posts about it: Appreciating Python's match-case by parsing Python code How I made a dataclass remover Turns out, this is a cool example for AST and structural pattern matching. Notes from the “how I made..” article: "I used some tricks I don't usually get to use in Python. I used: Many very hairy **match**-**case** blocks which replaced even hairier if-elif blocks A sentinel object to keep track of a location that needed replacing Python's **textwrap.dedent** utility, which I feel should be more widely known & used slice assignment to inject one list into another The ast module's unparse function to convert an abstract syntax tree into Python code” Michael #3: Qutebrowser via Martin Borus Qutebrowser is a keyboard-focused browser with a minimal GUI." It's Python powered Whats more important - doesn't force you to use it's Vim-based shortcuts, the mouse still works. But you usually don't need it: Because on any page, a keypress on the "f" key will show, you every clickable think and a letter combination to enter to click this. Brian #4: asyncio and web applications A collection of articles Quart is now a Pallets project P G Jones, maintainer of Quart and Hypercorn “Quart, an ASGI re-implementation of the Flask API has joined the Pallets organization. This means that future development will be under the Pallets governance by the Pallets maintainers. Our long term aim is to merge Quart and Flask to bring ASGI support directly to Flask. “When to use Quart?” “Quart is an ASGI framework utilising async IO throughout, whereas Flask is a WSGI framework utilising sync IO. It is therefore best to use Quart if you intend to use async IO (i.e. async/await libraries) and Flask if not. Don't worry if you choose the 'wrong' framework though, as Quart supports sync IO and Flask supports async IO, although less efficiently.” Using async and await, from Flask docs Flask has some support of async/await since Flask 2.0 But it’s still a WSGI application. “Deciding whether you should use Flask, Quart, or something else is ultimately up to understanding the specific needs of your project.” Should You Use AsyncIO for Your Next Python Web Application? Steven Pate A cool “brief history of Python web server interfaces” Discussion of the Python servers and frameworks for both WSGI and ASGI Recommendation: Do you need async? “… most people don’t. WSGI servers and frameworks are usually performant enough.” Extras Michael: Python Web Conf Talk: HTMX + Flask: Modern Python Web Apps, Hold the JavaScript browserosaurus Joke: Understanding JavaScript Joke: Where do you see yourself in 5 years?

#290 Sentient AI? If so, then what?

June 28, 2022 00:49:34 41.77 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Special guest: Nick Muoh Brian #1: picologging From a tweet by Anthony Shaw From README.md “early-alpha” stage project with some incomplete features. (cool to be so up front about that) “Picologging is a high-performance logging library for Python. picologging is 4-10x faster than the logging module in the standard library.” “Picologging is designed to be used as a drop-in replacement for applications which already use logging, and supports the same API as the logging module.” Now you’ve definitely got my attention. For many common use cases, it’s just way faster. Sounds great, why not use it? A few limitations listed: process and thread name not captured. Some logging globals not observed: logging.logThreads, logging.logMultiprocessing, logging.logProcesses Logger will always default to the Sys.stderr and not observe (emittedNoHandlerWarning). Michael #2: CheekyKeys via Prayson Daniel What if you could silently talk to your computer? CheekyKeys uses OpenCV and MediaPipe's Face Mesh to perform real-time detection of facial landmarks from video input. The primary input is to "type" letters, digits, and symbols via Morse code by opening and closing your mouth quickly for . and slightly longer for -. Most of the rest of the keyboard and other helpful actions are included as modifier gestures, such as: shift: close right eye command: close left eye arrow up/down: raise left/right eyebrow … Watch the video where he does a coding interview for a big tech company using no keyboard. Nick #3: Is Google’s LaMDA Model Sentient? authored by Richard Luscombe (The Guardian) The Google engineer who thinks the company’s AI has come to life Transcript of conversation Brian #4: richbench Also from Anthony “A little Python benchmarking tool.” Give it a list of (first_func, second_func, “label”), and it times them and prints out a comparison. Simple and awesome. def sort_seven(): """Sort a list of seven items""" for _ in range(10_000): sorted([3,2,4,5,1,5,3]) def sort_three(): """Sort a list of three items""" for _ in range(10_000): sorted([3,2,4]) __benchmarks__ = [ (sort_seven, sort_three, "Sorting 3 items instead of 7") ] Michael #5: typeguard A run-time type checker for Python Three principal ways to do type checking are provided, each with its pros and cons: Manually with function calls @typechecked decorator import hook (typeguard.importhook.install_import_hook()) Example: @typechecked def some_function(a: int, b: float, c: str, *args: str) -> bool: ... return retval Nick #6: CustomTkinter A modern and customizable python UI-library based on Tkinter. Extras Michael: OpenSSF Funds Python and Eclipse Foundations - OpenSSF’s Alpha-Omega Project has committed $400K to the Python Software Foundation (PSF), in order to create a new role which will provide security expertise for Python, the Python Package Index (PyPI), and the rest of the Python ecosystem, as well as funding a security audit. (via Python Weekly) Nick: Terms of Service Didn’t Read - Terms of Service; Didn't Read” (short: ToS;DR) is a young project started in June 2012 to help fix the “biggest lie on the web”: almost no one really reads the terms of service we agree to all the time. Joke: Serverless A DevOps approach to COVID-19

#289 Textinator is coming for your text, wherever it is

June 21, 2022 00:46:14 38.96 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Special guest: Gina Häußge, creator & maintainer of OctoPrint Michael #1: beanita Local MongoDB-like database prepared to work with Beanie ODM So, you know Beanie - Pydantic + async + MongoDB And you know Mongita - Mongita is to MongoDB as SQLite is to SQL Beanita lets you use Beanie, but against Mongita rather than a server-based MongoDB server Brian #2: The Good Research Code Handbook Patrick J Mineault “for grad students, postdocs and PIs (principle investigator) who do a lot of programming as part of their research.” lessons setup git, virtual environments, project layout, packaging, cookie cutter style style guides, keeping things clean coding separating concerns, separating pure functions and those with side effects, pythonic-ness testing unit testing, testing with side effects, … (incorrect definition of end-to-end tests, but a good job at covering the other bits) documentation comments, tests, docstrings, README.md, usage docs, tutorials, websites documenting pipelines and projects social aspects various reviews, pairing, open source, community sample project extras testing example good tools to use Gina #3: CadQuery Python lib to do build parametric 3D CAD models Can output STL, STEP, AMF, SVG and some more Uses same geometry kernel as FreeCAD (OpenCascade) Also available: desktop editor, Jupyter extension, CLI Would recommend the Jupyter extension, the app seems a bit behind latest development Jupyter extension is easy to set up on Docker and comes with a nice 3D preview pane Was able to create a basic parametric design of an insert for an assortment box easily Python 3.8+, not yet 3.11, OpenCascade related Michael #4: Textinator Like TextSniper, but in Python Simple MacOS StatusBar / Menu Bar app to automatically detect text in screenshots Built with RUMPS: Ridiculously Uncomplicated macOS Python Statusbar apps Take a screenshot of a region of the screen using ⌘ + ⇧ + 4 (Cmd + Shift + 4). The app will automatically detect any text in the screenshot and copy it to your clipboard. How Textinator Works At startup, Textinator starts a persistent NSMetadataQuery Spotlight query (using the pyobjc Python-to-Objective-C bridge) to detect when a new screenshot is created. When the user creates screenshot, the NSMetadataQuery query is fired and Textinator performs text detection using a Vision VNRecognizeTextRequest call. Brian #5: Handling Concurrency Without Locks "How to not let concurrency cripple your system” Haki Benita “…common concurrency challenges and how to overcome them with minimal locking.” Starts with a Django web app A url shortener that generates a unique short url and stores the result in a database so it doesn’t get re-used. Discussions of collision with two users checking, then storing keys at the same time. locking problems in general utilizing database ability to make sure some items are unique, in this case PostgreSQL updating your code to take advantage of database constraints support to allow you to do less locking within your code Gina #6: TatSu Generates parsers from EBNF grammars (or ANTLR) Can compile the model (similar to regex) for quick reuse or generate python source Many examples provided Active development, Python 3.10+ Extras Michael: Back on 285 we spoke about PEP 690. Now there is a proper blog post about it. Expedited release of Python3.11.0b3 - Due to a known incompatibility with pytest and the previous beta release (Python 3.11.0b2) and after some deliberation, Python release team have decided to do an expedited release of Python 3.11.0b3 so the community can continue testing their packages with pytest and therefore testing the betas as expected. (via Python Weekly) Kagi search via Daniel Hjertholm Not really python related, but if I know Michael right, he'll love the new completely ad free and privacy-respecting search engine kagi.com. I've used kagi.com since their public beta launched, mainly to search for solutions to Python issues at work. The results are way better than DuckDuckGo's results, and even better than Googles! Love the Programming-lens and the ability to up/down prioritize domains in the results. Their FAQ explains everything you need to know: https://kagi.com/faq Looks great but not sure about the pricing justification (32 sec of compute = $1), that’s either 837x more than all of Talk Python + Python Bytes or more than 6,700x more than just one of our sites/services. (We spend about $100/mo on 8 servers.) But they may be buying results from Google and Bing, and that could be the cost. Here's a short interview with the man who started kagi. Gina: rdserialtool: Reads out low-cost USB power monitors (UM24C, UM25C, UM34C) via BLE/pybluez. Amazing if you need to monitor the power consumption/voltage/current of some embedded electronics on a budget. Helped me solve a very much OctoPrint development specific problem. Python 3.4+ nodejs-bin: by Sam Willis: https://twitter.com/samwillis/status/1537787836119793667 Install nodejs via pypi/as dependency, still very much an Alpha but looks promising Makes it easier to obtain a full stack environment Very interesting for end to end testing with JS based tooling, or packaging a frontend with your Python app See also nodeenv, which does a similar thing, but with additional steps Joke: Rejected Github Badges

#288 Performance benchmarks for Python 3.11 are amazing

June 14, 2022 00:33:05 27.91 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Brian #1: Polars: Lightning-fast DataFrame library for Rust and Python Suggested by a several listeners “Polars is a blazingly fast DataFrames library implemented in Rust using Apache Arrow Columnar Format as memory model. Lazy | eager execution Multi-threaded SIMD (Single Instruction/Multiple Data) Query optimization Powerful expression API Rust | Python | ...” Python API syntax set up to allow parallel and execution while sidestepping GIL issues, for both lazy and eager use cases. From the docs: Do not kill parallelization The syntax is very functional and pipeline-esque: import polars as pl q = ( pl.scan_csv("iris.csv") .filter(pl.col("sepal_length") > 5) .groupby("species") .agg(pl.all().sum()) ) df = q.collect() Polars User Guide is excellent and looks like it’s entirely written with Python examples. Includes a 30 min intro video from PyData Global 2021 Michael #2: PSF Survey is out Have a look, their page summarizes it better than my bullet points will. Brian #3: Gin Config: a lightweight configuration framework for Python Found through Vincent D. Warmerdam’s excellent intro videos on gin on calmcode.io Quickly make parts of your code configurable through a configuration file with the @gin.configurable decorator. It’s in interesting take on config files. (Example from Vincent) # simulate.py @gin.configurable def simulate(n_samples): ... # config.py simulate.n_samples = 100 You can specify: required settings: def simulate(n_samples=gin.REQUIRED)` blacklisted settings: @gin.configurable(blacklist=["n_samples"]) external configurations (specify values to functions your code is calling) can also references to other functions: dnn.activation_fn = @tf.nn.tanh Documentation suggests that it is especially useful for machine learning. From motivation section: “Modern ML experiments require configuring a dizzying array of hyperparameters, ranging from small details like learning rates or thresholds all the way to parameters affecting the model architecture. Many choices for representing such configuration (proto buffers, tf.HParams, ParameterContainer, ConfigDict) require that model and experiment parameters are duplicated: at least once in the code where they are defined and used, and again when declaring the set of configurable hyperparameters. Gin provides a lightweight dependency injection driven approach to configuring experiments in a reliable and transparent fashion. It allows functions or classes to be annotated as @gin.configurable, which enables setting their parameters via a simple config file using a clear and powerful syntax. This approach reduces configuration maintenance, while making experiment configuration transparent and easily repeatable.” Michael #4: Performance benchmarks for Python 3.11 are amazing via Eduardo Orochena Performance may be the biggest feature of all Python 3.11 has task groups in asyncio fine-grained error locations in tracebacks the self-type to return an instance of their class The "Faster CPython Project" to speed-up the reference implementation. See my interview with Guido and Mark: talkpython.fm/339 Python 3.11 is 10~60% faster than Python 3.10 according to the official figures And a 1.22x speed-up with their standard benchmark suite. Arriving as stable until October Extras Michael: Python 3.10.5 is available (changelog) Raycast (vs Spotlight) e.g. CMD+Space => pypi search: Joke: Why wouldn't you choose a parrot for your next application

#287 Surprising ways to use Jupyter Notebooks

June 07, 2022 00:27:22 23.11 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Michael #1: auto-py-to-exe Converts .py to .exe using a simple graphical interface A good candidate to install via pipx For me, just point it at the top level app.py file and click go Can add icons, etc. Got a .app version and CLI version (I think 😉 ) Required brew install python-tk to get tkinter on my mac I tested it against my URLify app. Oddly, only ran on Python 3.9 but not 3.10 Brian #2: 8 surprising ways how to use Jupyter Notebook by Aleksandra Płońska, Piotr Płoński Fun romp through ways you can use and abuse notebooks package development web app slides book blog report dashboard REST API Michael #3: piptrends by Tankala Ashok Use piptrends.com for comparing python packages downloads and GitHub Statistics. Whenever doing research which python package, check multiple places to finalize it so thought of putting all those things in a single place. Inspired by npmtends.com. Brian #4: Is it a class or a function? It's a callable! by Trey Hunner It’s kinda hard to tell in Python. Actually, impossible to tell from staring at the calling code. “Of the 69 “built-in functions” listed in the Python Built-In Functions page, only 42 are actually implemented as functions: 26 are classes and 1 (help) is an instance of a callable class. Of the 26 classes among those built-in “functions”, four were actually functions in Python 2 (the now-lazy map, filter, range, and zip) but have since become classes. The Python built-ins and the standard library are both full of maybe-functions-maybe-classes.” len - yep, that’s a function zip - that’s a class reversed, enumerate, range, and filter “functions” are all classes. But callable classes. Cool discussion of callable objects partials, itemgetters, iterators, generators, factory functions … Extras Brian: What’s in which Python - Ned Batchelder brief bullet list of a few memorable changes in versions 2.1 through 3.11 Michael: Orion Browser via Dan Bader PSF 2021 Survey Results are out (full analysis next week) Joke: async problems

#286 Unreasonable f-strings

June 03, 2022 00:26:22 22.28 MB Downloads: 0

Watch the live stream: Watch on YouTube About the show Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Patreon Supporters Brian #1: The Python GIL: Past, Present, and Future Bary Warsaw and Paweł Polewicz Michael #2: Announcing the PyOxy Python Runner PyOxy is all of the following: An executable program used for running Python interpreters. A single file and highly portable (C)Python distribution. An alternative python driver providing more control over the interpreter than what python itself provides. A way to make some of PyOxidizer's technology more broadly available without using PyOxidizer. PyOxidizer is often used to generate binaries embedding a Python interpreter and a custom Python application. However, its configuration files support additional functionality, such as the ability to produce Windows MSI installers, macOS application bundles, and more. The pyoxy executable also embeds a copy of the Python standard library and imports it from memory using the oxidized_importer Python extension module. Brian #3: The unreasonable effectiveness of f-strings and re.VERBOSE Michael #4: PyCharm PR Management Really nice but not very discoverable Not covered in the docs, but super useful. Available in pro and free community edition Steps Open a project that has an associated github git repo If the GitHub repo has a PR, you’ll see it in the Pull Requests tab. Browse the PRs, and open them for details There you can see the comments, close or merge it, and more Most importantly, check it out to see how it works Extras Brian: Pandas Tutor: Using Pyodide to Teach Data Science at Scale Michael: Python + pyscript + WebAssembly: Python Web Apps, Running Locally with pyscript video is out And an iOS Python Apps video too Joke: Losing an orm!