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 setup.py file. This file contains metadata about your package, such as its name, version, and author. Here's an example:

from setuptools import setup

setup(
    name="mypackage",
    version="1.0.0",
    author="Your Name",
    author_email="your.email@example.com",
    description="A short description of your package",
    long_description=open("README.md").read(),
    long_description_content_type="text/markdown",
    url="https://github.com/yourusername/mypackage",
    packages=["mypackage"],
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)
  • Create a README.md 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 setup.py 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


9 views0 comments

Recent Posts

See All

How to setup reverse proxy on apache2

To set up a reverse proxy to a local installation using Apache2, you need to configure the Apache Virtual Hosts to forward requests to your local server. Here's a step-by-step guide: Enable Proxy Modu

How to Set Up Odoo with Apache Reverse Proxy on Ubuntu

Welcome, adventurous souls, to the whimsical world of Odoo installation! In this zany tutorial, we'll embark on a wild journey to set up Odoo, the beloved open-source ERP software, with an Apache reve

How to Attach S3 to your Django Project

Install Required Packages: Install django-storages package, which provides support for various storage backends including Amazon S3. You can install it via pip: pip install django-storages Configure D

bottom of page