How to create and publish 🐍python library from start to πŸ”š...

Have you ever thought πŸ’­ how should I create and publish a 🐍 python library

I will guide you through all the process. And yes, I am also goona to disccus about other stuff that will be required if you are goona to create some big library.

So, starting from scratch first, let's talk what is a python library βœ”οΈ
Well, a python library contains some function that help you to make your work easy. So, you don't have to write πŸ“ code from scratch πŸ‘Œ we'll, I hope all of you understood what I want to say if not then let take a quick example so, imagine a scenario where you are making a python program to edit a image in this case you are probably you need python library because you don't wanna to write πŸ“ the thousand lines of codes
Currently all python libraries are on pypi

Currently there are around 338,584 projects on pypi you can check out website to get exact numbers

Now, lets look at how to create a library πŸŒ€

First we need to create a folder πŸ“‚ and remember this folder name should be libraryname-master

Note πŸ—’ :- it's not necessary to name the folder same as library name but for convince still recommended πŸ˜€

inside this folder πŸ“‚ create another folder with name same to your library name

Inside this folder πŸ“‚ create some files here is list πŸ“ƒ of them

List of files:_

init.py, function.py, setup.py, readme.md, License, as your need like .gitgnore and more

Now, your folder πŸ“‚ and files structure look like this :-

Now, after creating all necessary files and folders you need to open setup.py file and write πŸ“ the following code :-

Code explanation :-

Actually this is very simple to understand because there nothing hard keyword all are simple and yes, if you dont understood what the code is comment down πŸ‘‡ bellow
Still some code are hard so, I am explaining
One thing is
install_requires
it's basically means if your library requires any other libraries if yes then write their name with commans

Now, in readme.md add the description and in function.py write πŸ“ all the function required for your library example:-

Class test():
def test():
print("test")

So, this method return test when called like this write all your code in function.py and you can also create new files if your code goes big

Now, in init.py write πŸ“ following code

from .function import test
Basically you have import all files in this folder remember write .filename

Now all done
Open terminal navigate to libraryname-main directory and write "setup.py sdist bdist_wheel"
After this, you will see new files and folders πŸ“‚ in your project
Don't edit them just open terminal and navigate to

Libraryname-main>dist

Inside DIST you see a file with extension .whl

Just type "pip install and that file name"

Test you library

And finally time to publish open terminal and type "twine upload dist"
And finally this command ask you for username and password you can create a account on pypi to get them

Everything done

Refer to these for more clear and revlant information :-

recommended

21