Menu
Courses / python basic / Modules, Packages & Next Steps

Modules, Packages & Next Steps

10 / 10 Part of python basic




 

    🚀 Topic 10 · Mastery
 

 


    Modules, Packages & Next Steps
 


 


    Organise code into reusable modules, install third-party packages with pip, and discover where to take your Python skills next.
 


 

    ⏱ ~45 min
    🟡 Intermediate
    🎓 Course finale
 


 
 

   

     
     

What is a Module?


   

   


      A module is simply a .py file containing functions, classes, or variables. You can import any module and reuse its code anywhere in your project.
   


   

     

        mathutils.py — your custom module
     

     
# mathutils.py
PI = 3.14159

def circle_area(radius):
    return PI * radius ** 2

def add(a, b):
    return a + b

   

   

     

        main.py — importing your module
     

     
# Import the whole module
import mathutils
print(mathutils.circle_area(5))   # 78.53975

# Import specific names
from mathutils import add, PI
print(add(3, 7))              # 10

# Import with an alias
import mathutils as mu
print(mu.PI)                   # 3.14159

   

 


 
 

   

     
     

The Standard Library


   

   


      Python ships with a vast standard library — hundreds of modules for common tasks, all available without installing anything.
   


   

     

        os
       

File system operations — paths, directories, environment variables


     

     

        sys
       

Interpreter internals, command-line args, exit codes


     

     

        math
       

Trigonometry, logarithms, floor/ceil, constants like pi


     

     

        datetime
       

Dates, times, timedeltas, and formatting


     

     

        random
       

Random numbers, shuffling, sampling from sequences


     

     

        re
       

Regular expressions for pattern matching in text


     

   

   

     

        stdlib_examples.py
     

     
import os, math, random
from datetime import datetime

print(os.getcwd())              # current directory
print(math.sqrt(144))         # 12.0
print(random.randint(1, 6))    # random dice roll
print(datetime.now())           # current date & time

   

 


 
 

   

     
     

pip & Virtual Environments


   

   


      pip is Python's package manager. Use virtual environments to keep each project's dependencies isolated and conflict-free.
   


   

     

        Terminal — pip & venv
     

     
# Create a virtual environment
python -m venv venv

# Activate it
source venv/bin/activate        # macOS / Linux
venv\Scripts\activate           # Windows

# Install a package
pip install requests

# Save all dependencies
pip freeze > requirements.txt

# Restore them on another machine
pip install -r requirements.txt

   

   

      💡 Always use a venv
     

Installing packages globally can break system tools. One virtual environment per project keeps everything clean and reproducible.


   

 


 
 

   

     
     

Creating a Package


   

   


      A package is a folder of modules. Add an __init__.py file to make Python treat the folder as an importable package.
   


   

     

        Package folder structure
     

     
myproject/
├── main.py
└── utils/
    ├── __init__.py      # makes utils/ a package
    ├── math_utils.py
    └── string_utils.py

   

   

     

        main.py — importing from package
     

     
from utils.math_utils import circle_area
from utils.string_utils import capitalise_words

print(circle_area(10))
print(capitalise_words("hello world"))

   

 


 
 

   

     
     

The if __name__ == "__main__" Guard


   

   


      This pattern lets a file be both a runnable script and an importable module. Code inside the guard runs only when the file is executed directly, not when it's imported.
   


   

     

        script.py
     

     
def main():
    print("Running as a script")

def helper():
    return "I can be imported freely"

if __name__ == "__main__":
    main()   # only runs when you do: python script.py

   

 


 
 

   

     
     

Popular Third-Party Packages


   

   


      PyPI hosts over 500,000 packages. Here are the most essential ones by domain.
   


   

     

       
🌐

        Web Development
       

Flask, Django, FastAPI — build REST APIs and full web apps


     

     

       
📊

        Data Science
       

numpy, pandas, matplotlib — number crunching and visualisation


     

     

       
🤖

        AI & ML
       

scikit-learn, tensorflow, torch — machine learning and deep learning


     

     

       
🔗

        HTTP & APIs
       

requests, httpx, aiohttp — call REST APIs and fetch web data


     

     

       
🧪

        Testing
       

pytest, unittest — write and run automated tests


     

     

       
⚙️

        Automation
       

selenium, playwright, pyautogui — browser & desktop automation


     

   

 


 
 

   
🎉

   

Course Complete!


   


      You've covered all 10 core topics of Python — from variables and loops all the way through OOP, file handling, and the module ecosystem. You're ready to build real projects.
   


   

     
✅ 10 Topics

     
💻 40+ Code Examples

     
🚀 Ready to Build

   

 


 
 

   

     
     

What to Learn Next


   

   

     

        🧩
       

          Decorators & Generators
          Advanced function patterns — @decorator, yield, and lazy evaluation.
       

     

     

       
       

          Async / Await
          Concurrent programming with asyncio for fast I/O-bound applications.
       

     

     

        🧪
       

          Testing with pytest
          Write automated tests, fixtures, and parametrize to ship with confidence.
       

     

     

        🗄️
       

          Databases with SQLAlchemy
          Query SQL databases using Python ORM patterns — no raw SQL required.
       

     

     

        🏗️
       

          Build a Real Project
          The fastest way to solidify everything — build a CLI tool, API, or web scraper from scratch.