Python Packages Creation Tutorial – Complete Guide

When it comes to Python, one of the most powerful features it offers is the ability to create and use packages. Similar to packing a suitcase before a trip, Python packages help to organize, modularize, and enable reusable code, making your programming journey much smoother. Whether you are a beginner or a seasoned coder, learning how to create Python packages is an essential skill to have.

What are Python Packages?

In the simplest terms, Python packages are directories that are used to organize modules. Think of them as a closet where you neatly arrange and store your clothes (or in this case, your code). These ‘clothes’ can then be easily reused and accessed when required, without having to recreate or duplicate anything.

What are they used for?

Python packages serve multiple purposes:

  • Organization: They help manage and organize code in a logical manner, making it easier to understand and maintain.
  • Reusability: Packages allow code to be reused across different projects, saving time and effort.
  • Namespace Handling: They prevent naming conflicts by providing unique namespaces for the code.

Why should you learn to create Python Packages?

Learning to create Python packages is akin to learning how to pack efficiently for a trip. You are not just arranging your belongings, but also optimizing space, ensuring easy access and facilitating reusability. It enhances your coding efficiency, code readability, and maintainability, making it a crucial skill in your programming toolkit.

CTA Small Image




Creating Your First Python Package

Considering that you already have Python and an Integrated Development Environment (IDE) installed, let’s get started with creating a simple Python package.

Step 1: Begin by creating a new directory for your package. Let’s name it ‘greetings’.

$ mkdir greetings

Step 2: Now, we need to tell Python that ‘greetings’ is a package. This can be done by creating an empty file named ‘’ inside the ‘greetings’ directory.

$ touch greetings/

With these two simple steps, you’ve created a basic Python package!

Adding Modules to Your Python Package

Step 3: Let’s add a module to our package. Create a Python file named ‘’ within the ‘greetings’ directory.

$ touch greetings/

Step 4: Open ‘’ and write a basic function that prints a greeting message.

def say_hello(name):
    print(f"Hello, {name}!")

Congratulations, you’ve just added a module to your Python package!

Using Your Python Package

Step 5: How do we use the function we created? Create a new Python file in a different directory (For example, the directory above ‘greetings’) and import the module from our package.

import greetings.hello

Step 6: Now, let’s call the ‘say_hello’ function from the ‘hello’ module.


Running this code will output:

Hello, Zenva!

With these steps, you’ve successfully used a Python package that you created. You can add as many modules as you like, making your code organized, reusable, and efficient.

Adding Sub-packages to Your Python Package

Step 7: We can also include a sub-package within our Python package. Let’s create a sub-package named ‘farewell’ within the ‘greetings’ directory.

$ mkdir greetings/farewell
$ touch greetings/farewell/

Step 8: Now, let’s add a new module ‘’ to the ‘farewell’ sub-package.

$ touch greetings/farewell/

Step 9: Open ‘’ and write a function that prints a goodbye message.

def say_goodbye(name):
    print(f"Goodbye, {name}!")

Using Modules from Your Sub-package

Step 10: You can import the ‘bye’ module from the ‘farewell’ sub-package just like any other module.

from greetings.farewell import bye

Step 11: Now, call the ‘say_goodbye’ function from your ‘bye’ module.


Running this code will output:

Goodbye, Zenva!

There you have it – a Python package with sub-packages and multiple modules! As you work on larger projects, you’ll find that Python packages make your code much easier to manage and maintain.

From Package Creation to Mastery with Zenva

Understanding how to create Python packages and modules is just the beginning. At Zenva, we take you from creating simple Python packages to mastering complex programming concepts that can make you a proficient Python developer.

Our courses are designed to be interactive and engaging, providing you with the tools and the knowledge to solve real-world problems, contribute to open-source projects, and even start your own from scratch! Join us as we help you not only learn Python, but master it.

Embark on Your Next Adventure with Zenva

Creating your first Python package is an exciting milestone in your learning journey, but there’s so much more to explore.

The Python Mini-Degree

If you’re looking to immerse deeper into Python, consider taking our Python Mini-Degree which is a comprehensive collection of interactive and engaging courses. This Python Mini-Degree is meticulously designed, encompassing a broad range of topics such as coding basics, algorithms, object-oriented programming, game development, and app development.

With the Python Mini-Degree, we offer project-based courses that allow you to construct your own games, devise algorithms, and develop real-world apps. As a learner, you’ll be guided by experienced instructors, where you can move through the material at your own pace, with 24/7 access to the course content.

A Journey from Beginner to Professional

At Zenva, we cater to learners of all skill levels. The Python Mini-Degree is equally insightful whether you are an absolute beginner with no prior programming experience or an experienced programmer wanting to deepen your understanding. You can conveniently skip ahead to lessons that are relevant and challenging for your level of expertise.

Zenva’s Python Courses

Besides the Python Mini-Degree, we offer a multitude of Python courses tailored to various learning goals and interests. These range from data science to automated testing, making sure we cater for all types of learners.

Why Choose Zenva?

At Zenva, we have supported over 250,000 learners and developers with their educational and professional quests. Our courses not only arm you with valuable knowledge, but also with completion certificates which can boost your career prospects. With our vast catalog of beginner to professional courses in programming, game development, and AI, you can go from novice to professional, all under the experienced wing of Zenva.

Your Future as a Python Developer

Lastly, it’s worth remembering why you embarked on your Python journey. Python is one of the most popular and versatile languages. Python developers are widely sought after, across various industries. The skills you’ve started to develop today, as well as those you’ll gain through continuous learning, will make you a valuable asset in the job market.

Ready to level-up your Python skills? Join us at Zenva, and let’s venture on this rewarding learning journey together.


In the realm of coding, your learning journey is never truly over, thanks in part to the ever-evolving nature of technology. Learning to create Python packages is a useful skill that will greatly enhance your coding efficiency, but there is always more to learn and master!

Whether you’re a beginning coder or looking to refine your existing skills, our robust Python Mini-Degree can provide you the right path forward. At Zenva, the possibilities for growth are endless. So get ready to immerse yourself in an interactive and engaging learning experience, and shape your future in Python development with us today.


Python Blog Image

FINAL DAYS: Unlock coding courses in Unity, Unreal, Python, Godot and more.