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

Free lesson

OS 6.1 (5 of 10): Using libraries and packages

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

50 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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 that others can install.
LibraryCode that gives you extra features.
Standard libraryThe libraries that come with the language.
DependencyA library your program needs to work.
Package managerA tool that downloads and updates packages.pip, npm
APIReady-made jobs or web addresses another program offers you.
VersionThe release number of a library.2.31.0
LicenceThe rules for using a piece of software.

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

Import a module and use it

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.

Make a free account to save your work and track your progress.

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.

Check: where code comes from

Have a go

Check: where code comes from

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

Count words 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?

Make a free account to save your work and track your progress.

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

Important

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.

Check: what libraries add

Have a go

Check: what libraries add

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

Match the word

Have a go

Loading…

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

Use four standard library modules

Use four standard library modules. Counter counts words. json reads data. datetime works out days. random picks a winner, and a seed makes it repeat. Read the comments. Press Run Tests.

Code: python
import json
import random
from collections import Counter
from datetime import date


def count_words(text):
    # Count each word, ignoring upper and lower case. Words are split by spaces.
    # Give back a dictionary, like {"the": 2, "cat": 1}. Use collections.Counter.
    return None


def order_total(json_text):
    # json_text is like: {"items": [{"name": "tea", "price": 150}, {"name": "milk", "price": 90}]}
    # Give back the sum of the prices (pence). Use json.loads.
    return None


def days_until(today_text, due_text):
    # Both are dates written like 2026-11-05. Give back the number of days from
    # today to the due date. Use datetime.date.fromisoformat.
    return None


def pick_winner(names, seed):
    # Pick one name. With the same seed the same name must come back every time.
    # Use random.Random(seed).
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

Choose between two chart libraries

Your team needs a library to draw charts in a Python app. You find two. Library A is free, last updated four years ago, with one page of notes. Library B is free, updated last month, with clear guides and examples, but it is large. Choose one. Use at least four of the questions from the table: licence, looked after, size, security, documentation, platform. Then say how you would pin its version.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

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

Exit quiz

Have a go

Exit quiz

6 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

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.