0% found this document useful (0 votes)
23 views2 pages

Divya

PyPI is the official software repository for third-party Python packages. It stores all Python packages and libraries that can be installed and managed using pip. When creating a Python package, you must include a __init__.py file in the package directory to tell Python that the directory is a package. Creating a package involves making a directory, adding a __init__.py file, including any sub-packages or files, and accessing the package using import statements.

Uploaded by

divya domandula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Divya

PyPI is the official software repository for third-party Python packages. It stores all Python packages and libraries that can be installed and managed using pip. When creating a Python package, you must include a __init__.py file in the package directory to tell Python that the directory is a package. Creating a package involves making a directory, adding a __init__.py file, including any sub-packages or files, and accessing the package using import statements.

Uploaded by

divya domandula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

If you have been coding in python, even for a while, you must be familiar with the

concept of ‘pip’ by now.


It is a package management system used to install and manage software
packages/libraries written in Python.
Then one may ask that where are all these packages/libraries stored?
It is obvious that there must be a large “on-line repository” which stores all
this code.
And the answer to this question is Python Package Index (PyPI).

PyPI is the official third-party software repository for Python


a
packages makes projects easy to manage and conceptually clear
*python package is a directory containing
@sub packages
@modules
@along with an__init__.py file

We have included a __init__.py, file inside a directory to tell Python that the
current directory is a package.
Whenever you want to create a package, then you have to include __init__.py file
in the directory.
You can write code inside or leave it as blank as your wish. It doesn't bothers
Python.

Follow the below steps to create a package in Python

Create a directory and include a __init__.py file in it to tell Python that the
current directory is a package.
Include other sub-packages or files you want.
Next, access them with the valid import statements.
Let's create a simple package that has the following structure.

Package (university)

__init__.py
student.py
faculty.py
Go to any directory in your laptop or desktop and create the above folder
structure.
After creating the above folder structure include the following code in respective
files.
example:

# student.py
class Student:

def __init__(self, student):


self.name = student['name']
self.gender = student['gender']
self.year = student['year']

def get_student_details(self):
return f"Name: {self.name}\nGender: {self.gender}\nYear: {self.year}"

# faculty.py
class Faculty:
def __init__(self, faculty):
self.name = faculty['name']
self.subject = faculty['subject']

def get_faculty_details(self):
return f"Name: {self.name}\nSubject: {self.subject}"

You might also like