I just finished day 11 of 100 days of Web with Python and am pretty pleased with how it went. The past 2 days were following along as the instructor setup an API using API Star. While overall I was able to follow along with the tutorial, there were a couple of instances where Bob (the instructor) jumped to the next step with little or no explanation and I was playing catch up. In particular, since I had never used “breakpoint()” before, when he ran the application and there was suddenly a “pdb” prompt I was very confused. I got it figured out, but I probably re-watched that part of the video 10 times trying to figure out where the “pdb” was coming from.
breakpoint() is pretty slick!
That being said, I think that “breakpoint()” is one of my new favorite functions. Apparently it was added in Python 3.7, and implements PEP553. Basically it gives you a prompt at that point in your program so you can check variable states and test functions, etc. For more information about the breakpoint() function, see this quick tutorial on Hackernoon. I can definitely see using this in class next year. Unfortunately, Kubuntu 18.04 is still on Python 3.6. I guess that means I’ll be upgrading to 19.04 in the Fall. That’s ok, I was already thinking about switching the class to Xubuntu.
CRUD Operations
Back to APIs…I actually had my 2nd year classes do some work with open-notify.org, an API for checking the whereabouts of the International Space Station, so it’s pretty neat to see how to develop the API itself.
This was my first experience with CRUD operations since my databases class in college. CRUD is an acronym that stands for Create, Read, Update, and Delete. These are the primary operations you do on elements in a database. For this particular project, we used a dictionary instead of a database, but I can see where (probably) with a few minor changes to the code, we could be using an actual database back end.
Where’s the data?
An important part of building the API is getting the data. But finding data for testing things can be difficult. I mean, it’s EVERYWHERE, but in my experience it’s often behind a pay-wall or isn’t in a very usable format for testing things. That is where Mockaroo comes in. I hadn’t seen this tool before. Basically, it lets you get up to 1000 randomly generated rows of data in JSON, csv, xls, or SQL. That’s really cool. I think we may use this next year for some practice processing csv files.
Pytest
Another major part of the past two days was using Pytest for testing the functions. In class, I have my students use the doctest module, so I don’t have any experience with Pytest. I’m looking forward to diving in tomorrow to see what is involved and may consider using it instead next year. A big advantage to doctests is they can be inserted in as documentation in the code itself. The downside to this is it (in opinion) potentially makes the program much more difficult to read. It might be nice to just have a separate .py file with a bunch of tests that I can put in the starter repo. I know you can do the same thing with doctests basically, so I’ll have to weigh the advantages and disadvantages of each a bit more.



