How to publish your own Python library on PyPI

Source: Internet
Author: User

Background

Recent interest has written several Python libraries, also published on the PyPI, although no one to download, but they are used on other machines will be very convenient. Here I will show you how to publish your own Python library on PyPI.

Prepare to register your account

It is obvious to register an account with PyPI.

Install the necessary library Setuptools

The environment in which PIP is installed in principle has setuptools, but does not affect you to try to upgrade it.

pip install --upgrade setuptools
Twine

This is a tool that simplifies the process of publishing libraries to PyPI, which is described later in the use.

pip install --upgrade setuptools
Clone Warehouse (recommended)

The famous requests library of the author of the Great God Kennethreitz for everyone to prepare a warehouse as a setup.py good template, of course you can also hand-written setup.py.

clone  https://github.com/kennethreitz/setup.py
Coded edit setup.py

We recommend that you directly edit the setup.py in the previous warehouse, only need to modify some of the necessary configuration. This is the configuration of the library Condition_chain I wrote recently.

...# Package meta-data.NAME = ‘condition_chain‘DESCRIPTION = ‘Process a series of conditional judgement with a chained call.‘URL = ‘https://github.com/duyixian1234/condition_chain‘EMAIL = ‘[email protected]‘AUTHOR = ‘Yixian Du‘# What packages are required for this module to be executed?REQUIRED = [ # ‘requests‘, ‘maya‘, ‘records‘,]...
Writing Core Code

Next we can write our own code, note that the Source code folder (the My_package folder in the warehouse) name and setup.py in the configuration of the package name (name) to be consistent.
Also before re-uploading, we need to change the version number in the __version__.py to avoid overwriting the previous upload (believe that someone will need the previous version of the library).
The final code structure

│  LICENSE│  MANIFEST.in│  README.rst│  setup.py│└─condition_chain        core.py        __init__.py        __version__.py
Package upload

Run the following command under Setup.py's sibling directory.

python setup.py sdist bdist_wheel

And then run

twine upload dist/*

Note To enter the PyPI account number and password.

Done

After that we can search our own Python library in PyPI, and of course we can install it directly from PIP.

How to publish your own Python library on PyPI

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.