Very few things just work out of the box. As developers we know this, and are ready for it. When you dive into Python for the first time, the number of things that do indeed just work is amazing. Why then a post about more packages to use?
These 5 packages will give you the ability to move beyond what you think is possible, and in a couple of lines of code, allow you to grab information from web pages, do complex calculations on it, and push your findings onto your own web app in a matter of minutes not weeks, and as an added bonus, you get to sleep at night knowing your code is doing what it should be doing.
The 5 Python Packages every South African developer should know about are:
1. Requests
Whether you want to integrate with an external API or just grab a webpage’s content, Requests is the way to go. After installing the module, you just need 2 lines in your code to access any url over HTTP. Requests also allow you to set GET and POST variables with ease, or add JSON to the request body.
2. Beautiful Soup
Eskom se Push won a couple of app awards, all they did was setup a program to grab loadshedding information from a couple of sites, and then send the information to the app. Beautiful Soup makes getting the information out of a web page you downloaded with Requests as simple as searching a bit of text, an HTML tag, or CSS attribute and grabbing what you need from there.
3. NumPy
If you need to do some heavy numbers lifting, NumPy’s scientific computing capabilities will come in very handy. It supports N-dimensional arrays, linear algebra, and random number generators among other things. There is also support for including C++ or FORTRAN libraries, should you need those. NumPy is the reason a number of scientists are switching to Python, and a must if you are interested in data science.
4. Flask
Building your very first web app can be intimidating, unless you are using Flask. This micro framework allows you forget about complex routing of requests and files defining url endpoints. You define the endpoint right there at the function that returns the result. It is the quickest way to get something “out there”. It does not matter if you are writing prototypes, or creating a minimum viable product, Flask will have you done in no time.
5. Unittest
Unittest is one of those batteries that come included with the Python standard library. As the name suggests, it is a package that allows you to do unit testing of your code. This is the part that makes you sleep at night, knowing that the code you wrote does what it is intended to do. It is also the part of the project that helps you not have a panic attack when you need to change something 3 months after you built it.
If you get into the habit of writing unit tests, you will find that you trust the code you wrote more, and you also make changes with more confidence, knowing that the changes you made did not break something that was working yesterday.
Are there any other Python tools you use frequently? Let us know in the comments section below. Follow Hyperion blog in the future if you’d like to see more articles like these for the South African market.