loading...
Cover image for How I published my first pip package

How I published my first pip package

prashantsengar profile image Prashant Sengar ・2 min read

This is my first article on DEV and first article related to programming.
I am a programming student and I am full of joy today as I published my first package on Pypi.
This article will contain the things that I did to complete the feat.

1. Writing the code:

My package is a Python wrapper to download images from Reddit. It consists of a class that consists of a method that takes the input - an user-agent, subreddit name, and other inputs.
To write the code to be uploaded as a package, you need to modularize it well. Each line of code should be inside a function or a class.
Writing objective of the program first will help in the process. Drawing flowcharts and/or for writing an algorithm will help as well.
Follow the PEP-8 guidelines in your code.

2. Testing the code:

After you have written the code, a dry run should be the first step to figure out if there is a bug in your code.

If you do not find any bug in the dry run, then test your code.
Write a small script that imports your module and uses all the functions in it.

If you do not find any bug in the test, voila, move on to the next step.
If you find a bug, track it down and remove it.

3. Code review (optional):

Although this step is optional, it is the most important one. Getting your code reviewed by other programmers is the best thing you can do. Other people can find bugs or bad programming practices in your code better than you can do.
Hence, it is highly recommended to do this step.
I learned a lot in this process and you will too.

Places where you can get your code reviewed-

4. Setting up the package for uploading and uploading the package

Writing a good Readme and uploading the code to Github should be the first step before uploading
There's a whole documentation of getting your package ready for uploading on PyPi but it misses a lot of details.
I would recommend reading this article by joelbarmettlerUZH.

Your package is finally uploaded to PyPi and it is available for users to use. Spread the word!

Here is the link to the Github repo of my package - https://github.com/prashantsengar/RedPy

Discussion

pic
Editor guide