External Code Libraries (Packages)
Including external libraries without triggering the next security nightmare.
You have learned variables, loops, functions — you can write Python. But here is the secret of professional development: most real-world projects are 10% your code and 90% libraries others already built.
This article shows you the three layers of Python's code universe: what is already included, how to add what is missing, and why this ecosystem made Python the world's dominant AI language.
Standard Library & Imports
Module and Package
A real toolbox has physical space limits. Python's standard library keeps growing with each version and contains specialised modules (sqlite3, email, tkinter) that go far beyond basics. Also, a physical toolbox never requires choosing how you pull out a tool — Python's three import forms affect namespace behaviour.
Full module loaded. Access via math.sqrt(144). The name math serves as a namespace — no name conflicts with your own variables.
Only randint loaded. Direct call: randint(1, 6). Shorter, but with many imports you can lose track of origins.
Three Import Styles
Misconception: import Downloads Code from the Internet
Deep Dive: How Python's Import Machinery Works
pip & PyPI — The App Store for Python
pip and PyPI
An app store is curated and reviewed by a company. PyPI is open — anyone can upload. There is no mandatory quality gate, so you must learn to evaluate packages yourself (download counts, maintenance activity, documentation).
The pip Workflow: Install → Import → Use
requirements.txt — Making Dependencies Reproducible
Misconception: import Automatically Installs Missing Packages
Deep Dive: Evaluating Packages — Quality Signals
The Ecosystem — Why Python Became the AI Language
Python's Three-Layer Model
Each package is like a specialised LEGO brick manufactured by experts. You assemble them into custom creations without needing to know how plastic is moulded — just as you build an ML pipeline without writing C matrix multiplication code.
But LEGO bricks always fit together (standard stud size). Python packages can have version conflicts and incompatible dependencies. And LEGO is curated by one company, while PyPI is an open bazaar — ranging from industry-grade libraries to abandoned hobby projects.
Python as a Glue Language
Misconception: Python Is Too Slow for AI
Interactive: Package Manager Checklist
Answer the following questions about your Python project. At the end, you will receive a recommendation for which dependency management tool best fits your situation.
Package Manager Checklist
Find out which package management tool best fits your Python project.
Key Takeaways
Quiz: Packages and Imports
Checkpoint
- You run import requests in a fresh Python installation and get a ModuleNotFoundError. Why? What must you do first?
- A colleague sends you a project with a requirements.txt. You clone it and run the script — it crashes with ModuleNotFoundError for pandas. What command resolves this?
- NumPy performs matrix multiplication faster than a pure Python loop. Explain why, given that both run on the same CPU.