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

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

Ladybug Podcast
We're Emma Bostian, Sidney Buckner, Kelly Vaughn, and Ali Spittel - four seasoned software developers working in different sectors. Since there's a major lack of technical podcasts out there, we've decided to start one. Just kidding -- there's already a ton! But, we wanted to add our voices to the space and share our experiences and advice. We'll have great discussions around how to start coding, the hot technologies right now, how to get your first developer job, and more!
Check out our website!

In Machines We Trust
A podcast about the automation of everything. Host Jennifer Strong and the team at MIT Technology Review look at what it means to entrust artificial intelligence with our most sensitive decisions.
#271 CPython: Async Task Groups in Python 3.11
Watch the live stream: Watch on YouTube About the show Sponsored by us: Check out the courses over at Talk Python And Brian’s book too! Special guest: Steve Dower Michael #1: fastapi-events Asynchronous event dispatching/handling library for FastAPI and Starlette Features: straightforward API to emit events anywhere in your code events are handled after responses are returned (doesn't affect response time) support event piping to remote queues powerful built-in handlers to handle events locally and remotely coroutine functions (async def) are the first-class citizen write your handlers, never be limited to just what fastapi_events provides Brian #2: Ways I Use Testing as a Data Scientist Peter Baumgartner “In my work, writing tests serves three purposes: making sure things work, documenting my understanding, preventing future errors.” Test The results of some analysis process (using assert) Code that operates on data (using hypothesis) Aspects of the data (using pandera or Great Expectations) Code for others (using pytest) Use asserts liberally even within the code use on as many intermediate calculations and processes as you can embed expressions in f-strings as the last argument to assert to help debug failures check calculations and arithmetic check the obvious Notebooks: “One practice I’ve started is that whenever I visually investigate some aspect of my data by writing some disposable code in a notebook, I convert that validation into an assert statement.” utilize numpy and pandas checks, especially for arrays and floating point values hypothesis can help you think of edge cases that should work, but don’t, like empty Series, and NaN values. Write tests on the data itself pandera useful for lightweight cases, checking schema on datasets. Great Expectations if we’re epecting to repeatedly read new data with the same structure. Use pytest, especially for code you are sharking with other people, like libraries. TDD works great for API development Arrange-Act-Assert is a great structure. “Even if we’re not sure what to assert, writing a test that executes the code is still valuable. “ At least you’ll catch when you’ve forgotten to implement something. Steve #3: PEP 654 Exception groups and except A necessary building block for more advanced asyncio helpers Mainly for use by scheduler libraries to handle raising multiple errors “simultaneously” except: “a single exception group can cause several except clauses to execute, but each such clause executes at most once (for all matching exceptions from the group)” Necessary for complex scheduling, such as task groups Michael #4: py-overload A Runtime method override decorator. Python lacks method overriding (do_it(7) vs. do_it(``"``7``"``)) Probably due to lack of typing in the early days Go from this: def _func_str(a: str): ... def _func_int(a: int): ... def func(a: Union[str, int]): if isinstance(a, str): _func_str(a) else: _func_int(a) To this: @overload def func(a: str): ... @overload def func(a: int): ... Brian #5: Next-generation seaborn interface Love the background and goals section “This work grew out of long-running efforts to refactor the seaborn internals so that its functions could rely on common code-paths. At a certain point, I decided that I was developing an API that would also be interesting for external users too.” “seaborn was originally conceived as a toolbox of domain-specific statistical graphics to be used alongside matplotlib.” I’ve always wondered about this Some people now reach for, or learn, seaborn first. As seaborn has grown, reproducing with raw matplotlib to change something seaborn doesn’t expose is sometimes painful goal : “expose seaborn’s core features — integration with pandas, automatic mapping between data and graphics, statistical transformations — within an interface that is more compositional, extensible, and comprehensive.” I also like interface discussions that have phrases like “This is a clean namespace, and I’m leaning towards recommending from seaborn.objects import * for interactive usecases. But let’s not go so far just yet.” I like clean namespaces, and use some of my own libs like this, but import * always is a red flag for me. The new interface exists as a set of classes that can be acessed through a single namespace import: import seaborn.objects as so Start with so.Plot, add layers, like so.Scatter(), even multiple layers. layers have a Mark object, which defines how to draw the plot, like so.Line or so.Dot There’s a lot more detail in there. The discussion is great. Also a neat understanding that established libraries can change their mind on APIs. This is a good way to discuss it, in the open. Note included at the top: “This is very much a work in progress. It is almost certain that code patterns demonstrated here will change before an official release. I do plan to issue a series of alpha/beta releases so that people can play around with it and give feedback, but it’s not at that point yet.” Steve #6: Compile CPython to Web Assembly Allows fully in-browser use of CPython (demo at https://repl.ethanhs.me/) Currently uses Emscriptem as its runtime environment, to fill in gaps that browsers don’t normally offer (like an in-memory file system), or WASI to more carefully add system functionality Still the CPython runtime, and a lot of work to do before you’ll see it as part of client-side web apps, but the possibility is now there. Extras Michael: Get minutes, hours, and days from Python timedelta - A Python Short Did you know ohmyzsh is kind of local? Django reformatted code with Black (via PyCoders) Steve: Python 3.11’s latest alpha now has Windows ARM64 installers. These aren’t the dominant devices yet, but they’re out there, and if you’ve got one the CPython team would love to hear about your experience. Steve just released a new version of Deck, which started as a way to help people who misspelled collections.deque, but has grown into a useful building block for traditional 52-card games (or 54 including jokers). Joke: Help is coming
#270 Can errors really be beautiful?
Watch the live stream: Watch on YouTube About the show Sponsored by Datadog: pythonbytes.fm/datadog Special guest: Dean Langsam Brian #1: A Better Pygame Mainloop Glyph Doing some game programming is a great way to work on coding for early devs (and experienced devs). pygame is a popular package for writing games in Python But… the normal example of a main loop, which listens for events and dispatches actions based on events, has some problems: it’s got a while 1: that wastes power, too much busy waiting looks bad, due to “screen tearing” which is writing to a screen while your in the middle of drawing it This post discusses the problems, and walks through to an async main loop that creates a better gaming experience. Michael #2: awesome sqlalchemy A few notable ones SQLAlchemy-Continuum: Versioning and auditing extension for SQLAlchemy. SQLAlchemy-Utc: SQLAlchemy type to store aware datetime.datetime values. SQLAlchemy-Utils: Various utility functions, new data types and helpers for SQLAlchemy filedepot: DEPOT is a framework for easily storing and serving files in web applications. SQLAlchemy-ImageAttach: SQLAlchemy-ImageAttach is a SQLAlchemy extension for attaching images to entity objects. SQLAlchemy-Searchable: Full-text searchable models for SQLAlchemy. sqlalchemy_schemadisplay: This module generates images from SQLAlchemy models. Can we also get a shoutout to SQLModel? Dean #3: ThreadPoolExecutor in Python: The Complete Guide Long, but worth it (80-120 minutes). Could be consumed in parts. It’s mostly a collection of other blogposts on superfastpython Many examples LifeCycle Usage patterns Map and was as_completed vs sequentially callbacks IO-Bound vs CPU-bound Common Questions Comparison vs. ProcessPoolExecutor vs. threading.Thread vs. AsyncIO Brian #4: Chaining comparison operators Rodrigo Girão Serrão I use chained expressions all the time, mostly with ranges: min <= x <= max, which is like (min <=x) and (x <= max) There are lots of chained expressions available, and some not so obvious. a == b == c all are equal, no prob what abut a != b != c ? This actually can return True if a == c Lots of other issues with chaining discussed in the article, like non-constant expressions and side effects Michael #5: Create Beautiful Tracebacks with Python’s Exception Hooks def exception_hook(exc_type, exc_value, tb): ... sys.excepthook = exception_hook Libraries rich.traceback better-exceptions Pretty Errors IPython.core.ultratb stackprinter Dean#6: Ways I Use Testing as a Data Scientist The importance of knowing what to test for using assert in code on ad-hoc things. Do it while coding. Us numpy np.isclose to test “almost equal” on entire arrays. also [assert_frame_equal](https://pandas.pydata.org/docs/reference/api/pandas.testing.assert_frame_equal.html) Use hypothesis for bombarding the function with smart tests. Pandera and Great Expectations tests are documentation! Work with Arrange-Act-Assert Even if we’re not sure what to assert, writing a test that executes the code is still valuable. Extras Dean: Deprecate urllib out of stdlib? IPython 8 is out It’s less code! 37,500 LOC across 348 files → 36,100 across 294 files “I’m sorry I wrote you such a long letter. I didn’t have time to write you a short one.” – Blaise Pascal This was all done thanks to a developer hired through Small Development Grants coloring exceptions Michael: Python Shorts New videos Beyond the List Comprehension Combining dictionaries, the Python 3.10 way / on pypi.org Joke: Spelling
#269 Get Rich and replace your cat
Watch the live stream: Watch on YouTube About the show Sponsored by Datadog: pythonbytes.fm/datadog Special guest: Luciana and Brett Cannon Brian #1:rich-cli suggested by Lance Reinsmith rich on the command line. why? syntax highlighting rich example.py rich -m README.md use -m for markdown why Will? .md seems clear enough to me. comes with themes. ex: --theme monokai formats json, --json or -j and a bunch of other features I probably won’t use, but you might. alignment, maybe width, yeah, I’ll probably use -w a bunch more In my .zshrc: alias cat='rich --theme monokai' after pipx install rich-cli feel free to tell me that I shouldn’t used cat for looking at file contents. (although, why not?) I’m not, I’m using rich. :) Luciana #2: debugpy - a debugger for Python The debugger we use in the Python extension for VS Code Super heplful features that can save up a lot of time and a lot of folks don’t seem to know about: Conditional breakpoints Helpful when you want the code to break only on a specific condition e.g. # of execution times, or when an expression is true Debug console Helpful for quick testing using the context of the program at the breakpoint Temp edits on variable values, expresison evaluation, etc. Jump to Cursor (a.k.a. Set Next Statement) Control on what is the next line the debugger will execute Including previously executed lines Brian #3: Documentation unit tests Simon Willison Post talking about using pytest and tests to check documentation. Simon has test code that introspects the code introspects the docs then makes sure some items are definitely in the docs This is used in Datasette, so you can look at the example in the repo What’s tested: config options are all documented plugin hooks are documented views are all documented Cool use of parametrize to generate test cases based on introspection Nice use of fixtures Very cool idea Luciana #4: PEP 673 — Self Type Heard from Brett Cannon that it has been accepted! Interesting for me as I’m learning more about types in Python Adds a way to annotate methods that return an instance of their class Particularly interesting for subclasses, exemple they gave: from __future__ import annotations class Shape: def set_scale(self, scale: float) -> Shape: self.scale = scale return self class Circle(Shape): def set_radius(self, r: float) -> Circle: self.radius = r return self Circle().set_scale(0.5) # *Shape*, not Circle Circle().set_scale(0.5).set_radius(2.7) # => Error: Shape has no attribute set_radius Extras Luciana: Black is no longer in beta! Version 22.1.0 is out 🥳 PyCascades 2022 reminder (remote!) Joke:
#268 Wait, you can Google that?
Watch the live stream: Watch on YouTube About the show Sponsored by us: Check out the courses over at Talk Python And Brian’s book too! Special guest: Madison @AetherUnbound Brian #1: (draft) PEP 679 -- Allow parentheses in assert statements Pablo Galindo Salgado This is in draft, not approved, and not scheduled for any release But it seems like a really good idea to me. assert(1 == 2, "seems like it should fail") will always pass currently since the tuple (False,"seems like it should fail") is a non-empty tuple. Current Python will emit a warning >>> assert(1 == 2, "seems like it should fail") [stdin]:1: SyntaxWarning: assertion is always true, perhaps remove parentheses? But really, why not just change the language to allow assert with or without parens. Also would allow multi-line assert statements more easily: assert ( very very long expression, "very very long " "message", ) I hope this is a slam dunk and gets in ASAP. Michael #2: Everything I googled as a dev by Sophie Koonin In an attempt to dispel the idea that if you have to google stuff you’re not a proper engineer, this is a list of nearly everything I googled in a week at work Rather than my posting a huge list, check out the day logs on her post Worth calling out a few: Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag? - said React upgrade then started causing some super fun errors. semantic HTML contact details - wanted to check if the [HTML_REMOVED] tag was relevant here editing host file - desperate times (and it didn’t even work) Madison #3: PyCascades 2022! Another year of excellent and diverse talks across an array of subjects. Talks from some well known folks (Thursday Bram, Jay Miller) as well as first time speakers (Joseph Riddle, Isaac Na) PSF’s DE&I Panel is doing a meet & greet, and they have a survey they’d like Python community members to fill out. Socials Friday & Saturday night, sprints on Sunday. Tickets are still available! Brian #4: Strict Python function parameters Seth Michael Larson We have keyword only parameters def process_data(data, *, encoding="ascii"): ... notice the * encoding has to be a keyword argument, cannot be positional. We have position only parameters: def process_data(data, /, encoding="ascii"): ... notice the / data has to be positional, cannot be passed in as a keyword argument Combine the two: def process_data(data, /, *, encoding="ascii"): ... Now data has to be positional, and encoding has to be a keyword, if present. This way a function really can only be called as intended and all uses of the function will be consistent. This is a good thing. There are many benefits, including empowering library authors to make changes without weird behaviors cropping up in user code. Commentary: extra syntax may be confusing for some new users. For a lot of library API entry points, I think this makes a lot of sense. Michael #5: mureq - vendored requests mureq is a single-file, zero-dependency alternative to python-requests Intended to be vendored in-tree by Linux systems software and other lightweight applications. Doesn’t support connection pooling (but neither does requests.get()). Uses much less memory Avoids supply chain attack vulnerabilities Consider my prod branch until PRs #2 and #3 are merged. Madison #6: Openverse No, not Metaverse! Previously “CC Search” Search engine for openly licensed media, for free and public use/remix of content. Currently images & audio, hope to include video, text, 3D models down the line. Start your search here Extras Michael: We now have playable times in the transcript section (example). Very cool tool for building regex-es I used for the above: regex101.com Next video is out: Do you even need loops in Python? A Python short by Michael Kennedy Remember, we have full-text search Brian: pip-secure-install - from Brett Cannon Python Testing with pytest is, when I last checked, the #2 bestseller at Pragmatic so cool My Maui trip was also a work trip. Gave me time to completely re-read the book, make notes, and make last minute changes. Changes went in this week and tonight is my “pencils down” date. This is getting real, folks. Thanks to everyone for buying beta copies and supporting the re-write. Madison: spd.watch - new police accountability/information tool for the Seattle area Shoutout to just (mentioned in Ep 242) ghcr.io - free docker image hosting for open source projects, easy integration with GitHub Actions Joke: via Josh Thurston How did the hacker get away from the police? He just ransomware. That joke makes me WannaCry… Where do you find a hacker? In decrypt.
#267 Python on the beach
Watch the live stream: Watch on YouTube About the show Sponsored by us: Check out the courses over at Talk Python And Brian’s book too! Michael #1: Box: Python dictionaries with advanced dot notation access Want to treat dictionaries like classes? Box. small_box = Box({'data': 2, 'count': 5}) small_box.data == \ small_box['data'] == \ getattr(small_box, 'data') == \ small_box.get('data') There are over a half dozen ways to customize your Box and make it work for you: Check out the new Box github wiki for more details and examples! Superset of dict See Types of Boxes as well Brian #2: Reading tracebacks in Python Trey Hunner “When Python encounters an error in your code, it will print out a traceback. Let's talk about how to use tracebacks to fix our code.” Brian’s commentary Tracebacks can feel like brick wall of error telling you “you suck”. But they are really meant to help you, and do, once you know how to read them. Probably should be one of the earliest things we teach people new to coding. Like maybe: hello world tracebacks testing Anyway, back to Trey Start at the bottom. Read the last line first That will have the type of exception and an error message The two lines above that are The exact filename and line number where the exception occurs a copy of the line Those two lines are a stack frame. Keep going up and it’s other stack frames for the callstack of how you got here. Trey walks through this with an example and shows how to solve an error at a high level stack frame using the traceback. Michael #3: Raspberry Pi: These two new devices just went live on the International Space Station The International Space Station has connected new Raspberry 4 Model B units to run experiments from 500 student programmer teams in Europe. From the education-focused European Astro Pi Challenge These are new space-hardened Raspberry Pi units, dubbed Astro Pi The AstroPi units are part of a project run by the European Space Agency (ESA) for the Earth-focused Mission Zero and Mission Space Lab. The former allows young Python programmers to take humidity readings on board ISS while the latter lets students run various scientific experiments on the space station using its sensors. Brian #4: Make Simple Mocks With SimpleNamespace Adam Johnson Who’s crushing it recently, BTW, lots of recent blog posts SimpleNamespace is in the types standard library package. Works great as a test double, especially as a stub or fake object. “It’s as simple as possible, with no faff around being callable, tracking usage, etc.” Example: >from types import SimpleNamespace >obj = SimpleNamespace(x=12, y=17, verbose=True) >obj namespace(x=12, y=17, verbose=True) >obj.x 12 >obj.verbose True unittest.mock.Mock also works, but has the annoying feature that, unless you pass in a spec, any attribute will be allowed. The SimpleNamespace solution doesn’t allow any typos or other attributes. Example: >obj.vrebose Traceback (most recent call last): File "[HTML_REMOVED]", line 1, in [HTML_REMOVED] AttributeError: 'types.SimpleNamespace' object has no attribute 'vrebose'. Did you mean: 'verbose'? Michael #5: Extra, extra, exta Marak Squires, supply chain issues (NPM), and terrorism? [npm issues] css outlines! python 3.10.2 Python Shorts YouTube series #1 Parsing data with Pydantic #2 Counting the number of times items appear with collections.Counter Stream Deck + PyCharm video, github repo Brian #6: 3 Things You Might Not Know About Numbers in Python David Amos Most understated phrase I’ve read in a long time: “… there's a good chance that you've used a number in one of your programs” There’s more to numbers than many people realize The 3 things numbers have methods integers have to_bytes(length=1, byteorder="big") int.from_bytes(b'\x06\xc1', byteorder="big") class method bit_length() and a bunch of others floats have is_integer(), as_integer_ratio() and a bunch more use variables or parentheses, though. 5.bit_length() doesn’t work n=5; n.bit_length() and (5).bit_length() works numbers have hierarchy Every number in Python is an instance of the Number class. so isinstance(value, Number) should work for any number type Then there’s 4 abstract types encompassing other types Complex: has type complex Real: has float Rational: has Fraction Integral: has int and bool Where’s Decimal? It’s not part of those abstract types, it directly inherits from Number Also, floats are weird Numbers are extensible You can derive from numeric classes, both abstract and concrete, and create your own However, to do this effectively, you gotta implement A LOT of dunder methods. Joke:
#266 Python has a glossary?
See the full show notes for this episode on the website at pythonbytes.fm/266.
#265 Get asizeof pympler and muppy
See the full show notes for this episode on the website at pythonbytes.fm/265.
#264 We're just playing games with Jupyter at this point
See the full show notes for this episode on the website at pythonbytes.fm/264.
#263 It’s time to stop using Python 3.6
See the full show notes for this episode on the website at pythonbytes.fm/263.
#262 So many bots up in your documentation
See the full show notes for this episode on the website at pythonbytes.fm/262.
#261 Please re-enable spacebar heating
See the full show notes for this episode on the website at pythonbytes.fm/261.
#260 It's brutally simple: made just from pickle and zip
See the full show notes for this episode on the website at pythonbytes.fm/260.
#259 That argument is a little late-bound
See the full show notes for this episode on the website at pythonbytes.fm/259.
#258 Python built us an anime dog!
See the full show notes for this episode on the website at pythonbytes.fm/258.
#257 Python Launcher - Launching Python Everywhere
See the full show notes for this episode on the website at pythonbytes.fm/257.