Modules and import
📚 What are Modules? A module is a file of Python code you can reuse. Python comes with a huge standard library of modules covering maths, dates, randomness, file handling, networking, and much more. Rather than writing everything from scratch you simply import what you need.

Appy Says…
You don't have to build everything from scratch. Python has thousands of modules — pre-written code you can drop straight into your program. Need to generate a random number? Pick a date? Do maths? There's a module for that. Import it and go.
What are Modules and Imports?
A module is a Python file containing functions, classes, and variables you can reuse. Importing a module makes its contents available in your script. Python ships with a huge standard library of modules built in.
- •
import math— import the whole module; usemath.sqrt(16) - •
from math import sqrt— import just one function; usesqrt(16) - •
from math import *— import everything (avoid — pollutes your namespace) - •
import random as rnd— give it an alias for shorter names - •Useful standard library modules:
math,random,datetime,os,json,time - •Third-party modules (installed with
pip):requests,numpy,flask
Think of it like Roblox Studio plugins
In Roblox Studio, you can install plugins to add new tools — a terrain generator, a rig builder. Modules are Python's plugins. Instead of writing a square-root function yourself, you import math and use the one that's already been tested by millions of developers.
How It Works
- •1. Python searches for the module name in: your folder → standard library → installed packages
- •2.
import mathloads the whole module as an object calledmath - •3. Access its contents with dot notation:
math.pi,math.sqrt() - •4.
from random import choiceimports just that one function directly - •5. Your own
.pyfiles are also modules —import my_utilsworks if it's in the same folder - •6.
pip install requestsin the terminal installs third-party packages from PyPI
Real-World Examples
- •A quiz app uses
from random import shuffleto randomise question order - •A countdown timer uses
import timeandtime.sleep(1)to wait one second - •A weather app uses
import requeststo fetch live weather data from an API - •A data dashboard uses
import jsonto parse JSON responses from a server - •A game leaderboard uses
from datetime import datetimeto timestamp each score
Key Facts
- •Python's standard library has over 200 modules — covering everything from email to HTML parsing
- •PyPI (Python Package Index) hosts over 500,000 third-party packages you can install with pip
- •Modules are only loaded once per program run — Python caches them for efficiency
- •You can write your own module by saving any
.pyfile and importing it by name
Watch Out!
Never name your own file the same as a built-in module — a file called random.py will shadow Python's random module and cause confusing errors. Use descriptive names like my_random_utils.py.
Remember
Prefer from module import function for clean, readable code. Use import module when you need multiple things from it. Avoid import *.
What You Learned
- •Modules are reusable Python files; import them with
import nameorfrom name import x - •Python's standard library has 200+ modules; PyPI has 500,000+ packages installable via pip
- •Unlocks: using random, maths, dates, file paths, JSON, and thousands of third-party tools
Key Facts
- →Python's standard library has over 200 modules — covering everything from email to HTML parsing
- →PyPI (Python Package Index) hosts over 500,000 third-party packages you can install with pip
- →Modules are only loaded once per program run — Python caches them for efficiency
- →You can write your own module by saving any
.pyfile and importing it by name
Real-World Examples
Remember
Prefer from module import function for clean, readable code. Use import module when you need multiple things from it. Avoid import *.
Quick Quiz
import math gives?