Modules are single Python files that can be imported. Any python file can be a module. For example, if I have two Python files: and in the same directory:


  def hello(name):
      print("Hello {}".format(name))

I can import that module in my

  import module

  module.hello("World!") # Hello World!

The same can be done in the interpreter:

  >>> from module import hello
  >>> hello("World!") # Hello World!


Packages are made up of multiple Python files (or modules), and can even include libraries written in different languages like C or C++. Seeing an __init.py__ file in a folder typically tells you that that folder is a Python package. The doesn't have to contain any code โ€“ sometimes it does โ€“ it just has to be there for Python take that particular folder as a package.

  ๐Ÿ“ my_package
  # __init.py__

  from my_package.module import hello

When you import my_package in your script, the script will be run, giving you access to all of the functions in the package. In this case, it only gives access to the module.hello function.