✦ Python Intermediate & OOP Local Python project

L2 · Concept 03 · Modules, Packages & Environments

One module is useful.
A package keeps a project together.

When a project has several related Python files, a package keeps them organized. Learn to create one, use __init__.py, and import code from its modules.

Learning goalOrganize related Python modules in a package, create __init__.py, and explain each part of an import such as from alati.kalkulator import saberi.
01 Learn02 Build locally03 Check your understanding

Learning as a guest

Learning as a guest? Save your progress!

Create a free account to learn with Sloby AI, check your understanding, and track your progress.

The entire platform is free throughout 2026. Foundations stays free forever.

A module is one file. A package organizes related modules.

A module is one .py file, such as kalkulator.py. A package is a folder that groups related modules. Think of a module as one tool and a package as the box that keeps related tools together.

alati/
├── __init__.py
├── kalkulator.py
└── konverter.py

A package helps a larger project stay easy to read. Here, alati is the package and the two .py files inside it are modules.

In the previous lesson, related files could sit beside main.py. That works at first, but the main folder becomes crowded as a project grows.

↳

A clear learning pattern: __init__.py is a Python file inside the package folder. It can be empty. We use it in this course for a classic Python package, because it is a clear way to mark and organize the package. Modern Python also supports some packages without it, but we will not need that pattern yet.

Before: related modules in the main folder
moj_projekat/
├── main.py
├── kalkulator.py
└── konverter.py

This can work, but more files quickly make the main folder harder to scan.

After: group related modules in a package
moj_projekat/
├── main.py
└── alati/
    ├── __init__.py
    ├── kalkulator.py
    └── konverter.py

Now the related modules live together in the alati package, while main.py stays easy to find.

Two useful import styles
from alati import kalkulator
print(kalkulator.saberi(5, 3))

from alati.kalkulator import saberi
print(saberi(5, 3))

# Avoid: from alati.kalkulator import *

The first style imports the module, so the call keeps kalkulator.. The second imports one function directly. Avoid import * because it hides where names come from.

Read an import from a package

  1. 1. Start with the packageIn from alati.kalkulator import saberi, alati is the package folder.
  2. 2. Name the modulekalkulator is the module file inside that package.
  3. 3. Import what you needsaberi is the function imported from the module, so you can call saberi(...) in main.py.

Python cannot find my package

  • You ran the wrong fileOpen the project folder and run the correct main.py from there.
  • A name does not matchCheck the folder name, file name, and every part of the import for a typo.
  • A file is missing .pyMake sure module files really end with .py and that __init__.py exists for this course example.
  • The project folder is differentMake sure you are working in the project that contains main.py and the alati folder.

Build your first Python package

Do this in VS Code

Continue locally in VS Code — the setup from the previous lesson is enough. Create and save these files in one project folder before you run main.py.

Package example
moj_projekat/
├── main.py
└── alati/
    ├── __init__.py
    ├── kalkulator.py
    └── konverter.py

The alati folder is the package. It keeps two related modules together.

Build the package step by step

  1. Create the alati folder and __init__.pyInside moj_projekat, create the alati folder. Inside it, create __init__.py; it may stay empty.
  2. Create kalkulator.pyAdd two related functions, then save the file.
    def saberi(a, b):
        return a + b
    
    
    def oduzmi(a, b):
        return a - b
  3. Create konverter.pyAdd a conversion function, then save the file.
    def celsius_u_fahrenheit(celsius):
        return celsius * 9 / 5 + 32
  4. Use the package from main.pyalati is the package, kalkulator is the module, and saberi is the function.
    from alati.kalkulator import saberi
    from alati.konverter import celsius_u_fahrenheit
    
    print(saberi(5, 3))
    print(celsius_u_fahrenheit(20))
↳

Run locally: python main.py If your computer uses python3 instead, run python3 main.py. The expected first results are 8 and 68.0.

Check before asking Sloby for help

  • Save every fileSave main.py, __init__.py, and both modules before you run main.py.
  • Check the package pathThe alati folder must be beside main.py, and kalkulator.py must be inside alati.
↳

Next: Virtual Environments. You can now organize your own code. Next you will organize the Python libraries that belong to one specific project.

Which import lets us call the function directly as saberi(2, 3) in main.py?

The project has an alati package with kalkulator.py, and that module defines saberi(a, b).

moj_projekat/
├── main.py
└── alati/
    ├── __init__.py
    └── kalkulator.py
Choose the output

Build independently in VS Code

Create the moji_alati package

This challenge is local. Build the package yourself, then use Check My Code for mentoring feedback after your attempt.

Your goalCreate moji_alati with __init__.py, brojevi.py, and poruke.py. In brojevi.py, make a function that returns whether a number is even. In poruke.py, make a function that receives a name and returns a greeting. In main.py, import and use both functions.
moj_paket/
├── main.py
└── moji_alati/
    ├── __init__.py
    ├── brojevi.py
    └── poruke.py

Work in your local VS Code folder

Progressive hints
  • First create the package folder and its three files.
  • A number is even when the remainder after division by 2 is 0.
  • Import each function from its module, for example with from moji_alati.brojevi import ....

After your own attempt, use Check My Code on the active Python file, confirm that its code will be sent, and read Sloby’s mentoring feedback. Sloby does not run or change your code.

Sloby, the Python AI Tutor mascot

Your learning mentor

Sign in to ask Sloby

Create a free account or sign in to get AI guidance while you learn.

Sign in to check your understanding

Create a free account or sign in to receive AI feedback and save your learning progress.

Python AI Tutor · Learn by understanding, not just by running code.