🌐
Real Python
realpython.com › python-modules-packages
Python Modules and Packages – An Introduction – Real Python
March 21, 2024 - C:\Users\john\Documents>python mod.py Executing as standalone script If Comrade Napoleon says it, it must be right. [100, 200, 300] arg = quux <__main__.Foo object at 0x03450690> ... Modules are often designed with the capability to run as a standalone script for purposes of testing the functionality that is contained within the module. This is referred to as unit testing. For example, suppose you have created a module fact.py containing a factorial function, as follows:
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-packages
Python Packages - GeeksforGeeks
2 days ago - Module: A single Python file containing reusable code (e.g., math.py). Package: A directory containing modules and a special __init__.py file.
Discussions

How to write a Python module/package? - Stack Overflow
Just like the use of modules saves ... names saves the authors of multi-module packages like NumPy or the Python Imaging Library from having to worry about each other’s module names. Package Example: Let's now assume we have the following folder and files.... More on stackoverflow.com
🌐 stackoverflow.com
Modules every python developer should know

requests for http requests. this module should be taught as a case-study in good API design.

pretty much everything in itertools and functools is incredibly useful once you learn how to use them. makes for much more expressive code and easier use of functional style idioms.

More on reddit.com
🌐 r/Python
138
218
December 27, 2015
Top 20 Python libraries for data science in 2018

Honestly, I'm so bored of these "top X" articles on the corporate blogs.

More on reddit.com
🌐 r/Python
3
36
June 18, 2018
Top Python libraries of 2017

Too many machine learning libraries. I know they're the new shiny, but they're not used by the majority of Python developers.

More on reddit.com
🌐 r/Python
17
64
December 21, 2017
🌐
Python Packaging
packaging.python.org › tutorials › packaging-projects
Packaging Python Projects — Python Packaging User Guide
These are archives that are uploaded to the Python Package Index and can be installed by pip. Make sure you have the latest version of PyPA’s build installed: ... If you have trouble installing these, see the Installing Packages tutorial. Now run this command from the same directory where pyproject.toml is located: ... This command should output a lot of text and once completed should generate two files in the dist directory: dist/ example_package_YOUR_USERNAME_HERE-0.0.1-py3-none-any.whl example_package_YOUR_USERNAME_HERE-0.0.1.tar.gz
🌐
Programiz
programiz.com › python-programming › package
Python packages (With Examples)
Become a certified Python programmer. Try Programiz PRO! ... A package is a container that contains various functions to perform specific tasks. For example, the math package includes the sqrt() function to perform the square root of a number.
🌐
Python documentation
docs.python.org › 3 › tutorial › modules.html
6. Modules — Python 3.14.4 documentation
Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A.
🌐
ActiveState
activestate.com › home › blog › top 10 python packages with examples
Top 10 Python Packages with Examples - ActiveState
November 12, 2025 - Additional examples can be found on the pytest website. 8. NumPy: NumPy is the essential package for scientific and mathematical computing in Python. It introduces n-dimensional arrays and matrices, which are necessary when performing sophisticated mathematical operations.
🌐
PyPI
pypi.org
PyPI · The Python Package Index
PyPI helps you find and install software developed and shared by the Python community. Learn about installing packages.
🌐
Tutorialspoint
tutorialspoint.com › python › python_packages.htm
Python - Packages
This will be the Python package we are going to construct. Two Python modules areafunctions.py and mathfunctions.py will be created inside mypackage. Create an empty "__.init__.py" file inside mypackage folder.
Find elsewhere
🌐
Python Course
python-course.eu › python-tutorial › packages.php
31. Packages | Python Tutorial | python-course.eu
November 8, 2023 - Packages are a way of structuring Python’s module namespace by using "dotted module names". A.B stands for a submodule named B in a package named A. Two different packages like P1 and P2 can both have modules with the same name, let's say A, for example. The submodule A of the package P1 ...
🌐
Python Packaging
packaging.python.org
Python Packaging User Guide — Python Packaging User Guide
The Guides section for walk throughs, such as Installing pip/setuptools/wheel with Linux Package Managers or Packaging binary extensions. The Discussions section for in-depth references on topics such as Deploying Python applications or pip vs easy_install.
🌐
Readthedocs
python-packaging.readthedocs.io › en › latest › minimal.html
Minimal Structure - Python Packaging Tutorial - Read the Docs
Here’s an example of what .gitignore should look like for funniest: # Compiled python modules. *.pyc # Setuptools distribution folder. /dist/ # Python egg metadata, regenerated from source files by setuptools. /*.egg-info · The structure described so far is all that’s necessary to create reusable simple packages with no ‘packaging bugs’. If every published Python tool or library used followed these rules, the world would be a better place.
🌐
Tutorial Teacher
tutorialsteacher.com › python › python-package
Python Packages
Ensure that the command prompt is in the parent folder, in this case D:\MyApp.D:\MyApp>pip install mypackage Processing d:\MyApp Installing collected packages: mypack Running setup.py install for mypack ... done Successfully installed mypackage-0.1 · Now mypackage is available for system-wide use and can be imported in any script or interpreter.D:\>python >>> import mypackage >>>mypackage.average(10,20) 15.0 >>>mypackage.power(10,2) 100
🌐
Python Geeks
pythongeeks.org › python geeks › learn python › python packages with examples
Python Packages with Examples - Python Geeks
December 7, 2021 - Although a package is also a directory, the main distinction between these two is that the package contains __init__.py file and the directory doesn’t. The __init__.py file makes an ordinary directory into a Python package.
🌐
Learn Python
learnpython.org › en › Modules_and_Packages
Modules and Packages - Learn Python - Free Interactive Python Tutorial
This file, which can be empty, ... in is a Python package. That way it can be imported the same way as a module. If we create a directory called foo, which marks the package name, we can then create a module inside that package called bar. Then we add the __init__.py file inside the foo directory. To use the module bar, we can import it in two ways: ... In the first example above, we ...
🌐
Python Packaging
packaging.python.org › tutorials › installing-packages
Installing Packages — Python Packaging User Guide
For example, this could return C:\Users\Username\AppData\Roaming\Python36\site-packages so you would need to set your PATH to include C:\Users\Username\AppData\Roaming\Python36\Scripts. You can set your user PATH permanently in the Control Panel.
Top answer
1 of 8
482

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py

create hello.py then write the following function as its content:

def helloworld():
   print("hello")

Then you can import hello:

>>> import hello
>>> hello.helloworld()
'hello'

To group many .py files put them in a folder. Any folder with an __init__.py is considered a module by python and you can call them a package

|-HelloModule
  |_ __init__.py
  |_ hellomodule.py

You can go about with the import statement on your module the usual way.

For more information, see 6.4. Packages.

2 of 8
288

Python 3 - UPDATED 18th November 2015

Found the accepted answer useful, yet wished to expand on several points for the benefit of others based on my own experiences.

Module: A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

Module Example: Assume we have a single python script in the current directory, here I am calling it mymodule.py

The file mymodule.py contains the following code:

def myfunc():
    print("Hello!")

If we run the python3 interpreter from the current directory, we can import and run the function myfunc in the following different ways (you would typically just choose one of the following):

>>> import mymodule
>>> mymodule.myfunc()
Hello!
>>> from mymodule import myfunc
>>> myfunc()
Hello!
>>> from mymodule import *
>>> myfunc()
Hello!

Ok, so that was easy enough.

Now assume you have the need to put this module into its own dedicated folder to provide a module namespace, instead of just running it ad-hoc from the current working directory. This is where it is worth explaining the concept of a package.

Package: Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A. Just like the use of modules saves the authors of different modules from having to worry about each other’s global variable names, the use of dotted module names saves the authors of multi-module packages like NumPy or the Python Imaging Library from having to worry about each other’s module names.

Package Example: Let's now assume we have the following folder and files. Here, mymodule.py is identical to before, and __init__.py is an empty file:

.
└── mypackage
    ├── __init__.py
    └── mymodule.py

The __init__.py files are required to make Python treat the directories as containing packages. For further information, please see the Modules documentation link provided later on.

Our current working directory is one level above the ordinary folder called mypackage

$ ls
mypackage

If we run the python3 interpreter now, we can import and run the module mymodule.py containing the required function myfunc in the following different ways (you would typically just choose one of the following):

>>> import mypackage
>>> from mypackage import mymodule
>>> mymodule.myfunc()
Hello!
>>> import mypackage.mymodule
>>> mypackage.mymodule.myfunc()
Hello!
>>> from mypackage import mymodule
>>> mymodule.myfunc()
Hello!
>>> from mypackage.mymodule import myfunc
>>> myfunc()
Hello!
>>> from mypackage.mymodule import *
>>> myfunc()
Hello!

Assuming Python 3, there is excellent documentation at: Modules

In terms of naming conventions for packages and modules, the general guidelines are given in PEP-0008 - please see Package and Module Names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

🌐
Igmguru
igmguru.com › blog › python-packages
Python Packages: Overview, Uses, and Examples (Updated 2026)
3 days ago - Let's discuss a few important Python package elements- Module: A standalone .py file that holds reusable code (for example, math.py).
🌐
pyOpenSci
pyopensci.org › python-package-guide › tutorials › intro.html
Python packaging 101 — Python Packaging Guide
Pandera is another more broadly used Python package. Pandera supports data testing and thus also has a broader research application. ... At the larger end of the user spectrum, Matplotlib is a great example.
🌐
Py-pkgs
py-pkgs.org › 04-package-structure.html
4. Package structure and distribution — Python Packages
Regardless of whether you import a single, standalone module (i.e., a .py file) or a package (i.e., a directory), Python will create a module object in the current namespace. For example, let’s import the pycounts package we created in Chapter 3: How to package a Python and check its type (recall that this package contains two modules; pycounts.py and plotting.py):
🌐
GitHub
github.com › activescott › python-package-example
GitHub - activescott/python-package-example: A simple example of creating and consuming a distributable Python package.
I can tell you that eggs appear to essentially be deprecated and as noted on the previously linked python.org site Wheel is currently considered the standard for built and binary packaging for Python. Therefore I no longer maintain an example of building eggs, but some docs you might find interesting are as follows: "Python Packages" are documented at https://packaging.python.org/distributing/ and Eggs are documented at http://peak.telecommunity.com/DevCenter/PythonEggs
Starred by 34 users
Forked by 49 users
Languages   Python 74.6% | Shell 25.4% | Python 74.6% | Shell 25.4%