Open In App

How to Publish Python package at PyPi using Twine module?

Python is so flexible and easy to use because of its available packages that are hosted on pypi.org, Let’s see how to publish your own package on PyPi using Twine module.

Requirements:

pip install twine

Steps to publish package:

Step 1: Prepare and organize the package



For the sub-folder akshaypawar-tut:



Step 2: Creating README.md file

The .md files are mark down files just as markup languages, it has it’s own syntax,it is used as a User-Friendly Readme file which will be displayed on home page.

You may use extensions for VS Code or any online editors like https://dillinger.io/ to create >Readme.md .

Step3: Creating License.txt file

Your package must have license, If you don’t have any concern to sharing it all over world you may use License.txt. If your package has policies you may use any online license maker website like https://choosealicense.com/ .

Step 4: Create Setup.py File

Your package must have a Setup.py file as it’s one of binding component of package, It describes dependencies of the package and author version, etc.

Below is the code for general Setup.py . One needs to use their own credentials. 




import setuptools
  
with open("README.md", "r") as fh:
    long_description = fh.read()
  
setuptools.setup(
    # Here is the module name.
    name="akshaypawar_tut",
  
    # version of the module
    version="0.0.1",
  
    # Name of Author
    author="Akshay Pawar",
  
    # your Email address
    author_email="akshaygpawar15@gmail.com",
  
    # #Small Description about module
    # description="adding number",
  
    # long_description=long_description,
  
    # Specifying that we are using markdown file for description
    long_description=long_description,
    long_description_content_type="text/markdown",
  
    # Any link to reach this module, ***if*** you have any webpage or github profile
    # url="https://github.com/username/",
    packages=setuptools.find_packages(),
  
  
    # if module has dependencies i.e. if your package rely on other package at pypi.org
    # then you must add there, in order to download every requirement of package
  
  
  
    #     install_requires=[
    #      "package1",
    #    "package2",
    #    ],
  
  
    license="MIT",
  
    # classifiers like program is suitable for python3, just leave as it is.
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
)

Step 5: Final Stage

Here you have to create account on pypi.org also we will be using twine library. The whole package is uploaded in the form of .dist file.

To create .dist file use command:

# Windows
python setup.py bdist_wheel 

or 

# Linux/Mac
python3 setup.py bdist_wheel 

You will observe this message on Powershell when the above commands are executed.

Now our binary .dist file is created, now we need to upload it using the below command:

twine upload dist/* 

Enter the required credentials regarding pypi.org account and the package will be uploaded.

After successful upload you will get a link of your project and all the details 


Article Tags :