Himalaya: Listen. Learn. Grow.

4.8K Ratings
Open In App
title

Python Bytes

Michael Kennedy and Brian Okken

96
Followers
468
Plays
Python Bytes

Python Bytes

Michael Kennedy and Brian Okken

96
Followers
468
Plays
OVERVIEWEPISODESYOU MAY ALSO LIKE

Details

About Us

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.

Latest Episodes

Big news for a very small Python runtime

Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest Michael #1: micropython updated via Matt Trentini v1.13 is packed with features and bugfixes including solid asyncio support and tasty BLE improvements. Heck, we've even got the walrus operator. a new implementation of the uasyncio module which aims to be more compatible with CPython's asyncio module. The main change is to use a Task object for each coroutine, allowing more flexibility to queue tasks in various places, eg the main run loop, tasks waiting on events, locks or other tasks. It no longer requires pre-allocating a fixed queue size for the main run loop. Most code in this repository is now auto-formatted using uncrustify for C code and Black for Python code. BlueKitchen BTstack bindings have been added for the ubluetooth module, as an optional alternative to the NimBLE stack. The unix port can now be built with BLE support using these bindings Other Bluetooth additions include: new events for service/characteristic/ descriptor discovery complete; new events for read done and indicate acknowledgement; and support for active scanning in BLE.gap_scan(). PEP 526 has been (Walrus) There has been an important bug fix when importing ARM machine code from an .mpy file: the system now correctly tracks the executable memory allocated to the machine code so this memory is not reclaimed by the garbage collector. For testing, a multi-instance test runner has been added (see tests/run-multitests.py) which allows running a synchronised test across two or more MicroPython targets. There are breaking changes First release since Dec 19, 2019 Brian #2: respx: A utility for mocking out the Python HTTPX library When using requests, you can mock it with responses. When using httpx, mock with respx. Quick start: import httpx import respx @respx.mock def test_something(): request = respx.post("https://foo.bar/baz/", status_code=201) response = httpx.post("https://foo.bar/baz/") assert request.called assert response.status_code == 201 Documentation includes examples of using respx with both pytest and unittest, including how to set up mocked_api fixtures for pytest. There’s call statistics you can assert on. Ability to raise exceptions, return non-200 status codes, set custom return content. Content can be generated in a callback method. JSON content can be returned Tons of nice options to help test your httpx based application. Michael #3: GetPy - A Vectorized Python Dict/Set The goal of GetPy is to provide the highest performance python dict/set that integrates into the python scientific ecosystem. GetPy is a thin binding to the Parallel Hashmap (https://github.com/greg7mdp/parallel-hashmap.git) which is the current state of the art unordered map/set with minimal memory overhead and fast runtime speed. The binding layer is supported by PyBind11 (https://github.com/pybind/pybind11.git) The gp.Dict and gp.Set objects are designed to maintain a similar interface to the corresponding standard python objects. Simple example: - import getpy as gp key_type = np.dtype('u8') value_type = np.dtype('u8') keys = np.random.randint(1, 1000, size=10**2, dtype=key_type) values = np.random.randint(1, 1000, size=10**2, dtype=value_type) gp_dict = gp.Dict(key_type, value_type) gp_dict[keys] = values Brian #4: isort and black now play nice together easily Contributed by John Hagen isort “sorts your imports, so you don’t have to” black reformats all of your code to a consistent code style, including import statements There is a config page on black documentation that shows how to set isort to be compatible with black. It also shows how to make flake8 and pylint play nice with black, but they are less complicated. Now, however, with isort 5 introduction of built in profiles, you can just use isort --``profile black . and the profile sets everything for you. There’s a profile page for isort that describes all that it does. Other profiles include: d

29 min4 d ago
Comments
Big news for a very small Python runtime

There's a beaver in your database and Anna-Lena drops by

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Special guest: Anna-Lena Popkes Brian #1: Easily create Python scripts using argparse Back in the day, when I was writing most of my utility scripts in bash, I’d keep around an example.bash file with different types of arguments and flags and control structures, etc to use as a template for new scripts. Python has the same problem, or worse, if you use the built in argparse instead of something like click or typer. However, there are many times where you don’t want to have any external dependencies on a script, so built in argparse it is. But I definitely relate to this tweet: “Every time I write a python script, I have to go back to an old script of mine to remember how to set up argparse. For some reason it just does not stick in my mind AT ALL.” - Joshua Schraiber Well, then steps in Ken Youens-Clark with a little utility called new.py. It’s not pip install-able, so you gotta c...

34 min1 w ago
Comments
There's a beaver in your database and Anna-Lena drops by

Structured concurrency in Python

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Michael #1: Structured concurrency in Python with AnyIO AnyIO is a Python library providing structured concurrency primitives on top of asyncio. Structured concurrency is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by using a structured approach to concurrent programming. The core concept is the encapsulation of concurrent threads of execution (here encompassing kernel and userland threads and processes) by way of control flow constructs that have clear entry and exit points and that ensure all spawned threads have completed before exit. — Wikipedia The best overview is Notes on structured concurrency by Nathaniel Smith (or his video if you prefer). Python has three well-known concurrency libraries built around the async/await syntax: asyncio, Curio, and Trio. (WHERE IS unsync?!?! ) Since it's the default, the overwhelming...

36 min2 w ago
Comments
Structured concurrency in Python

Version your SQL schemas with git + automatically migrate them

Sponsored by Datadog: pythonbytes.fm/datadog Brian #1: Surviving Django (if you care about databases) Daniele Varazzo Hard to summarize, but this is an interesting perspective on getting to know your database better and using database migrations and database schemas, etc. instead of relying on Django’s seemingly agnostic view of databases. Following the article is a nice civilized discussion in the comments between the author, Paolo Melchiorre, Andrew Godwin, and others. Interesting comment by Andrew: “I agree that at some point in a project/company's life, if it's big enough, SQL migrations are the way to go. … Migrations in the out-of-the-box state are mostly there to supplement rapid prototyping, and then like a lot of Django, can be removed/ignored progressively if and when you outgrow the single set of design constraints we had to choose for them.” Michael #2: Python Numbers and the Flyweight design pattern Working on allocation and other memory internals from my upcoming P...

31 min3 w ago
Comments
Version your SQL schemas with git + automatically migrate them

Runtime type checking for Python type hints

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Michael #1: watchdog via Prayson Daniel Python API and shell utilities to monitor file system events. Example: observer = Observer() observer.schedule(event_handler, path, recursive=True) observer.start() Watchdog comes with an optional utility script called watchmedo try $ watchmedo log and see what happens in that folder. Why Watchdog? Compared to other similar libs Brian #2: Status code 418 Thanks Andy Howe for the suggestion Python 3.9 rc1 is out. One nice enhancement that has made it into 3.9, a fix for http library missing HTTP status code 418 “I’m a teapot”. https://bugs.python.org/issue39507 Title: http library missing HTTP status code 418 "I'm a teapot" See also status code 418 is also supported by HTCPCP, Hyper Text Coffee Pot Control Protocol, https://tools.ietf.org/html/rfc2324 418 I'm a teapot Any attempt to brew coffee with a teapot should result in the error code "418...

33 minAUG 18
Comments
Runtime type checking for Python type hints

Events and callbacks in the Python language!

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Brian #1: An introduction to mutation testing in Python Moshe Zadka This article uses mutmut, but there are other mutation testing packages. The example shows 3 methods, and one test case that actually hits 100% code coverage. The mutmut is used and finds 16 surviving mutants. “Mutation testing algorithmically modifies source code and checks if any "mutants" survived each test. Any mutant that survives the unit test is a problem: it means that a modification to the code, likely introducing a bug, was not caught by the standard test suite.” “For each mutation test, mutmut modified portions of your source code that simulates potential bugs. An example of a modification is changing a > comparison to >= to see what happens. If there is no unit test for this boundary condition, this mutation will "survive": this is a potential bug that none of the tests will detect.” Cool example of how...

28 minAUG 10
Comments
Events and callbacks in the Python language!

Break out the Django testing toolbox

Sponsored by us! Support our work through: Our courses at Talk Python Training Brian’s pytest book Brian #1: Start using pip install --use-feature=2020-resolver if you aren’t already Mathew Feickert You may see something interesting when you run pip This is not a problem. Do not adjust your sets. But, you should be aware of it. Especially if you install from requirements generated with pip freeze, you’ll want to use --use-feature=2020-resolver everywhere: $ python -m pip install --use-feature=2020-resolver -r requirements_original.txt $ python -m pip freeze > requirements_lock.txt $ python -m pip install --use-feature=2020-resolver -r requirements_lock.txt Otherwise, you may run into issues see Example of --use-feature=2020-resolver breaking a pip freeze requirements.txt and Changes to the pip dependency resolver in 20.2 (2020) Michael #2: Profiling Python import statements Conversation with Brandon Braner lead to import-profiler A basic python import profiler to find bottlenecks...

34 minAUG 6
Comments
Break out the Django testing toolbox

Calculations by hand, but in the compter, with Handcalcs

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Brian #1: Building a self-updating profile README for GitHub Simon Willison, co-createor of Django “GitHub quietly released a new feature at some point in the past few days: profile READMEs. Create a repository with the same name as your GitHub account (in my case that’s github.com/simonw/simonw), add a README.md to it and GitHub will render the contents at the top of your personal profile page—for me that’s github.com/simonw” Simon takes it one further, and uses GitHub actions to keep the README up to date. Uses Python to: Grab recent releases from certain GH repos using GH GraphQL API Links to blog entries using feedparser Retrieve latest links using SQL queries Michael #2: Handcalcs Created by Connor Ferster In design engineering, you need to do lots of calculations and have those calculation sheets be kept as legal records as part of the project's design history. If they are n...

30 minAUG 2
Comments
Calculations by hand, but in the compter, with Handcalcs

Live from the Manning Python Conference

Special guest: Ines Montani Michael #1: VS Code Device Simulator Want to experiment with MicroPython? Teaching a course with little IoT devices? Circuit Playground Express BBC micro:bit Adafruit CLUE with a screen Get a free VS code extension that adds a high fidelity simulator Easily create the starter code (main.py) Interact with all the sensors (buttons, motion sensors, acceleration detection, device shake detection, etc.) Deploy and debug on a real device when ready Had the team over on Talk Python. Brian #2: pytest 6.0.0rc1 New features You can put configuration in pyproject.toml Inline type annotations. Most user facing API and internal code. New flags - --no-header - --no-summary - --strict-config : error on unknown config key - --code-highlight : turn on/off code highlighting in terminal Recursive comparison for dataclass and attrs Tons of fixes Improved documentation There’s a list of breaking changes and deprications. But really, nothing in the list seems like a big deal ...

52 minJUL 22
Comments
Live from the Manning Python Conference

You will now be notified if the Python zipper is broken

Our courses at Talk Python Training Brian’s pytest book Brian #1: Python async frameworks - Beyond developer tribalism Tom Christie Written on encode.io. encode also encompasses several awesome projects: Django REST framework HTTPX async projects: starlette, uvicorn, orm, databases, broadcaster Partly a reaction to “Async Python is not faster” Tom would like to see the Python community move beyond polarizing discussions. “… we could probably benefit from a bit more recognition of where there is shared ground. And in areas where there’s less clarity, to be able to have constructive conversations around the relative merits in differing approaches.” Some points about performance You probably shouldn’t care about performance when you start a project. Success of a project is more related to development experience and strength of the surrounding ecosystem. We should care enough about performance that people don’t dismiss Python due to performance issues. Be careful about the word...

43 minJUL 16
Comments
You will now be notified if the Python zipper is broken

Latest Episodes

Big news for a very small Python runtime

Sponsored by us! Support our work through: Our courses at Talk Python Training Python Testing with pytest Michael #1: micropython updated via Matt Trentini v1.13 is packed with features and bugfixes including solid asyncio support and tasty BLE improvements. Heck, we've even got the walrus operator. a new implementation of the uasyncio module which aims to be more compatible with CPython's asyncio module. The main change is to use a Task object for each coroutine, allowing more flexibility to queue tasks in various places, eg the main run loop, tasks waiting on events, locks or other tasks. It no longer requires pre-allocating a fixed queue size for the main run loop. Most code in this repository is now auto-formatted using uncrustify for C code and Black for Python code. BlueKitchen BTstack bindings have been added for the ubluetooth module, as an optional alternative to the NimBLE stack. The unix port can now be built with BLE support using these bindings Other Bluetooth additions include: new events for service/characteristic/ descriptor discovery complete; new events for read done and indicate acknowledgement; and support for active scanning in BLE.gap_scan(). PEP 526 has been (Walrus) There has been an important bug fix when importing ARM machine code from an .mpy file: the system now correctly tracks the executable memory allocated to the machine code so this memory is not reclaimed by the garbage collector. For testing, a multi-instance test runner has been added (see tests/run-multitests.py) which allows running a synchronised test across two or more MicroPython targets. There are breaking changes First release since Dec 19, 2019 Brian #2: respx: A utility for mocking out the Python HTTPX library When using requests, you can mock it with responses. When using httpx, mock with respx. Quick start: import httpx import respx @respx.mock def test_something(): request = respx.post("https://foo.bar/baz/", status_code=201) response = httpx.post("https://foo.bar/baz/") assert request.called assert response.status_code == 201 Documentation includes examples of using respx with both pytest and unittest, including how to set up mocked_api fixtures for pytest. There’s call statistics you can assert on. Ability to raise exceptions, return non-200 status codes, set custom return content. Content can be generated in a callback method. JSON content can be returned Tons of nice options to help test your httpx based application. Michael #3: GetPy - A Vectorized Python Dict/Set The goal of GetPy is to provide the highest performance python dict/set that integrates into the python scientific ecosystem. GetPy is a thin binding to the Parallel Hashmap (https://github.com/greg7mdp/parallel-hashmap.git) which is the current state of the art unordered map/set with minimal memory overhead and fast runtime speed. The binding layer is supported by PyBind11 (https://github.com/pybind/pybind11.git) The gp.Dict and gp.Set objects are designed to maintain a similar interface to the corresponding standard python objects. Simple example: - import getpy as gp key_type = np.dtype('u8') value_type = np.dtype('u8') keys = np.random.randint(1, 1000, size=10**2, dtype=key_type) values = np.random.randint(1, 1000, size=10**2, dtype=value_type) gp_dict = gp.Dict(key_type, value_type) gp_dict[keys] = values Brian #4: isort and black now play nice together easily Contributed by John Hagen isort “sorts your imports, so you don’t have to” black reformats all of your code to a consistent code style, including import statements There is a config page on black documentation that shows how to set isort to be compatible with black. It also shows how to make flake8 and pylint play nice with black, but they are less complicated. Now, however, with isort 5 introduction of built in profiles, you can just use isort --``profile black . and the profile sets everything for you. There’s a profile page for isort that describes all that it does. Other profiles include: d

29 min4 d ago
Comments
Big news for a very small Python runtime

There's a beaver in your database and Anna-Lena drops by

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Special guest: Anna-Lena Popkes Brian #1: Easily create Python scripts using argparse Back in the day, when I was writing most of my utility scripts in bash, I’d keep around an example.bash file with different types of arguments and flags and control structures, etc to use as a template for new scripts. Python has the same problem, or worse, if you use the built in argparse instead of something like click or typer. However, there are many times where you don’t want to have any external dependencies on a script, so built in argparse it is. But I definitely relate to this tweet: “Every time I write a python script, I have to go back to an old script of mine to remember how to set up argparse. For some reason it just does not stick in my mind AT ALL.” - Joshua Schraiber Well, then steps in Ken Youens-Clark with a little utility called new.py. It’s not pip install-able, so you gotta c...

34 min1 w ago
Comments
There's a beaver in your database and Anna-Lena drops by

Structured concurrency in Python

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Michael #1: Structured concurrency in Python with AnyIO AnyIO is a Python library providing structured concurrency primitives on top of asyncio. Structured concurrency is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by using a structured approach to concurrent programming. The core concept is the encapsulation of concurrent threads of execution (here encompassing kernel and userland threads and processes) by way of control flow constructs that have clear entry and exit points and that ensure all spawned threads have completed before exit. — Wikipedia The best overview is Notes on structured concurrency by Nathaniel Smith (or his video if you prefer). Python has three well-known concurrency libraries built around the async/await syntax: asyncio, Curio, and Trio. (WHERE IS unsync?!?! ) Since it's the default, the overwhelming...

36 min2 w ago
Comments
Structured concurrency in Python

Version your SQL schemas with git + automatically migrate them

Sponsored by Datadog: pythonbytes.fm/datadog Brian #1: Surviving Django (if you care about databases) Daniele Varazzo Hard to summarize, but this is an interesting perspective on getting to know your database better and using database migrations and database schemas, etc. instead of relying on Django’s seemingly agnostic view of databases. Following the article is a nice civilized discussion in the comments between the author, Paolo Melchiorre, Andrew Godwin, and others. Interesting comment by Andrew: “I agree that at some point in a project/company's life, if it's big enough, SQL migrations are the way to go. … Migrations in the out-of-the-box state are mostly there to supplement rapid prototyping, and then like a lot of Django, can be removed/ignored progressively if and when you outgrow the single set of design constraints we had to choose for them.” Michael #2: Python Numbers and the Flyweight design pattern Working on allocation and other memory internals from my upcoming P...

31 min3 w ago
Comments
Version your SQL schemas with git + automatically migrate them

Runtime type checking for Python type hints

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Michael #1: watchdog via Prayson Daniel Python API and shell utilities to monitor file system events. Example: observer = Observer() observer.schedule(event_handler, path, recursive=True) observer.start() Watchdog comes with an optional utility script called watchmedo try $ watchmedo log and see what happens in that folder. Why Watchdog? Compared to other similar libs Brian #2: Status code 418 Thanks Andy Howe for the suggestion Python 3.9 rc1 is out. One nice enhancement that has made it into 3.9, a fix for http library missing HTTP status code 418 “I’m a teapot”. https://bugs.python.org/issue39507 Title: http library missing HTTP status code 418 "I'm a teapot" See also status code 418 is also supported by HTCPCP, Hyper Text Coffee Pot Control Protocol, https://tools.ietf.org/html/rfc2324 418 I'm a teapot Any attempt to brew coffee with a teapot should result in the error code "418...

33 minAUG 18
Comments
Runtime type checking for Python type hints

Events and callbacks in the Python language!

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Brian #1: An introduction to mutation testing in Python Moshe Zadka This article uses mutmut, but there are other mutation testing packages. The example shows 3 methods, and one test case that actually hits 100% code coverage. The mutmut is used and finds 16 surviving mutants. “Mutation testing algorithmically modifies source code and checks if any "mutants" survived each test. Any mutant that survives the unit test is a problem: it means that a modification to the code, likely introducing a bug, was not caught by the standard test suite.” “For each mutation test, mutmut modified portions of your source code that simulates potential bugs. An example of a modification is changing a > comparison to >= to see what happens. If there is no unit test for this boundary condition, this mutation will "survive": this is a potential bug that none of the tests will detect.” Cool example of how...

28 minAUG 10
Comments
Events and callbacks in the Python language!

Break out the Django testing toolbox

Sponsored by us! Support our work through: Our courses at Talk Python Training Brian’s pytest book Brian #1: Start using pip install --use-feature=2020-resolver if you aren’t already Mathew Feickert You may see something interesting when you run pip This is not a problem. Do not adjust your sets. But, you should be aware of it. Especially if you install from requirements generated with pip freeze, you’ll want to use --use-feature=2020-resolver everywhere: $ python -m pip install --use-feature=2020-resolver -r requirements_original.txt $ python -m pip freeze > requirements_lock.txt $ python -m pip install --use-feature=2020-resolver -r requirements_lock.txt Otherwise, you may run into issues see Example of --use-feature=2020-resolver breaking a pip freeze requirements.txt and Changes to the pip dependency resolver in 20.2 (2020) Michael #2: Profiling Python import statements Conversation with Brandon Braner lead to import-profiler A basic python import profiler to find bottlenecks...

34 minAUG 6
Comments
Break out the Django testing toolbox

Calculations by hand, but in the compter, with Handcalcs

Sponsored by us! Support our work through: Our courses at Talk Python Training Test & Code Podcast Brian #1: Building a self-updating profile README for GitHub Simon Willison, co-createor of Django “GitHub quietly released a new feature at some point in the past few days: profile READMEs. Create a repository with the same name as your GitHub account (in my case that’s github.com/simonw/simonw), add a README.md to it and GitHub will render the contents at the top of your personal profile page—for me that’s github.com/simonw” Simon takes it one further, and uses GitHub actions to keep the README up to date. Uses Python to: Grab recent releases from certain GH repos using GH GraphQL API Links to blog entries using feedparser Retrieve latest links using SQL queries Michael #2: Handcalcs Created by Connor Ferster In design engineering, you need to do lots of calculations and have those calculation sheets be kept as legal records as part of the project's design history. If they are n...

30 minAUG 2
Comments
Calculations by hand, but in the compter, with Handcalcs

Live from the Manning Python Conference

Special guest: Ines Montani Michael #1: VS Code Device Simulator Want to experiment with MicroPython? Teaching a course with little IoT devices? Circuit Playground Express BBC micro:bit Adafruit CLUE with a screen Get a free VS code extension that adds a high fidelity simulator Easily create the starter code (main.py) Interact with all the sensors (buttons, motion sensors, acceleration detection, device shake detection, etc.) Deploy and debug on a real device when ready Had the team over on Talk Python. Brian #2: pytest 6.0.0rc1 New features You can put configuration in pyproject.toml Inline type annotations. Most user facing API and internal code. New flags - --no-header - --no-summary - --strict-config : error on unknown config key - --code-highlight : turn on/off code highlighting in terminal Recursive comparison for dataclass and attrs Tons of fixes Improved documentation There’s a list of breaking changes and deprications. But really, nothing in the list seems like a big deal ...

52 minJUL 22
Comments
Live from the Manning Python Conference

You will now be notified if the Python zipper is broken

Our courses at Talk Python Training Brian’s pytest book Brian #1: Python async frameworks - Beyond developer tribalism Tom Christie Written on encode.io. encode also encompasses several awesome projects: Django REST framework HTTPX async projects: starlette, uvicorn, orm, databases, broadcaster Partly a reaction to “Async Python is not faster” Tom would like to see the Python community move beyond polarizing discussions. “… we could probably benefit from a bit more recognition of where there is shared ground. And in areas where there’s less clarity, to be able to have constructive conversations around the relative merits in differing approaches.” Some points about performance You probably shouldn’t care about performance when you start a project. Success of a project is more related to development experience and strength of the surrounding ecosystem. We should care enough about performance that people don’t dismiss Python due to performance issues. Be careful about the word...

43 minJUL 16
Comments
You will now be notified if the Python zipper is broken
success toast
Welcome to Himalaya LearningDozens of podcourses featuring over 100 experts are waiting for you.