How to create and publish 🐍python library from start to 🔚... 
Tags: python, library, pypi
Published: 2021-11-13 03:49:42

<h3>Have you ever thought 💭 how should I create and publish a 🐍 python library<h3>

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.

<h5>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 <a href="https://pypi.org" >pypi</a><h5>

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 


Note 🗒 :- recommended ~ use this python library (my suggestion) named <a href="https://pypi.org/project/auto-file/" >autofile<a> because it generates all required file and folder 📂 needed to create a python library 🔗 link:- https://pypi.org/project/auto-file/


Now, your folder 📂 and files structure look like this :-

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zu0qdbvpht8u87m0g5zi.jpg)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4qn3i0ba9v7pkht3cfi.jpg)

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 <br>install_requires<br> 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 

1st ~ <a href="https://packaging.python.org/tutorials/packaging-projects/" >python officials docs for this <a>

2nd ~ <a href="https://youtu.be/Ttc2bu651VU">youtube video <a>