How to Create a Custom Pip Package and Publish

  • Create the account in pypi: https://pypi.org/
  • Create the root folder and sub folder (inside the root folder) as same name.
whirldata-gowtham@whirldata-gowtham:~/magfacy/magfacy$
  • Create the __init__.py, inside the sub folder
def sum(a,b):
return(a+b)
  • Create the setup.py, inside the root folder
import setuptools
setuptools.setup(
name="magfacy",
version="0.0.3",
author="gowthambalusamy",
author_email="xxxxxxxxxxxxx@gmail.com",
description="A small example package",
url="https://github.com/pypa/example-project",
packages=setuptools.find_packages(),
classifiers=(
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
),
)
  • Run the following Commands:
sudo python setup.py sdist bdist_wheel
sudo pip install twine
sudo python -m pip install - upgrade twine
twine upload dist/*
sudo pip install magfacy (or) sudo pip install magfacy==0.0.2
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import magfacy
>>> magfacy.sum(1022,181872)
182894