Keeping Tabs With THW -3

Keeping Tabs With THW -3

Part 3 -- PyPI Push & Usage

If you have been following this mini-series, I am so glad that you did and today we shall hit one of our final droplets in this sequel and upload or push our resources to PyPIfor distribution.

If you missed any part of this series, check it out here.

Creating a PyPI package is easy and I have an introductory article on how you too can easily create and share a resource with anyone out there.

Publishing it to PyPI and then pip installing it will make it available in the site-packages list of Python and we get to use it the usual way we import all other modules.

Assuming you are with me and this is our complete code so far. I won't change anything in that current code but you can go ahead and create a pull request if you want to contribute to it.

Let's create our setup.py file. Before, let's upgrade setup tools & wheel first with;

python -m pip install –-user –-upgrade setuptools wheel

Then the setup file;

import pathlib
from setuptools import setup

# The directory containing this file
HERE = pathlib.Path(__file__).parent

# The text of the README file
README = (HERE / "README.md").read_text()

# This call to setup() does all the work
setup(
    name="thwAPI",
    version="1.1.0",
    description="Keeping Tabs With The Hashnode Writeathon (THW)",
    long_description=README,
    long_description_content_type="text/markdown",
    keywords='Hashnode Writeathon Challenges Blogging Tech',
    url="https://github.com/Ronlin1/THW",
    author="Ronnie Atuhaire",
    author_email="ronlinx6@gmail.com",
    license="MIT",
    install_requires=[
          'requests',
          'progress'
      ],
    classifiers=[
        "License :: OSI Approved :: MIT License",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.10",
    ],
    packages=["thwAPI"],
    include_package_data=True,
    package_dir={'/':'thwAPI'}
)

You can also include a setup.cfg file that has the following data;

[metadata]
description_file=README.md
license_files=LICENSE

Now let's create thwAPI folder and shift all our project code in there;

So let's build our distribution from the setup.py file in the root project:

python setup.py sdist bdist_wheel

Output;

image.png

💨 Upload the sdist on PyPI;

py -m twine upload dist/* --verbose

image.png

--verbose for logging errors and more details

And our project is live;

image.png

Visit it here

Let's pip install thwAPI and create another test file to get to use our own module;

pip show thwAPI would return;

image.png

Please read more about publishing on PyPI here if you did not understand anything.

In our Test_2.py file . Let this test file not be in the root folder of our project, infact create another folder and place it in there or run it completely outside of that folder to test locally on your machine.

# Testing PyPI Upload after pip install
from thwAPI import thw

# print(dir(thw))

# initialize = thw.THW()

API_URLs = ['https://hashnode.com/api/feed/tag/thw-cloud-computing',
            'https://hashnode.com/api/feed/tag/thw-mobile-apps',
            'https://hashnode.com/api/feed/tag/thw-web3',
            'https://hashnode.com/api/feed/tag/thw-web-apps'

            ]


for idx, url in enumerate(API_URLs):
    print(f"API {idx} ; Counter")
    count = thw.THW(url).count()
    print(count)

Estimated count at the time of writing this article;

"""
Estimated Count At the time of execution;
...

Cloud Computing; There are currently 81 posts written!
Mobile Apps ; There are currently 73 posts written!
Web 3 ; There are currently 99 posts written!
Web Apps ; There are currently 264 posts written!
...

"""

You could also add this code for your own testing;

for idx, url in enumerate(API_URLs):
    print(f"API {idx} ; Summary")
    summary = thw.THW(url).all_posts()
    print(summary)

I am still having one post to submit under this mini-serieseven though the #TheHashnodeWriteathon is gaming today.

That article is going to be about automation with GitHub workflows and updating the package at PyPI.

That's it for today! Find all code and the entire project here.

🌟 Conclusion

Once again, hope you learned something today from my little closet.

Please consider subscribing or following me for related content, especially about Tech, Python & General Programming.

You can show extra love by buying me a coffee to support this free content and I am also open to partnerships, technical writing roles, collaborations and Python-related training or roles.

Buy Ronnie A Coffee 📢 You can also follow me on Twitter : ♥ ♥ Waiting for you! 🙂