Publish Python Package with PyPI

PyPI or Python Package Indexing is a great place to publish Python packages, recently I have published a Python package called funmotd to PyPI. Unlike other tutorials, this post is about my experience that I published real working python app and refered many docs to make it work for specific requirement which we will see in a moment.

First, let’s see what is this funmotd package, it’s functionality and build the package according to it.

funmotd Package

The idea is to display famous Movies and TV Shows quotes on Terminal as motd when you open. I want to make the app simple, have local quotes db, should configurable via CLI and easy to install; which boil down below points.

  • The app has local db files (python files)
  • The app has configuration text file
  • The app should accessible via CLI that user can interact
  • Easy to install
├── funmotd
│   ├── config.json
│   ├──
│   └──

Above is my project tree structure which typical file structure for python package.

  • funmotd Directory - Contains actual code ( in funmotd directory indicates that funmotd is package. More info here)
  • - Packages information
  • - Used to specify include/exclude files

Packing with setuptools

setuptools is another python package or module designed to facilitate packaging Python projects. Let’s see step-by-step process, how to pack and publish

0. Prerequisites

Install required packages and create account on

$ sudo pip install setuptools twine

1. Create which is build script like below

import setuptools
from setuptools.command.install import install

      description='TV Show and Movie Quotes MOTD for Terminal',
      author='Veerendra Kakumanu',
      license='Apache 2.0',
      entry_points={'console_scripts': ['funmotd = funmotd:main']},
      package_dir={'funmotd': 'funmotd/'},
      package_data={'funmotd': ['config.json'], },
              "Programming Language :: Python :: 3.4",
              "License :: OSI Approved :: Apache Software License",
              "Development Status :: 4 - Beta"

Most of the arguments are self-explainatory, let’s go through some interesting arguments.


Name of the distribution which should be unique on


List of packages/sub-packages or simply use setuptools.find_packages() finds all pacakges automatically

entry_points as console_scripts

As I said, we want to install package as CLI, with the help console_scripts type entry_points, we can call our function which contains CLI code(argparse). The syntax would be

entry_points={'console_scripts': ['<your_package_name> = <path_to_module>:<function_name>']}

For example, if you have project structure like below and you want to call a function cli_function in which in sub_pkg directory, the syntax should like below

└── my_pkg1
    └── sub_pkg

entry_points={'console_scripts': ['my_pkg1 = my_pkg1.sub_pkg.cli:cli_function']}

If the function that want to call is in, then you just have to specify <pkg_name>:<function_name> like below

entry_points={'console_scripts': ['my_pkg1 = my_pkg1.sub_pkg:cli_function']}
Written on