top of page
  • Writer's pictureRahul R

How to create a python package for distribution

To create a Python package for deployment to PyPI, you can follow these steps:

  • Choose a name for your package and create a new directory with that name.

  • Inside the package directory, create a file. This file contains metadata about your package, such as its name, version, and author. Here's an example:

from setuptools import setup

    author="Your Name",
    description="A short description of your package",
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
  • Create a file in the package directory. This file should contain a detailed description of your package, along with any usage instructions or examples.

  • Create a LICENSE file in the package directory. This file should contain the text of the license under which you're releasing your package.

  • Write your package code and save it in a Python file or a package directory under the same name as your package.

  • Optionally, include any dependencies your package requires in a requirements.txt file.

  • Build your package by running the following command in the package directory:

python sdist bdist_wheel
  • This will create a source distribution (sdist) and a binary distribution (bdist_wheel) of your package in a dist directory.

  • Upload your package to PyPI by running the following command:

twine upload dist/*

This will upload all the distributions in the dist directory to PyPI.

Once your package is uploaded to PyPI, it can be installed using pip. For example:

pip install mypackage

8 views0 comments
bottom of page