Publishing Python Modules with PIP via PyPi

We'll install so many packages in our day to day python development. Now in this blog  post, we'll try to know how to create our own python module installable with PIP. In this blog post we'll make our own package installable with PIP using  PyPI. PyPI is the default Package Index for the Python community. It is open to all Python developers to consume and distribute their distributions.

To make a python module installable with PIP via PyPI the follwoing files are to be included in your project:

  1. setup.py:
    This is the major file that makes our normal python module to an installable package. The major part of setup.py is that it contains a global setup() function. The keyword arguments those being  passed to this function define some specific details of your project like name, version, description etc., The following are the few arguments that we pass frequently to the function.
    1. name:
      name='django-simple-pagination'
      This is the name of your project, and will determine how your project is listed on PyPI. For name should follow PEP426 naming convensions.
    2. version:
      version='0.1'
      This is the current version of your project, allowing your users to determine whether or not they have the latest version, and to indicate which specific versions that the users can install. Versions are displayed on PyPI for each release if you publish your project.
    3. description:
      description='A simple pagination app for Django'
      long_description=README
      These  will give short and long description for your project. These values will be displayed on PyPI if you publish your project.
    4. url:
      url='https://github.com/MicroPyramid/django-simple-pagination'
      This is the url where your projecct code is placed, generally it is a git url for your project.
    5. author:
      author='Ashwin',
      author_email='ashwin@micropyramid.com'
      Provides details about the author like author and author email.
    6. classifiers:
              classifiers=[
                          # How mature is this project? Common values are
      		    'Development Status :: 3 - Alpha',
                          # Indicate who your project is intended for
      		    'Intended Audience :: Developers',
                          'Environment :: Web Environment',
                          'Framework :: Django',
      		    'Topic :: Software Development :: Build Tools',
                          # Pick your license as you wish (should match "license" above)
      		    'License :: OSI Approved :: MIT License',
                          # Specify all Python versions you support here.
      		    'Programming Language :: Python :: 2',
      		    'Programming Language :: Python :: 2.6',
      		    'Programming Language :: Python :: 2.7',
      		    'Programming Language :: Python :: 3',
      		    ],
      For a full listing, see https://pypi.python.org/pypi?%3Aaction=list_classifiers.
    7. packages:
      packages=['simple_pagination', 'simple_pagination.migrations', 'simple_pagination.templatetags'] or
      packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
      
      Packages is the list of the packages to be included in your project. They can be listed manually or find using setuptools.find_packages automatically. Use the exclude keyword argument to omit packages that are not intended to be released and installed.
    8. install_requires:
      install_requires=['django']
      “install_requires” is the list of modules what dependencies a project minimally needs to run. When the project is installed by pip, these will be installed automatically.
    9. include_package_data:
      include_package_data = True
      This tells the sdist command whether to include package data or not.
  2. README.rst:
    All projects should contain a readme file that covers the brief documentation of the project. The most common format is reStructuredText with an “rst” extension.

  3. MANIFEST.in:

    A MANIFEST.in file can be added in a project to define the list of files to include in the distribution built by the sdist command. When sdist is run, it will look for the MANIFEST.in file and interpret it to generate the MANIFEST file that contains the list of files that will be included in the package. This mechanism can be used when the default list of files is not enough. The following is the simple MANIFEST.in file.

    	include README.rst
    	recursive-include simple_pagination/templates *
    The recursive-include tells sdist to include all files anywhere under the simple_pagination/templates directory.

After adding all the above files in your app, now your project is ready to be pushed into PyPI.

Uploading our project to PyPI:

  1. Create an account in PyPI.
  2. Reguster your app to PyPI using following command.
    python setup.py register -r pypi
  3. Upload your distribution to PyPI using the follwoing command.
    python setup.py sdist upload -r pypi

With this proceedure we can make our app to be installable as a python package.

Note: If we edit and try to push the code it won't accept, we have to change its version for every code push.

Posted On 02 August 2012 By MicroPyramid


Need any Help in your Project?Let's Talk

Latest Comments
Unit testing with selenium-python

Unit testing with selenium-python. Unit test case example to test the front-end

Continue Reading...
Tips to choose the best custom software development company

Choosing the best company for your software development needs is the most important step. This blog explains you tips to outsource custom software development services.

Continue Reading...
WSGI explanation with simple APP

The main goal of WSGI is to facilitate easy interconnection of servers and web frameworks/applications. WSGI defines a standerd API for web servers(uWSGI, Twisted, Gunicorn) …

Continue Reading...
Understanding self and __init__ method in python Class.

Understand self and __init__ method in python Class?
Before understanding the "self" and "__init__" methods in python class, it's very helpful if we have the idea …

Continue Reading...
List of python class special methods or magic methods

python class special methods or magic methods. magic methods allow us to override or add the default functionality of python objects. One of the biggest …

Continue Reading...
Building and Parsing XML Document using Python

Creating XML document with required elements, Then Parsing it using Python to generate a serialized form of its contents.

Continue Reading...
Working with python collections Counter

Python collections - Counter is to count the frequency of character, OrderedDict is to track the order of the contents in which they are added …

Continue Reading...
Python to Debian package: Simple, Easy and Fast

Packaging python script to debian follows strict instructions, using the following instructions, most of the steps can be skipped hence making it easy and fast.
If …

Continue Reading...
Sending SMS, MMS using Twilio.

A simple Tutorial on sending SMS and MMS in python using Twilio. In this tutorial you will learn how to send SMS, MMS and checking …

Continue Reading...
Customize and Embed Vimeo Videos using Python Requests.

Using python requests and vimeo endpoints it becomes very easy and simple to upload our videos and customize them.

Vimeo Access token:
1. Create an …

Continue Reading...
Getting Started with the IPython Notebook

IPython is a set of tools developed to make it easier for the programmers to work with Python and data. IPython provides extensions to the …

Continue Reading...
Python Arrow To Show Human Friendly Time

Arrow is a python library and command-line tool to genrerate, manipulate dates, times, timestamps.
use of arrow:
With the use of arrow, we can also create, manipulate, …

Continue Reading...
Working with python collections part 1

Python Collections - named tuple is to access by the names specified and deque is to append and pop the elements from both sides of …

Continue Reading...
Building Documentation with readthedocs

In this blog, I'm going to explain you how to write the Sphinx docs using reStructuredText to host in the Read the Docs.

Installing Sphinx

Continue Reading...
Create excel file, Insert image, Draw Bar Graphs in excel files in python using xlsxwriter

Xlsxwriter is a python module through which we can write data to Excel 2007+ XLSX file format. In this blog post we learn to write …

Continue Reading...
Integrate Twitter Social API into Django App

Integrating Twitter sign in (OAuth) in Django App, which includes
1. Capturing username via Twitter Login
2. Updating authenticated user current status on twitter(tweets).

Continue Reading...
How to implement Case Insensitive CSV DictReader in python

In general use cases we upload the CSV files to the system to store huge amount of data by uploading single file. For example in …

Continue Reading...
Python using yield and generators.

Generators are memory efficient. They allow us to code with minimum intermediate arguments, less data structures. Generators are of two types, generator expressions and generator …

Continue Reading...
Introduction to Object Oriented Programming with Python 3

Introduction to Object Oriented Programming with Python

Continue Reading...
Python Coding Techniques and Programming Practices

Coding techniques and programming practices are one of the features of a professional programmer. While writing code to solve a problem programmer should make simple …

Continue Reading...
FABRIC – LEARNING PART 2

Using Fabric, we can develop interactive script for ec2 region, ec2 flavour amazon web services. For this, you need aws account, security group, key pair, …

Continue Reading...
Generating PDF Files in Python using xhtml2pdf

There are many ways for generating PDF in python. In this post I will be presenting PDF files generation with xhtml2pdf.

xhtml2pdf: xhtml2pdf is a …

Continue Reading...
Using Python xlwt generating CSV writer and Excel files

In most of the cases, you need to export the data from your database to different formats. In this post I will show you how …

Continue Reading...
How to access development server publicly using Localtunnel

We do need to expose our local server to hit call-back URLs while programming with other APIs. There is a tool called local tunnel from …

Continue Reading...
How to generate PDF Files from HTML In Python using PDFKIT

There are many approches for generating PDF in python. pdfkit is one of the better approache as, it renders HTML into PDF with various image …

Continue Reading...
Converting Audio and Video files using FFMPEG Tool

FFMPEG is a command-line tool that converts audio or video to required formats, which handle multimedia data. It can also capture and encode in real-time.

Continue Reading...
Python Web Scraping with Beautiful soup

Download all One Piece animation series episodes by scraping site using BeautifulSoup python library.

Continue Reading...
Publishing Python Modules with PIP via PyPi

We'll install so many packages in our day to day python development. Now in this blog post, we'll try to know how to create our …

Continue Reading...
Programming with python: Decorators

Python decorators supports aspect-oriented programming. It is used to add or modify code in functions or classes. Using decorators will provide security, tracing, looking ..etc …

Continue Reading...
Vim for Python Web Development

Having a good environment setup is important for effective, fast and easy coding. We have different IDE's like eclipse, pycharm, sublime etc.. which are powerful …

Continue Reading...
Understanding Python Properties

Python Properties is a class for managing class attributes in Python. Property( ) is a built-in function that creates and returns a property object

Syntax:
attribute_name …

Continue Reading...
QRCode generation in python

A Quick Response code(QRCode) is a two-dimensional pictographic code used for its fast readability and comparatively large storage capacity. The code consists of black modules …

Continue Reading...
Understanding Audio Quality: Bit Rate, Sample Rate

Audio Quality is the accuracy and enjoyability of the audio which the user can listen from an electronic device. Audio quality depends upon the bit …

Continue Reading...
Programming with python Descriptors (_get_, _set_, _delete_) - MicroPyramid

Python descriptors are object attributes that are only invoked for new style of classes. Python descriptors comes under the category of meta programming(code that manipulates …

Continue Reading...
Debugging in Python

When something goes wrong with your code instead of using standard debugging techniques such as print statements use debugging tools. I found two great tools …

Continue Reading...
Python development environment on windows

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of …

Continue Reading...

Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
* We don't provide your email contact details to any third parties