21
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
Note 🗒 :- recommended ~ use this python library (my suggestion) named autofile 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 :-
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
2nd ~ youtube video
21