Python Packages
Python Lab supports many of the built-in features of the Python language, as well as a small set of third-party packages that are useful for data science, interactivity, and drawing. Students can use the import statement to access additional functions and tools from these modules in their programs.
Built-in Modules and Functions
Many core Python functions are available in Python Lab without needing to import anything. This includes:
-
print() and input() for console output and user input
- Common data types like str, int, float, and list
- Built-in functions like len(), range(), sum(), and max()
In addition, Python Lab supports several commonly used built-in modules that must be imported before use:
-
math – for mathematical operations like sqrt() and pi
-
random – for generating random numbers or selecting random items
- time – for tracking time or adding delays with sleep()
To use a module, students can import it like this:
import math
print(math.sqrt(25))
Or import specific functions:
from random import randint
print(randint(1, 10))
Third-Party Packages
Python Lab also supports a small number of widely used third-party Python libraries:
-
matplotlib.pyplot – for creating charts and visualizations
-
pandas – for working with tables and structured data
- numpy – for working with arrays and numerical computations
These libraries must be imported explicitly. For example:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
Note: Many other third-party libraries commonly available in full Python environments (like pygame or requests) are not supported in Python Lab.
Code.org Packages
Python Lab includes a Code.org-specific package for creating drawings in Neighborhood levels:
- codeorg_neighborhood – provides access to the Neighborhood environment for movement, drawing, and interaction
This package is only available in levels that support the Neighborhood or can be found in Standalone Python Lab. For example:
from neighborhood import Painter
The neighborhood module in Console only mode. If students try to use it in a level where it’s not supported, they will receive an error. You can see more about the API and capability of the neighborhood here.