Michael Driscoll's Blog, page 9

September 4, 2023

PyDev of the Week: Franek Magiera

This week we welcome Franek Magiera as our PyDev of the Week! Franek is a core developer of the Python programming language.

If you’d like to see what else Franek has been working on, you can check out Franek’s GitHub profile. Now let’s spend a few moments getting to know Franeky better!

Can you tell us a little about yourself (hobbies, education, etc):

I am interested in a lot of different things – playing the guitar, chess, science, computers, mountain hiking and sports. I used to be a competitive powerlifter, but now I am more into climbing and endurance sports – running and road cycling especially.

I got my bachelor’s in Automatic Control and Robotics and my master’s in Computer Science. My engineering and master’s theses are about applications of genetic programming, which was quite interesting to me when I was a student – I even co-authored a paper on genetic programming applications in dimensionality reduction. For a while I was considering a career in research, but ended up as a Java software developer.

Why did you start using Python?

When I was a student, most of my courses featured MATLAB. It is a very powerful tool and I liked working with it, but I didn’t like that when my student license would end, I wouldn’t be able to use it for my personal projects. I was also worried that there weren’t many job offers that required MATLAB knowledge.

I had heard that some of the older students were using Python and that it was quite similar to MATLAB, but it was open source and there were quite a few job offers that listed Python knowledge as one of the requirements. Also I had heard that a lot of people use it for machine learning, which I was interested in at the time. So that’s when I decided to learn Python and picked it up for one of my university projects.

What other programming languages do you know and which is your favorite?

I’ve played around with quite a lot of different programming languages. In high school I was using Pascal. In university, I was coding in C, C++ and MATLAB. Then, I’ve learnt Python and I’ve been heavily relying on it for my personal projects ever since.

I have also spent some time programming in Scala for a couple of MOOCs and in Scheme when going through SICP. I went through the Tour of Go on two separate occasions, but have never used the language for anything else.

I’ve used JavaScript and TypeScript during my internships and now at work I’m using Java exclusively. Recently, I’ve become interested in and started learning Rust.

That’s quite a range of different programming languages, but I think nowadays I’m somewhat productive only in Python and Java, since those are the two I use most often.

As for my favorite – it’s really hard to decide, but I think that’s Python. It’s the one I feel most comfortable with and the community around it is great. For what it’s worth, I’ve also had a lot of fun programming in Rust, Scala, TypeScript, Scheme and C.

What projects are you working on now?

Unfortunately, I haven’t been doing much programming and OSS development in my free time lately. Whenever I find the time and motivation to do that, I am trying to finish certain aspects of PEP 692. I also try to contribute to urllib3 from time to time, but it’s been a while since I’ve done that.

I’ve mentioned earlier that I started learning Rust – I’m spending some of my free time on writing a LISP interpreter in Rust as a way to learn the language.

I have a couple of other ideas for side projects, but it’s been hard for me to get round to actually work on them. The vast majority of my programming time is devoted to the stuff I do at work.

Which Python libraries are your favorite (core or 3rd party)?

I love numpy, pandas, matplotlib and seaborn combo for data analysis. I also liked working with DEAP when doing my research at university. As for core – typing module is my favorite.

How did you get into doing core Python development?

I just wanted to start by saying I haven’t done a lot of core Python development apart from the very small changes related to PEP 692. Anyway, here’s how I got there.

After one of my internships I got a job offer, but wanted to get my master’s degree before starting full time employment. That meant I had still one more year as a student that I wanted to enjoy before starting work full time. Then, everything got locked down due to the pandemic, which meant I had a lot of free time that I had to spend at home. Almost all of my friends were already working in industry and I was feeling like they are learning much more than I was. At the same time, no one wanted to hire me knowing that I’d leave for another job in a year. So, I decided I’d start contributing to open source projects to gain some experience and learn new things.

I started going through GitHub looking for interesting projects. That’s how I found urllib3. I’ve done a few simple PRs that got merged. Then I started working on adding type hints to the codebase. It was then when I learnt that there is no way to precisely type hint functions that use `**kwargs` – an annotation on `**kwargs` would mean that all of the keyword arguments are of that type, which in real life is rarely the case. I’ve seen an issue regarding that on mypy’s GitHub page that seemed to gain a lot of interest and has been opened for quite some time and I thought – why don’t I try fixing that?

The problem was, I knew nothing about interpreters, compilers or type checkers – it was not part of an Automatic Control and Robotics curriculum and my master’s in Computer Science was focused on data analysis. So I started reading Crafting Interpreters by Bob Nystrom to learn more about all that stuff. After that, I more or less understood how mypy was supposed to work and I could go through the codebase and understand what certain parts were responsible for. I’ve created a simple PR that probably got a lot of stuff wrong, but it worked for the cases I was interested in. I got a response from the maintainers, that the best way to move with this feature forward would be to propose a PEP. This was around the time I started full time employment, so my free time became more limited, but I still wanted to continue working on that.

I created a topic about the problem on Python’s dev mailing list. I got invited to a typing meetup where I proposed an approach to solve that problem and mostly got positive feedback. After that, I started working on the PEP, which with my chaotic approach took me around half a year to write. Then, there was a review process by the community and the Steering Council. In the end, the PEP got accepted and that’s how I ended up doing the small changes in cpython codebase.

What is your favorite obscure Python library and why?

It’s pygraphviz because it made drawing really nice graphs easy when I needed them.

Is there anything else you’d like to say?

I just wanted to say thanks for letting me be part of the series. Python’s community is very welcoming and supportive. I probably wouldn’t have gotten as far in my open source journey if it wasn’t for the help from all the people I’ve met on my path and I’m really grateful for that.

Thanks for doing the interview, Franek!

The post PyDev of the Week: Franek Magiera appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on September 04, 2023 05:28

August 30, 2023

Textual Apps Coming to a Website Near You

Textual is an amazing Python package for creating Text-Based User Interfaces (TUIs) in Python. You can learn more in An Intro to Textual – Creating Text User Interfaces with Python.

However, Textual isn’t only about creating user interfaces for your terminal. The Textual team is also making Textual for the web! Textual Cloud Service will allow developers to run their terminal GUIs in web applications.

When creating a Textual-based web application, you will use a Textual Agent. These agents can be configured to serve single or multiple textual apps using a TCP/IP connection to a cloud service that supports the Websocket protocol.

According to the Textual Cloud Service documentation, the benefits of using their service are as follows:

Works over proxies – The websocket protocol is designed to cooperate with network infrastructure such as proxies.Bypasses firewalls – Firewalls are generally configured to allow outgoing TCP/IP connections.Encrypted – Connections are encrypted with industry standards.Compressed – Data is compressed on the fly.

Keep an eye on the Textual product so you know when this new feature goes live!

Related ReadingPython Based Textual Apps Are Coming to the Web – InfoWorld.An Intro to Textual – Creating Text User Interfaces with Python

 

The post Textual Apps Coming to a Website Near You appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 30, 2023 10:27

An Intro to Protocol Buffers with Python

Protocol buffers are a data serialization format that is language agnostic. They are analogous to Python’s own pickle format, but one of the advantages of protocol buffers is that they can be used by multiple programming languages.

For example, Protocol buffers are supported in C++, C#, Dart, Go, Java, Kotlin, Objective-C, PHP, Ruby, and more in addition to Python. The biggest con for Protocol buffers is that far too often, the versions have changes that are not backward compatible.

In this article, you will learn how to do the following:

Creating a Protocol formatCompiling Your Protocol Buffers FileWriting MessagesReading Messages

Let’s get started!

Creating a Protocol Format

You’ll need your own file to create your application using protocol buffers. For this project, you will create a way to store music albums using the Protocol Buffer format.

Create a new file named music.proto and enter the following into the file:

syntax = "proto2";

package music;

message Music {
optional string artist_name = 1;
optional string album = 2;
optional int32 year = 3;
optional string genre = 4;

}

message Library {
repeated Music albums = 1;
}

The first line in this code is your package syntax, “proto2”. Next is your package declaration, which is used to prevent name collisions.

The rest of the code is made up of message definitions. These are groups of typed fields. There are quite a few differing types that you may use,  including bool, int32, float, double, and string.

You can set the fields to optional, repeated, or required. According to the documentation, you rarely want to use required because there’s no way to unset that. In fact, in proto3, required is no longer supported.

Compiling Your Protocol Buffers File

To be able to use your Protocol Buffer in Python, you will need to compile it using a program called protoc. You can get it here. Be sure to follow the instructions in the README file to get it installed successfully.

Now run protoc against your proto file, like this:

protoc --python_out=. .\music.proto --proto_path=.

The command above will convert your proto file to Python code in your current working directory. This new file is named music_pb2.py.

Here are the contents of that file:

# -*- coding: utf-8 -*-
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: music.proto
"""Generated protocol buffer code."""
from google.protobuf import descriptor as _descriptor
from google.protobuf import descriptor_pool as _descriptor_pool
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import builder as _builder
# @@protoc_insertion_point(imports)

_sym_db = _symbol_database.Default()




DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0bmusic.proto\x12\x05music\"H\n\x05Music\x12\x13\n\x0b\x61rtist_name\x18\x01 \x01(\t\x12\r\n\x05\x61lbum\x18\x02 \x01(\t\x12\x0c\n\x04year\x18\x03 \x01(\x05\x12\r\n\x05genre\x18\x04 \x01(\t\"\'\n\x07Library\x12\x1c\n\x06\x61lbums\x18\x01 \x03(\x0b\x32\x0c.music.Music')

_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'music_pb2', _globals)
if _descriptor._USE_C_DESCRIPTORS == False:
DESCRIPTOR._options = None
_globals['_MUSIC']._serialized_start=22
_globals['_MUSIC']._serialized_end=94
_globals['_LIBRARY']._serialized_start=96
_globals['_LIBRARY']._serialized_end=135
# @@protoc_insertion_point(module_scope)

There’s a lot of magic here that uses descriptors to generate classes for you. Don’t worry about how it works; the documentation doesn’t explain it well either.

Now that your Protocol Buffer is transformed into Python code, you can start serializing data!

Writing Messages

To start serializing your data with Protocol Buffers, you must create a new Python file.

Name your file music_writer.py and enter the following code:

from pathlib import Path
import music_pb2


def overwrite(path):
write_or_append = "a"
while True:
answer = input(f"Do you want to overwrite '{path}' (Y/N) ?").lower()
if answer not in "yn":
print("Y or N are the only valid answers")
continue

write_or_append = "w" if answer == "y" else "a"
break
return write_or_append


def music_data(path):
p = Path(path)
write_or_append = "w"
if p.exists():
write_or_append = overwrite(path)

library = music_pb2.Library()
new_music = library.albums.add()

while True:
print("Let's add some music!\n")
new_music.artist_name = input("What is the artist name? ")
new_music.album = input("What is the name of the album? ")
new_music.year = int(input("Which year did the album come out? "))

more = input("Do you want to add more music? (Y/N)").lower()
if more == "n":
break

with open(p, f"{write_or_append}b") as f:
f.write(library.SerializeToString())

print(f"Music library written to {p.resolve()}")


if __name__ == "__main__":
music_data("music.pro")

The meat of this program is in your music_data() function. Here you check if the user wants to overwrite their music file or append to it. Then, you create a Library object and prompt the user for the data they want to serialize.

For this example, you ask the user to enter an artist’s name, album, and year. You omit the genre for now, but you can add that yourself if you’d like to.

After they enter the year of the album, you ask the user if they would like to add another album. The application will write the data to disk and end if they don’t want to continue adding music.

Here is an example writing session:

Let's add some music!

What is the artist name? Zahna
What is the name of the album? Stronger Than Death
Which year did the album come out? 2023
Do you want to add more music? (Y/N)Y
Let's add some music!

What is the artist name? KB
What is the name of the album? His Glory Alone II
Which year did the album come out? 2023
Do you want to add more music? (Y/N)N

Now, let’s learn how to read your data!

Reading Messages

Now that you have your Protocol Buffer Messages written to disk, you need a way to read them.

Create a new file named music_reader.py and enter the following code:

from pathlib import Path
import music_pb2


def list_music(music):
for album in music.albums:
print(f"Artist: {album.artist_name}")
print(f"Album: {album.album}")
print(f"Year: {album.year}")
print()


def main(path):
p = Path(path)
library = music_pb2.Library()

with open(p.resolve(), "rb") as f:
library.ParseFromString(f.read())

list_music(library)


if __name__ == "__main__":
main("music.pro")

This code is a little simpler than the writing code was. Once again, you create an instance of the Library class. This time, you loop over the library albums and print out all the data in the file.

If you had added the music in this tutorial to your Protocol Buffers file, when you run your reader, the output would look like this:

Artist: Zahna
Album: Stronger Than Death
Year: 2023

Artist: KB
Album: His Glory Alone II
Year: 2023

Give it a try with your custom music file!

Wrapping Up

Now you know the basics of working with Protocol Buffers using Python. Specifically, you learned about the following:

Creating a Protocol formatCompiling Your Protocol Buffers FileWriting MessagesReading Messages

Now is your chance to consider using this type of data serialization in your application. Once you have a plan, give it a try! Protocol buffers are a great way to create data in a programming language-agnostic way.

Further ReadingProtocol Buffer Basics: Python | Protocol Buffers Documentation (protobuf.dev)

The post An Intro to Protocol Buffers with Python appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 30, 2023 05:19

August 23, 2023

Python in Excel Announcement!

Microsoft announced that Python is now a part of Excel! Guido van Rossum mentioned on Twitter that he helped the Excel team add Python to the popular spreadsheet application.

You can get Python in Excel if you have the ability to access Public Preview versions of Office.

This new feature allows you to write Python directly in a cell. For some reason, the Python code will run in Microsoft Cloud rather than locally, so an internet connection is required for this to work. When the cloud is done running, it will return the results, including your plots or other visualizations.

Python in Excel is using the Anaconda distribution of Python rather than the regular Python from Python.org. What that means is that you have many popular scientific packages included automatically, such as pandas, Matplotlib, scikit-learn, etc.

You can learn more by checking out Microsoft’s announcement or visiting Anaconda’s page on the topic.

The post Python in Excel Announcement! appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 23, 2023 06:11

August 22, 2023

Python 101 – Expanding Paths and Variables

Working with file and folder paths in Python can take time and effort. Fortunately, the Python programming language has a couple of great packages to help you!

This tutorial will teach you how to expand an initial path component, such as a tilde (~). You will also learn how to expand/replace environment variables such as $USERNAME or $TEMPDIR.

You will learn how to do this using the following modules (if applicable):

os.pathpathlib

Let’s get started!

 

Expanding the User with os.path

You’ll need to write three simple lines of code to get started.

Take a look:

>>> import os
>>> os.path.expanduser ("~/test.log")
'/Users/mike/test.log'

Here you take a path that beings with a tilde and expand it using os.path.expanduser().

Expanding the User with pathlib

Now let’s find out how to use pathlib to expand the user instead of os.path!

Here’s the code you’ll need:

>>> from pathlib import Path
>>> p = Path("~/test.log")
>>> p.expanduser()
PosixPath('/Users/mike/test.log')

The primary difference here is that you are creating a Path() object. Then after you create that object, you can call the expanduser() method to do the magic!

The pathlib module has lots of other great methods. For example, if all you want is the current user’s home folder, you can call the home() method, like this:

>>> p.home()
PosixPath('/Users/mike')

Now you’re ready to move on and learn how to expand environment variables!

Expanding Environment Variables with os.path

Each operating system will have its environment variables that you can use. You may want to check what’s available by accessing os.environ.

Here’s an example from the author’s laptop:

>>> import os
>>> os.environ
environ({'SECURITYSESSIONID': '186a4', 'USER': 'mike', '__CFBundleIdentifier': 'com.wingware.wingpro', 'COMMAND_MODE': 'unix2003', 'PATH': '/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/u...', 'SHELL': '/bin/zsh', 'HOME': '/Users/mike', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'LaunchInstanceID': '4731D42A-3EA8-45E8-9921-EA9E897160E4', 'XPC_SERVICE_NAME': 'application.com.wingware.wingpro.446397.446405', 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.1ldniyJtTK/Listeners', 'XPC_FLAGS': '0x0', 'LOGNAME': 'mike', 'TMPDIR': '/var/folders/2q/yhh5dc6n367gftpg043m0x3r0000gn/T/', 'LC_CTYPE': 'UTF-8', 'WING_ORIG_LANGUAGE': '__undefined__', 'LANGUAGE': 'en', 'SHLVL': '0', 'PWD': '/Users/mike', 'OLDPWD': '/', 'HOMEBREW_PREFIX': '/opt/homebrew', 'HOMEBREW_CELLAR': '/opt/homebrew/Cellar', 'HOMEBREW_REPOSITORY': '/opt/homebrew', 'MANPATH': '/opt/homebrew/share/man::', 'INFOPATH': '/opt/homebrew/share/info:', '_': '/Applications/Wing Pro.app/Contents/Resources/bin/__os__...', 'WINGDB_SPAWNCOOKIE': 'LmdeVvJlrPMSBCZu', 'PYTHONIOENCODING': 'utf_8', 'WINGDB_PARENT_PIDS': '699', 'WINGDB_ACTIVE': '699'})

With that in mind, let’s try expanding a couple of the variables mentioned above:

>>> os.path.expandvars("$TMPDIR")
'/var/folders/2q/yhh5dc6n367gftpg043m0x3r0000gn/T/'
>>> os.path.expandvars("$PATH")
'/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/u...'

Now give it a try on your computer. If it doesn’t work, check your copy of os.environ to ensure you use the correct names.

Unfortunately, pathlib does not support expanding environment variables in any way.

Wrapping Up

If you need to work with file or folder paths, check out os.path and pathlib. Most developers who use Python 3 prefer pathlib as it’s much newer and makes some things easier. However, it is good to know about both because you will encounter os.path in legacy code.

 

 

The post Python 101 – Expanding Paths and Variables appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 22, 2023 06:26

August 16, 2023

Global Interpreter Lock Optional in Python 3.13

Python’s Global Interpreter Lock (GIL) may finally be coming to an end. The Python Steering Council recently announced that they are accepting PEP 703. This PEP proposes adding a build configuration (--disable-gil) to CPython, which will turn off the GIL.

The Python Global Interpreter Lock or GIL, is a mutex or lock that only ever allows the Python interpreter to run in a single thread.

You can read more about this topic in the What is the Python GIL? article that was published last month.

What About Python 3.12?

Of course, the earliest you’ll get to try this new build config flag is in early builds for Python 3.13, which probably won’t be available until late in 2023 or early 2024.

In the meantime, you might want to read up on PEP 684, which allows sub-interpreters to work in Python 3.12. You can start playing around with those in the release candidate builds for 3.12 now.

Wrapping Up

These are exciting times in Python land. While there aren’t any new core features like structural pattern matching in 3.10, there are still some important improvements and changes coming to the language that will impact Python in profound ways.

The post Global Interpreter Lock Optional in Python 3.13 appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 16, 2023 15:44

August 7, 2023

PyDev of the Week: Zac Hatfield Dodds

This week we welcome Zac Hatfield Dodds as our PyDev of the Week! Zac is a core developer of the Hypothesis package, which is a Python library for creating unit tests.

You can see what else Zac is up to by checking out Zac’s GitHub profile or by visiting Zac’s website.

Let’s take a few moments to get to know Zac better!

Can you tell us a little about yourself (hobbies, education, etc):

I grew up in Australia, until moving to San Francisco for work last year, and for as long as I can remember I’ve loved the outdoors. My family goes camping regularly – at the beach all year as a kid, or for weeks in the mountains every summer. I’ve also always loved reading so you can often find me tucked into a science fiction or fantasy novel in the evenings – I put up with ebooks when travelling to save weight – and I also enjoy nonfiction, usually about history or technology or both. I’ve also been known to make iridescent chocolate for parties, tempering it against a diffraction grating – it’s edible and beautiful nanotechnology!

My undergrad was in interdisciplinary studies at the Australian National University – I started programming towards the end of that time when I discovered that the projects I wanted to do in science classes required traditional programming, for data analysis which was beyond Microsoft Excel. These days I lead a research team at Anthropic, but still working towards my PhD in evenings and weekends – it’s in computer science and largely based on my open-source projects, so while there’s not much subject-matter overlap with work I still spend a lot of time thinking about it.

How did you get involved with the Hypothesis project?

I started using Python late in my degree for scientific data analysis, and loved it. I spent most of my project classes working on various packages for scientific data analysis. In fact one of those packages was my first contribution to the python package index and my first GitHub repository which was useful to someone else! Two of these projects also turned into part-time jobs, which was a lot of fun.

I actually discovered Hypothesis, which was started by David MacIver, through one of those science projects. There’s a research forest at the national arboretum, and the School of Biology had recently started using drones to capture high-resolution 3D models of the forest, which I still find incredibly cool. My project was to take this many-gigabyte 3D model, and… count the trees. We knew how many had been planted, but hadn’t actually counted them and wanted to get some basic metrics like a list of trees with height, area, and canopy colour automatically.

The problem was that my program worked perfectly for the small data sets that we had, and it worked perfectly when I clipped a subset of the large data set, but whenever we run it on the full large data set my program would spend about 16 hours processing it and then crash. It’d get all the way through the data processing, create final outputs, and then crash instead of writing out the output file. I didn’t know what to do, but when it takes you a full working day to do one run of your program before it crashes you have plenty of time to study better ways to test code!

I’d read about property based testing before and decided that it sounded pretty promising. I spent about a day reading the hypothesis docs, playing around with it, and implementing some extensions to its numpy support that I needed to generate arrays of structs (to create input files). Once I had that, it was a matter of about 20 seconds to discover that the library I was using would crash if you attempted to write a file where one of the column names contained a space character. 15 minutes later I had patched it, installed the patched version of the library, and set off another run! I discovered the day after that that had indeed fixed my problem and so after several weeks of confusion and stress the project was successful after all – and I was hooked.

I contributed my extensions upstream, hung around and fixed a few other bugs and documentation problems that I’d seen, and because I had enjoyed that so much I kept hanging around and kept fixing more. Six years later I lead the Hypothesis project, and I’ve made some great friends and gotten to work on fascinating projects that I don’t think would have happened otherwise!

Which Python libraries are your favourite (core or 3rd party)?

I often end up contributing to my favourite libraries, so I want to be clear that I was a fan first – it’s not because I help maintain things that I like them, though I find it does deepen my appreciation.

I’m a huge fan of Trio, the library for async structured concurrency – I feel like I can in fact write nontrivial concurrent code and get it right, which is incredible.  Read Notes on Structured Concurrency or watch my talk from PyCon to learn more!

I also really like Hypothesis and the surrounding ecosystem, or I wouldn’t spend so much time working on it.  See the rest of this interview!

LibCST makes automated refactoring remarkably easy, and I’ve enjoyed building auto-fixer tools for deprecations in Hypothesis or async antipatterns in flake8-trio, and autoformatting tools like shed have also been fun.

In the standard library, contextlib is an under-appreciated tool for correct code – without try/finally or context managers, forgetting to clean up or close a resource is all too easy when an unexpected exception is raised.  I also find functools remarkably useful – easy caching and partial application are great.

What projects are you working on now?

My current open source projects are mostly related to testing in Python. I lead the Hypothesis project, and have a variety of related spinoffs / extensions / new features as part of my ongoing PhD – thankfully the implementation is done, so I’m “just” writing my dissertation around work.

The Ghostwriter writes tests for you – sometimes ready to run, other times partially-filled templates to help you get started.  The idea is to make it as quick and easy as possible to start using Hypothesis!

Hypothesis’ explain phase makes it easier to understand why your test failed, going beyond the traditional minimal failing example.  We vary each part of the input, trying to find parts of the minimal failing example which can vary without the test ever passing – for example, in `divide(x=0, y=0)` x can be any value!  We also report lines of code which were always run by failing examples but never passing examples (if any!), which can be a useful complement to a traceback.

HypoFuzz adds smart, coverage-guided fuzzing for your whole test suite.  It’s a higher-overhead way to find failing inputs, but if you want to run something overnight or all weekend it’s a fantastic addition to your workflow – and has zero-effort integration with your local or CI test runs via the shared database of failing examples.  You just run your tests, and they replay whatever the fuzzer found!

Finally, I work on a variety of unrelated projects too – as a Pytest core dev I’m particularly interested in making warnings and error messages as helpful as possible (sometimes in CPython); I contribute to Trio occasionally for the async ecosystem; and have added several linter warnings to flake8-bugbear and started flake8-trio.  On the niche side, I have an autoformatter named shed which wraps black, pyupgrade, isort, autoflake, and a bunch of custom refactoring logic to provide a maximally standardised code style.

Thanks for doing the interview, Zac!

The post PyDev of the Week: Zac Hatfield Dodds appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on August 07, 2023 05:30

July 31, 2023

PyDev of the Week: Dr Becky Smith

This week we welcome Dr. Becky Smith (@rebkwok) as our PyDev of the Week! Becky is one of the organizers for DjangoCon Europe. If you’d like to see what Becky has been coding recently, you shold check out Becky’s GitHub profile.

Let’s spend a few moments getting to know Becky better!

Can you tell us a little about yourself (hobbies, education, etc):

Education-wise, I’m a psychologist (degree in psychology, PhD in behavioural neuroscience), but that was a long time ago! After my PhD I went into clinical trials research, and spent more than a decade doing various roles in that industry, including training researchers on assessment scales, adverse event monitoring, and project management. Now I work as a software developer at the Bennett Institute for Applied Data Science.

I like hanging upside down from things (aerial silks, hoop, pole), running, crafting – especially knitting – and I have 2 dogs, a staffie and a podenco.

Why did you start using Python?

I wasn’t enjoying my job (this was when I was still working in clinical trials) and I started learning python as a hobby, something to do because I didn’t feel like I was learning anything at work. I mostly used free online resources and courses, and started working on small projects. After a few months, I decided to take the leap and try to make a career out of it. Going from a director-level role in my previous career back to being an intern was one of the scariest, but best things I’ve ever done. I went to EuroPython in Berlin when I’d only been learning Python for 4 or 5 months, and it just happened to be the EuroPython that DjangoGirls was launched at. That really inspired me, and I ended up running a DjangoGirls workshop in Edinburgh in November of that year. And now, 9 years later, I’m somehow a trustee of the UK Python Association, and apparently a serial conference organiser.

What other programming languages do you know and which is your favorite?

Not many! Python is obviously my main programming language, and my favourite. I can get by where I need to with javascript, and I have some very outdated knowledge of Matlab and R, but as a late-comer to programming in general I haven’t (so far) become as familiar with any other languages as I am with Python.

What projects are you working on now?

Python projects? Nothing major…I’ve just finished running DjangoCon Europe (that’s a pretty big project, right?!), and that’s taken most of my brainspace for at least the past 6 months! I’m also an organiser for PyCon UK, which is in September this year, so that’s taking over as my next python-related project!

Which Python libraries are your favorite (core or 3rd party)?

I mean, it’s not exactly unprecedented, but I have to say itertools, don’t I? It’s definitely the most useful core library, just full of all the useful things you don’t need to write for yourself! I also have a fondness for a small library for working with datetimes and timezones, called Delorean (and not just for the name)!

Is there anything else you’d like to say?

As a career-changer, and someone who came to Python and programming in general later in life, I suffer (probably more than most) from imposter syndrome. One of the questions I’ve often been asked is whether I’d encourage other people to do what I did, and start again from scratch in a new industry. I find it a hard question to answer, because while it was a great thing for me, I don’t deny that I also had a lot of luck and support. In general though, I think a diverse team of developers builds a better product – whatever that is. My current team consists of people from many different backgrounds, and only a very few formal computer scientists. We bring a lot of different perspectives and approaches to our work, and I think that means we come up with solutions that wouldn’t happen if we were all the same!

Thanks for doing the interview, Becky!

The post PyDev of the Week: Dr Becky Smith appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on July 31, 2023 05:28

July 24, 2023

PyDev of the Week: Sanskar Jethi

This week we welcome Sanskar Jethi (@sansyrox) as our PyDev of the Week! Sanskar is the author of Robyn, a super fast Python web framework with a runtime written in Rust. Sanskar is also the creator of Starfyre, a package for building reactive frontends with Python.

If you’d like to catch up with Sanskar, you can find him on Medium.

Sanskar Jethi

Let’s spend some time getting to know Sanskar better!

Can you tell us a little about yourself (hobbies, education, etc):

Hey! ????

My name is Sanskar. I was born and raised in New Delhi, India, and work in London. I work as a Software Engineer at Bloomberg during the mornings and as a Free and Open Source developer at Robyn during the nights. When I am not in front of my PC, I enjoy lifting heavy circles and chasing the pump at the gym. I am an avid reader and love discussions on the topics of philosophy, business, and technology. You call me a ‘Philosopher-Coder-Athlete’ – or, you know, Sanskar for short.

Why did you start using Python?

In 2016, I decided to explore Python due to its striking similarities to JavaScript. Although the indentation-based syntax was initially a hurdle, my real dive into the language began when I embarked on a project called SUSI. That was the turning point, where I grew a deep affinity for Python.

What other programming languages do you know and which is your favorite?

Currently, my work involves Python, JavaScript, TypeScript, and Rust. Despite the stiff competition between JavaScript (not TypeScript!) and Rust, Python still reigns supreme as my absolute favorite.

What projects are you working on now?/h2>

At present, my primary focus lies on two Python packages – Robyn and Starfyre.

Robyn is a high-performance, community-driven, innovator-friendly web framework with a Rust runtime.

Starfyre, on the other hand, is a Python framework designed specifically for crafting reactive front-end applications.

Which Python libraries are your favorite (core or 3rd party)?

Apart from Robyn and Starfyre(haha), a Python library that has recently piqued my interest is `pysnooper`. This unique library aids in debugging by providing a detailed view of variables in scope alongside the output – a feature that I find invaluable.

What is the origin story behind Robyn web framework?

It was April 2021 and I was in my final year of university. I was supposed to be working on my final project, but Reddit distracted me. Around that time, a major tech company announced their adoption of Rust for one of their projects, leading to a flood of “Rewriting Everything in Rust” memes on the platform.

I was working on a personal project with a Flask backend at the time and was frustrated by the lack of async support in Flask. I had tried using Quart and FastAPI before, but they weren’t as widely used. That’s when I decided to see if I could create a version of Flask with async support

Since Rust was gaining so much traction, I decided to try making Robyn in Rust. Much to my surprise, my first benchmark showed that Robyn outperformed many other Python frameworks. And thus, Robyn was born.

Why do you think others should try Robyn over Django or FastAPI?

Robyn is a High-Performance, Community-Driven, and Innovator Friendly Web Framework with a Rust runtime.

Robyn excels in environments that demand rapid development of a Python web backend, yet hold scalability as a crucial requirement. Its design philosophy caters to developers who appreciate a flexible framework with essential functionalities pre-built, but also want the liberty to customize as per their unique needs. Robyn is especially suitable for web applications where developers value simplicity in implementation while retaining the ability to conduct complex operations. Its robustness and flexibility make it a perfect fit for both straightforward and complex web application development.

Thanks so much for doing the interview, Sanskar!

The post PyDev of the Week: Sanskar Jethi appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on July 24, 2023 05:25

July 17, 2023

PyDev of the Week: Sophia Yang

This week we welcome Sophia Yang (@sophiamyang) as our PyDev of the Week! Sophia is a data scientist who works at Anaconda. You can connect with Sophia on LinkedIn. If podcasts are your thing, you can catch Sophia on this Teaching Python Podcast from last year.

Sophia Yang

Let’s take a few moments to get to know Sophia better!

Can you tell us a little about yourself (hobbies, education, etc):

I’m a Senior Data Scientist and a Developer Advocate at Anaconda. I’m passionate about the data science community and the Python open-source community. I made several Python open-source libraries such as condastats, cranlogs, PyPowerUp, intake-stripe, and intake-salesforce, and I serve on the Steering Committee and the Code of Conduct Committee of the Python open-source visualization system HoloViz. I hold an M.S. in Computer Science, an M.S. in Statistics, and a Ph.D. in Educational Psychology from The University of Texas at Austin.

Why did you start using Python?

I started using Python in college when I took my stats classes : )

What other programming languages do you know and which is your favorite?

I learned Matlab, C++, Rust, Go, and Kotlin in classes and I have used R/Stata/SAS for research in grad school. Python is my favorite. I love Python’s rich ecosystem and open-source community.

What projects are you working on now?

This week we are working on collaborating with Hugging Face and getting HoloViz and Panel on Hugging Face. HoloViz is a set of open-source and interoperable tools for making sense of data at any scale, primarily through visualization in a web browser. I hope the Hugging Face community will like using HoloViz and Panel as much as I do.

Which Python libraries are your favorite (core or 3rd party)?

hvPlot and Panel are my favorites. hvPlot allows me to build interactive plots super easily. It’s built on Bokeh, Matplotlib, and Plotly. I use Panel to build interactive apps and dashboards.

How did you decide to be a data scientist?

During graduate school, my research was all around understanding data and building models and I wanted to keep doing that after I graduate.

Do you really need lots of math to be a data scientist? Why or why not?

Yes and no. Everything is learnable. You can learn a lot of things on the job. A good math foundation might help you learn things faster. There is a lot more than math in a data science job. Programming skills, understanding business logic, and communicating skills are also essential for success in a data science role.

Is there anything else you’d like to say?

I have a Data Science and Machine Learning book club. We read one book a month and chat with the book authors by the end of the month. Check out my book club here: http://dsbookclub.github.io/.

Thanks for doing the interview, Sophia!

The post PyDev of the Week: Sophia Yang appeared first on Mouse Vs Python.

 •  0 comments  •  flag
Share on Twitter
Published on July 17, 2023 05:45