How to upload your python package to PyPi

joelbarmettlerUZH
May 7, 2018 · 8 min read
Complete Guide of how to upload your package to PyPi and install it via pip. Screenshot: PyPi.org

But what is PyPi?

How to use PyPi

cd "C://PATH//TO//YOUR//DOWNLOADED//FILE"
python get-pip.py
pip install scrapeasy
setx PATH "%PATH%;C://WHERE//PYTHON//IS//INSTALLED//Scripts"
setx PATH "%PATH%;C:\Python36\Scripts"

Make your code publish-ready

if __name__ == "__main__":
your example code goes here

Create a python package

from packagename.Filename import Classname
# Inside of __init__.py
from MyLib.File1 import ClassA, ClassB, ClassC
from MyLib.File2 import ClassX, ClassY, ClassZ

Create a PyPi account

Upload your package to github.com

Create the files PyPi needs

setup.py

from distutils.core import setup
setup(
name = 'YOURPACKAGENAME', # How you named your package folder (MyLib)
packages = ['YOURPACKAGENAME'], # Chose the same as "name"
version = '0.1', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'TYPE YOUR DESCRIPTION HERE', # Give a short description about your library
author = 'YOUR NAME', # Type in your name
author_email = 'your.email@domain.com', # Type in your E-Mail
url = 'https://github.com/user/reponame', # Provide either the link to your github or to your website
download_url = 'https://github.com/user/reponame/archive/v_01.tar.gz', # I explain this later on
keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'validators',
'beautifulsoup4',
],
classifiers=[
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
'Intended Audience :: Developers', # Define that your audience are developers
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License', # Again, pick a license 'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
)

download_url

Install_requires

# In the Class1 File
import numpy as np
from scrapeasy import Webpage
import time
install_requires=[
'numpy',
'scrapeasy',
],

setup.cfg

# Inside of setup.cfg
[metadata]
description-file = README.md

LICENSE.txt

MIT LicenseCopyright (c) 2018 YOUR NAMEPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

README.md (Optional)

Upload your package to PyPi

cd "C://PATH//TO//YOUR//FOLDER"
python setup.py sdist
pip install twine
twine upload dist/*

Install your own package using pip

pip install YOURPACKAGENAME

Change your package

python setup.py sdist
twine upload dist/*
pip install YOURPACKAGE --upgrade

joelbarmettlerUZH

Written by

Student @ University of Zurich UZH Major: Software Systems Minor: Neuroinformatics

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade