Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 2.16 KB

02_Python_PyPI_Packaging_Cheat_Sheet.md

File metadata and controls

71 lines (49 loc) · 2.16 KB

Creating a Python Package and put it on PyPI

This cheat-sheet shows how to create a Python package and put it on PyPI so everyone can install your awesome library or framework using pip install <your-awesome-package-name>. The main reference is to be found at this link : https://packaging.python.org/tutorials/packaging-projects/.

Step 1 : Register

First thing to do is to register on the PyPI platform using this link : https://pypi.org/account/register/. So now you can have your own account to manage your "online" Python packages.

PyPI reguster

Step 2 : Have the right dependencies

We will need three dependencies to be installed

pip install wheel
pip install setuptools
pip install twine

Step 3 : Create the setup file

The file is self-explanatory, we define all information related to our package or library, like its main name, version we're uploading, the linked github repo etc...

import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
    name="ostorlab",
    version="0.0.0",
    author="Amine LEMAIZI",
    author_email="[email protected]",
    description="A personal machine learning library made for experimental purposes",
    long_description=long_description,
    long_description_content_type="text/markdown",
    url="https://github.com/aminelemaizi/ostorlab",
    packages=setuptools.find_packages(),
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
        "Development Status :: 1 - Planning",
    ],
    python_requires='>=3.6',

Step 4 : Generating source distribution and uploading to PyPI

Generating source distribution

python setup.py sdist bdist_wheel

Uploading source distribution to PyPI

python -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

Now all is clear, all what you need to install your package is internet and run the following command

pip install <your-awesome-package-name>