Labs ICT
Pro Login

Packages

Packages

A package is a folder containing an __init__.py file and one or more module files. Packages let you organize related modules into a hierarchy.

# Directory structure:
# mypackage/
#   __init__.py
#   mathops.py

# mathops.py
def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

# main.py
from mypackage import mathops

print(mathops.add(5, 3))
print(mathops.multiply(4, 2))

Install third-party packages with pip:

pip install requests

import requests
response = requests.get("https://api.github.com")
print(response.status_code)
Try it Yourself →