Resources mentioned in this lesson:
Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Doing More With Python
00:00 With Python, it’s easy to start building beyond the basics. Occasionally, you may think you need to build a feature from scratch, but there’s a good chance Python already has something you can use.
00:10 Python comes batteries included with a comprehensive standard library. These packages come with the standard Python installation, and you just need to import them.
00:18
For example, math for mathematical operations,
00:22
random for pseudo-random numbers, pathlib for working with file paths, tkinter for building desktop GUI applications, the json and csv modules for common data formats, and even a unittest module for testing code, amongst many, many more.
00:38 And when something isn’t in the standard library, odds are you can find it in the community. The Python Package Index, PyPI, hosts packages created by the Python community.
00:49
These packages add features that Python doesn’t include by default. You can install these packages with tools like pip and uv. But be forewarned, you should always research packages before depending on them.
01:01 Once you include a package as a dependency in your project, you’re tied to it. Maybe it contains vulnerabilities, which your project will inherit. Or if the code is sound, it still might not be regularly maintained, and could end up breaking down the road, taking your project with it.
01:15 Or worse, you might have to become the orphaned package’s new maintainer. Say goodbye to your weekends. So to avoid such a tragic fate, how should you research a package?
01:25
Check out How to Evaluate the Quality of Python Packages. And how exactly do you install a package? Well, if a package isn’t installed, any code that tries to run it will get a ModuleNotFoundError.
01:38
For example, say you’re following a tutorial about working with the web. You’ll probably encounter requests, a library so common a lot of people forget that it isn’t part of the standard library.
01:48
The quickest solution would be to pip install it. python -m pip install requests. This command installs requests into your current Python environment.
01:58
Problem solved. But be careful about where you run pip install. Typically, you’ll want to be in a virtual environment, a kind of isolated Python workspace that keeps one project’s dependencies separate from those of other projects.
02:11 To learn more, have a read through Python Virtual Environments: A Primer.
Become a Member to join the conversation.