• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

How to make visible functions at package level in python?

I have package that contains several modules. I would like to expose some functions from a module to the package level.

How to do that?

module.py that contains function

So ...
# example
import package
# here the function definition is in the module.py
# how to avoid this:
import package.module

Open in new window

  • 2
1 Solution
Roger BaklundCommented:
Use this syntax:

from package import function

... or:

from package.module import function
koleto115Author Commented:
I want to keep the package name as a root name and to expose the function defined in the module at package level. What I need is suppose the package name is effects and it contain module echo.py and the function delay() is defined inside the module echo.py so I need to do this:

import effects



import effects.echo

I would like to keep the root name of the package.

Roger BaklundCommented:
Within effects/__init__.py, do:

from echo import delay

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now