Jul. 21st, 2024
2024年 6月 16日

Post: Python packaging Cheatsheet

Python packaging Cheatsheet

Published 08:08 Aug 02, 2020.

Created by @ezra. Categorized in #Programming, and tagged as #Cheatsheet.

Source format: Markdown

Table of Content

Python Packaging

  • [ ] In your files export that classes and functions you want to export.
  • [ ] Create a pypi account
  • [ ] upload your package to
  • [ ] create the files pypi requires
  • setup.cfg
  • [ ] Upload the package to pypi
  • [ ] Maintain package file

Dir structure:


# Inside of
from MyLib.File1 import ClassA, ClassB, ClassC
from MyLib.File2 import ClassX, ClassY, ClassZ

Pypi Required Files

from distutils.core import 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:
  description = 'TYPE YOUR DESCRIPTION HERE',   # Give a short description about your library
  author = 'YOUR NAME',                   # Type in your name
  author_email = '',      # Type in your E-Mail
  url = '',   # Provide either the link to your github or to your website
  download_url = '',    # I explain this later on
  keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'],   # Keywords that define your package best
  install_requires=[            # I get to this in a second
    '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 -- You have previously uploaded your project to your github repository. Now, we create a new release version of your project on github. This release will then be downloaded by anyone that runs the “pip install YourPackage” command.
  • install_requires -- Here, you define all the dependencies your package has — all the pip packages that you are importing.


# Inside of setup.cfg
description-file =

Uploading the package to pypi

Now, we create a source distribution with the following command:

$ python sdist

We will need twine for the upload process, so first install twine via pip:

$ pip install twine

Then, run the following command:

$ twine upload dist/*

You will be asked to provide your username and password. Provide the credentials you used to register to PyPi earlier.

Maintain Package

Simply upload your new code to github, create a new release, then adapt the file (new download_url — according to your new release tag, new version), then run the and the twin command again (navigate to your folder first!)

python sdist
twine upload dist/*

Finally, update your package via pip to see whether your changes worked:

pip install YOURPACKAGE --upgrade
Pinned Message
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF