Publish Your Own Python Package

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] what is going on guys welcome back in today's video we're going to learn how to publish your own python package onto pip onto pi pi so that other programmers at home can type pip install your package name and install your module at home and use your functionality in their projects so i'm going to guide you through the process of how to do that in this video and i'm also going to share the story of how i did this for my module for my pip library called witstream so let us get right into it all right so the first thing we're going to do is we're going to take a look at vidstream so that you get a basic idea of what such a project could look like and then we're going to talk about how to do this with your own project with your own idea however i want to mention one thing here pi pi doesn't have a filter for quality so you can literally just publish a hello world package you don't need to publish something useful if you just want to play around now of course i encourage you to publish something useful um and to contribute in a meaningful way to the python community but if you just want to play around and you want to publish an adding script that just adds numbers or a number guessing game or a um i don't know hello world program you can still do that there's no one telling you you're not allowed to publish your hello world package because it's too stupid and too useless so you can publish literally everything here um of course in a legal context you should not do anything illegal but you can just you know publish your hello world script so the basic structure of the project is that you have a setup.py file a license a readme and so on then you have the package itself and in bitstream we just have the streaming.py package um or the streaming.py file with some functionality here but we're not going to get into code actually the only thing that i want to tell you here it's not mandatory to have a github repository but it helps so instead of just having your code locally writing it and then always updating it to pypi which is this platform here i would recommend having a github repository where you can just upload stuff and change stuff and commit stuff and people can write issues and have pull requests and they can fork it and they can work on it and you have a pull request you add their functionality and so on this is something that i would recommend you to do it's not mandatory as far as i know so you can still publish on pi pi without having a github repository but before you do anything i would just recommend publishing this on github here as well so the basic structure is the setup.py file we're going to talk about that in detail but the first step is definitely set up a github repository create a github account click the plus your new repository and just set up the basic repository and then we're going to talk about the structure in it so one thing that you also want to do is you want to go to pipi.org and register for an account and then you want to reserve a name so if you're having for example uh an audio modification library maybe you want to call it audi mod if this name is not already taken it's important that you register that name so that you create a project you don't have to add the code immediately but you just want to create a project and say okay this is audi mod 0 0 1 or something just so that no one else takes the name because if you run a github repository if you create a github repository with that name and you have an audience or something of course you want to make sure that no one takes the name so you create an account here and you register the name all right so the next thing that you want to do is you want to create the library structure or the directory structure that's needed for the library and for this we are going to create a base folder here and inside of that base folder we have the library name folder so another directory with uh the name of the library so hello world one two three or bitstream or numpy and so on and we're going to look at this in the terminal so we're going to navigate to the base folder inside that we have the lip name so the library name and inside of that we have the code so we're going to open this up in vim and you're going to see the directory tree here we basically have the uh the base folder libname and then we have hello.py in here we can put some code i don't know uh we can define a function say hello and it's going to print hello world like that we're going to write that and what we also need to have in that library uh folder is we're going to have an init file so we're going to have an underscore underscore init underscore underscore dot py file and in here we're just going to have the import so we're going to say actually i need to look up the notation i think we need to say from file name and not from the library so we need to save from hello import say hello like that and this is important so that we recognize this as a module so that's the basic structure we have a base folder we have the library name and then we also have the python files in there that we need and an init.py file so that it's recognized as a module with the respective imports all right so the next step is to go ahead and create a setup.py file and we're not going to write it from scratch we're going to use this vidstream setup.py file as a template here so just go ahead to uh the github of neural nine vidstream and then we're going to copy all that here and we're going to run this clear and we're going to create the setup.py file however we're not going to do this in the lip name so we're not going to do this in the actual library folder we're going to do it one level above in the base folder so we're going to say setup.py by the way don't be confused that i'm using the terminal you can just use your desktop system you can use notepad plus plus you can use vs code and all the other editors i'm just going to use the terminal here and what we're going to do is i'm going to set this to paste and i'm going to paste all this here and uh now we have all those things that are very specific to bitstream so we're going to remove some things here for example we're going to remove this information up here and we're going to change the version so we're going to change the version to 0 0 1 for the initial release we're going to change the description to a basic hello package and we're going to change the long description to a basic hello package long description or something like that uh the name of course has to be changed to something else so for example hello p k g abc i don't know what something that's not taken uh then put your author name in here put your email in here uh what do we have here undefined long description oh yeah actually why is it undefined we can actually forget about about the long description here let's just ignore it um then we have packages find packages it's not really important then we have install requires which essentially means uh what do we require when someone installs this particular module for example if you install vidstream you also automatically install opencv and pi autogui because those are important for screen sharing and for camera transmission and so on in this case we're not going to need anything and the keywords are just the keywords i'm going to leave them the same and in the classifiers you can specify some stuff like um the status of the development so are we planning right now are we actually releasing production whatever the intended audience then you can also specify this has worked for python 3 python uh and on what operating system the uh systems does does this work um you're also going to need setup tools i think this is actually a core python module i'm not sure if it's not you're just going to have to say pip3 install setup tools uh but i actually think it's core python so yeah and once we have all that once we have the structure here i'm going to show it once again we have a base folder we have a setup.py file we have a libname folder inside of that libname folder we have the python files and the init.py file again if you need some guidance on the structure you can just check out um check out the project with stream here you can see that we have set up py file here read me md file here license and in here we have uh the same structure right so you can use this as a guideline and once we have that we're going to navigate out of this and we're going to say python 3 setup dot py sdist be dist wheel and it's working and it's creating the package and when we're done we have a bunch of different libraries here we can actually go to the desktop and look at them we have the base folder here and we have all the stuff and the actual thing the actual uh package is now here in the dist folder so this is the thing that we're going to upload to pi pi so last but not least we're going to have to upload this to pi pi and this is very easy we just go into the terminal again uh you can also use cmd on on windows and what we do then is we say pip or pip 3 install twine this is the tool that we're going to use for the upload and it's going to okay for me it's already satisfied so we have twine and what we do with twine is we say twine upload dist slash star so we want to upload the content out of the dist and it's then going to ask for username and password now i'm not going to do this here because i don't want to upload a hello hello package abc i just want to show you the process so what you do here is you follow the whole process that we did up until now you just create a structure you have the setup file you have the init file uh you have the names and and the descriptions and so on then you install twine you you say twine upload dist slash star and here you enter the credentials that you use to sign up or to register on pi pi so when we created an account on pi pi you used certain username you created a certain repository and so on or actually i think it's it's created automatically i'm not even sure about that but basically you enter your username your password and then your package is available in a couple of minutes people should be able to i'm going to abort this here uh people should be able to type pip or pip 3 install your package name so hello p k g abc in this case and they can have all the functionality now this is not a detailed implementation i didn't show you any specific steps on how to structure those those modules how to write the code in an efficient way this is just a basic tutorial on how you can create this structure and how you can publish your own first python package so that's it for this video i hope you enjoyed i hope you learned something if so let me know by hitting the like button and leaving a comment in a comment section down below if you want to see more videos like this on python packages or on how to structure projects for pip and how to actually uh program something useful for pip uh let me know in the comment section maybe i'm going to do more videos on it uh other than that also don't forget to subscribe to this channel and hit the notification bell to not miss a single future video for free and other than that thank you very much for watching see you next video and bye [Music] you
Info
Channel: NeuralNine
Views: 138,142
Rating: undefined out of 5
Keywords: programming, python, pip, package, library, module, publish, publish python package, upload, publish pip package, how to publish python package, how to publish python module, coding, own pip package, own
Id: tEFkHEKypLI
Channel Id: undefined
Length: 11min 26sec (686 seconds)
Published: Fri Feb 12 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.