Python package on PyPI

Python package and publish to PyPI

In this tutorial am using the plotlyplus package as an example. The package can be found at: https://github.com/jgbrainstorm/plotlyplus. In this package, there are two python files, plotplyplus.py and plotlyplus_safe.py. 

Step 1: Structure Your Package

On your local computer, create the folder structure as follow

plotlyplus/

|-- plotlyplus/

|   |-- __init__.py

|   |-- plotlyplus.py

|   |-- plotlyplus_safe.py

|-- tests/

|   |-- __init__.py

|   |-- test_plotlyplus1.py  # Optional but recommended

|   |-- test_plotlyplus2.py  # Optional but recommended

|-- setup.py

|-- README.md

|-- LICENSE

Step 2: Prepare the Package Files

from .plotlyplus import *

from .plotlyplus_safe import *

Here is a template for the setup.py file:

from setuptools import setup, find_packages


setup(

    name='plotlyplus',

    version='0.1.0',

    author='Your Name',

    author_email='your.email@example.com',

    description='Enhance pandas DataFrame with direct Plotly Express plotting functions, including safe versions',

    long_description=open('README.md').read(),

    long_description_content_type='text/markdown',

    url='https://github.com/yourusername/plotlyplus',

    packages=find_packages(),

    classifiers=[

        'Programming Language :: Python :: 3',

        'License :: OSI Approved :: MIT License',

        'Operating System :: OS Independent',

    ],

    install_requires=[

        'pandas>=1.0.0',

        'plotly>=4.0.0'

    ],

    python_requires='>=3.6',

)

Step 3:  Create account at PyPI if you have not yet. 

In the account setting part, create the token. Follow the instruction there to use __token__ as user name and the token as password in the uploading step 5 below. 


Step 4: Building Your Package locally.

python3 -m pip install --user --upgrade setuptools wheel

2.Create the distribution package:

Navigate to the directory containing setup.py and run:

python3 setup.py sdist bdist_wheel

This command should output a lot of text and once completed, will generate files in the dist directory.

Step 5: Uploading the Distribution to PyPI

The recommended tool for uploading your package to PyPI is twine because it securely authenticates you to PyPI over HTTPS.

Step 6: Verifying upload 

go to: https://pypi.org/project/plotlyplus/