Creating My First PyPI Package

python

In my efforts to gulp the cool-aid on all things Python, this weekend I uploaded my first package to PyPI. What is PyPI you ask? When you use pip, the default repository used is PyPI. From the official website:

PyPI — the Python Package Index
The Python Package Index is a repository of software for the Python programming language.

The package I wrote is a simple and silly program that outputs a single random Taylor Swift lyric to the console. I called it tay_say. The technical part is easy, I usually find the hardest part of most projects is coming up with an idea

The GitHub repository can be found here: https://github.com/DEV3L/python-tay-say.

tay_say_console

In this blog post, I intend to cover the steps I took to make this simple package.

Follow Peter Downs :
How to submit a package to PyPI

I Google searched on how to upload a package to PyPI and found an awesome tutorial by Peter Downs: http://peterdowns.com/posts/first-time-with-pypi.html

This blog post takes a user from zero to one, in regards to PyPI! It is really thorough and a great resource. In a nutshell the post covers the following steps:

  1. Create PyPI Test and Production accounts
  2. Proper project layout
  3. setup.py construction
  4. Upload to PyPI

These steps get you a empty package up on PyPI.

Add Console Entry Point to setup.py

So missing from the above article is how to create an entry script for you package.

If you look at my example setup.py:

  entry_points={
   'console_scripts': [
     'tay_say = tay_say:print_lyric'
  ]},

The format is pretty simple. It goes ‘<script name> =  <path to module>:<function>’.

My initial test file simply outputted the word ‘test’ to the console. The commit that contains these initial changes to setup.py and test function can be found here.

Final Steps

I incremented the package version in setup.py and uploaded the updated package to PyPI.

Now, as a result anyone with python installed can type ‘pip install tay_say’. Although this is an over simplified example, it opens the door to using pip to install internal or externally hosted package files.

Example install and usage from the command line:

~ pip install tay_say
~ tay_say

 

One thought on “Creating My First PyPI Package

  1. Pingback: PyOhio Presentation 2016 – How To Create Your First PyPI Package | Software Dev3loper

Leave a comment