Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Using libraries and packages

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

50 minutes

Do not write what exists

You need to show today's date in your app. Do you work out leap years yourself? You could. It would take a week and have bugs.

Somebody already wrote it and tested it. You import it and use it in one line.

A good developer knows what to build and what to borrow.

Key words

WordWhat it meansExample
ModuleA file of ready-made code that you can import.json
PackageA folder of modules, shared so others can install it.
LibraryA collection of code that gives you extra features.
Standard libraryThe libraries that come with the language, with nothing to install.
DependencyA library your program needs to work.
Package managerA tool that downloads and updates packages.pip, npm
APIA set of ready-made jobs or web addresses that another program offers for you to use.
VersionA number that says which release of a library you have.2.31.0
LicenceThe rules that say how you may use a piece of software.

The cells students fill in are left blank in this preview.

Try it: import a module

Code: python
import json
from datetime import date

text = '{"name": "Sam", "goals": 3}'
data = json.loads(text)   # text to a dictionary
print(data["name"])

today = date(2026, 11, 1)
print(today.strftime("%d %B %Y"))
print(today.weekday())   # 0 is Monday

# Change the date and run again.

Where does code come from?

There are three places.

The standard library comes with the language. It is safe and always there. json, datetime and random are in it.

A package from a package manager is written by other people. You install it with pip for Python or npm for JavaScript.

An API lets you use a service on another computer, such as a weather forecast.

Quick check

Have a go

Quick check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Try it: count with a library

Code: python
from collections import Counter
import random

words = "goal goal miss goal miss save".split()
print(Counter(words))
print(Counter(words).most_common(1))

rng = random.Random(5)     # a seed: the same numbers every time
print(rng.choice(["Aisha", "Ben", "Sam"]))
print(rng.randint(1, 6))

# Run it twice. Why do you get the same result?

Choose a library with care

AskWhy it matters
What is the licence?It may forbid your use, or force you to share your code
Is it still looked after?A library with no updates for years may have unfixed bugs
How big is it?A big library slows your app and your downloads
Is it secure?Check for known problems before you add it
Does it have good documentation?You must be able to learn it without asking anybody
Does it work on our platform?Compatibility: it must work on your system, such as Windows or Linux, and with your language version

The cells students fill in are left blank in this preview.

Pin the version

data-callouts.important.label

A new version can change how a library works. Write the version you tested in a list file, for example: requests==2.31.0. Then your product works the same on every computer.

What libraries can add

Libraries add features that would take you weeks to write. Some play audio or resize pictures: this is media content. Some give buttons, menus and charts: these are interface components. Others help one program work on many systems: this is compatibility.

Always read the documentation first. It shows examples and warns about problems.

The lesson goes on

6 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.