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