1
00:00:00,500 --> 00:00:01,600
Hey, welcome back.

2
00:00:01,609 --> 00:00:10,100
In this video, we're going to upload our package to the Internet to Pi Pi, the Python package index.

3
00:00:10,250 --> 00:00:16,970
So all packages that we install are actually stored in the Python package index.

4
00:00:16,970 --> 00:00:26,720
So if you do Pip install pandas as a user, you are installing pandas from this website.

5
00:00:26,720 --> 00:00:30,770
So we want to have our package listed in here.

6
00:00:30,770 --> 00:00:35,300
So for example, if you search for pandas, it shows the Pandas package.

7
00:00:35,300 --> 00:00:39,560
So we want to be able to search for our package here as well.

8
00:00:39,570 --> 00:00:41,090
Let's see how we can do that.

9
00:00:41,120 --> 00:00:43,070
We need to go to PyCharm again.

10
00:00:43,070 --> 00:00:50,690
So make sure that invoicing is here with these two files so everything looks good on my end.

11
00:00:50,720 --> 00:00:57,560
You can close these files and you need to create a setup.py file here.

12
00:00:57,560 --> 00:01:04,319
Now I've uploaded a setup.py file in the lecture resources so you can download that file and just paste

13
00:01:04,319 --> 00:01:06,840
it here instead of creating it from scratch.

14
00:01:08,540 --> 00:01:10,220
So that's the file.

15
00:01:10,580 --> 00:01:12,700
I'm going to paste it in here.

16
00:01:12,710 --> 00:01:18,200
So you see now setup dot pi is in the same directory with invoicing.

17
00:01:18,500 --> 00:01:23,060
You see they are both inside this root directory.

18
00:01:23,180 --> 00:01:23,750
Now.

19
00:01:23,750 --> 00:01:24,770
Setup dot pi.

20
00:01:24,800 --> 00:01:25,650
What is it?

21
00:01:25,670 --> 00:01:32,150
Well, this file specifies the parameters for creating the package.

22
00:01:32,150 --> 00:01:39,290
So I've already written out the details of the package and I'll explain them now for you.

23
00:01:39,290 --> 00:01:43,730
So here we import this setup function from setup tools.

24
00:01:43,760 --> 00:01:45,740
This is a standard library.

25
00:01:45,890 --> 00:01:50,420
It's used to create packages and then we call that function.

26
00:01:50,420 --> 00:01:54,380
Here you see the opening parentheses and the closing parentheses here.

27
00:01:54,380 --> 00:01:57,670
So this function gets multiple arguments.

28
00:01:57,670 --> 00:01:59,120
So that's the first argument.

29
00:01:59,120 --> 00:02:03,920
So that is the name arguments and it gets the name of the package.

30
00:02:03,920 --> 00:02:05,900
So we want to call it invoicing.

31
00:02:05,900 --> 00:02:07,700
For example.

32
00:02:07,700 --> 00:02:15,200
Now, before deciding on the name, you want to first make sure that there is no other package with

33
00:02:15,200 --> 00:02:16,010
that name.

34
00:02:16,010 --> 00:02:22,610
So search for that name, invoicing or copy it here and paste it here so that you can make sure you

35
00:02:22,610 --> 00:02:29,900
are typing the correct name and you will see that there is actually a package made by someone already

36
00:02:29,900 --> 00:02:35,300
for generating from that text templates invoicing.

37
00:02:35,420 --> 00:02:41,180
So that means this name is occupied and you want to come up with something else.

38
00:02:41,360 --> 00:02:45,140
Perhaps invoicing pdf press enter.

39
00:02:46,170 --> 00:02:49,200
And this name seems to be available.

40
00:02:49,200 --> 00:02:54,270
So we would go here and say invoicing minus PDF.

41
00:02:54,510 --> 00:03:00,270
Then we go to the packages arguments that is set to a list in case.

42
00:03:00,270 --> 00:03:02,100
In case you have multiple packages.

43
00:03:02,100 --> 00:03:05,970
We have only one package here invoicing and that's the name of the package.

44
00:03:05,970 --> 00:03:12,060
So that should reflect that the users will install using this name.

45
00:03:12,060 --> 00:03:15,870
So that's the actual name or the official name of the package.

46
00:03:15,870 --> 00:03:20,550
The version here is 1.0.0 since this is the first release.

47
00:03:20,550 --> 00:03:22,530
So that is the default.

48
00:03:22,740 --> 00:03:25,620
This is a license on how to use the package.

49
00:03:25,620 --> 00:03:31,680
So you can search for this on Google to learn more about this sort of license.

50
00:03:31,680 --> 00:03:36,540
So it means everybody is basically free to use this license, this package.

51
00:03:36,960 --> 00:03:43,200
The description here, I gave a short description to this package.

52
00:03:43,200 --> 00:03:48,730
So just a string divided by a comma, of course, because it's multiple arguments.

53
00:03:48,760 --> 00:03:50,920
The author is my name here.

54
00:03:51,760 --> 00:03:57,340
I would like to reformat this code, actually reformat the file so we don't need these spaces between

55
00:03:57,340 --> 00:03:59,110
the assignment operator.

56
00:03:59,890 --> 00:04:01,090
So that's my name.

57
00:04:01,420 --> 00:04:03,760
This should be your email address.

58
00:04:03,940 --> 00:04:10,960
It's fine if you just write some dummy email address there, your URL of your website as well, the

59
00:04:10,960 --> 00:04:11,620
keywords.

60
00:04:11,740 --> 00:04:16,120
So you want people to search for your package.

61
00:04:16,120 --> 00:04:22,180
So you want some keywords that should show your package if the users happen to to search for any of

62
00:04:22,180 --> 00:04:22,930
these keywords.

63
00:04:22,930 --> 00:04:26,530
So just write a list of multiple strings.

64
00:04:26,530 --> 00:04:28,300
Install requires.

65
00:04:28,300 --> 00:04:35,770
This argument Specifies what dependencies should be installed for your package to work correctly.

66
00:04:35,770 --> 00:04:46,150
So our package you can see it has the pandas, the Globe Fpdf and Pathlib libraries also OS, but here

67
00:04:46,180 --> 00:04:49,960
pandas and Fpdf are third party libraries.

68
00:04:49,960 --> 00:04:52,030
Therefore we need them in here.

69
00:04:52,030 --> 00:04:53,710
O also needs pandas here.

70
00:04:53,710 --> 00:04:54,640
I forgot it.

71
00:04:55,540 --> 00:05:00,700
So pandas fpdf also open pi XL.

72
00:05:00,730 --> 00:05:08,050
Even though this is not imported, we know that it's a dependency when reading Excel files with pandas.

73
00:05:08,050 --> 00:05:10,150
So that should be included there as well.

74
00:05:10,150 --> 00:05:17,020
Even though it's not imported, then we have the classifier classifiers argument, which is some metadata

75
00:05:17,020 --> 00:05:18,820
about the package.

76
00:05:18,820 --> 00:05:28,330
So the development status alpha intended audience and also the Python versions it supports.

77
00:05:28,420 --> 00:05:29,620
And yeah, that's it.

78
00:05:29,650 --> 00:05:35,380
You can save this file, close it, close that file as well.

79
00:05:35,620 --> 00:05:37,720
And you want to go to the terminal.

80
00:05:42,100 --> 00:05:46,990
And we want to do python setup.py.

81
00:05:47,020 --> 00:05:53,380
So I am in the root directory so I can access setup.py which also is in the root directory.

82
00:05:53,680 --> 00:05:55,450
S dist.

83
00:05:55,780 --> 00:05:56,740
Press enter.

84
00:05:58,160 --> 00:06:04,100
And reload the root directory and it will show you this dist directory.

85
00:06:05,120 --> 00:06:11,360
And that's something we need to upload now to the Python package index.

86
00:06:11,360 --> 00:06:14,870
To do the uploading you need a library called Twine.

87
00:06:14,870 --> 00:06:21,200
So please do Pip install twine in your terminal.

88
00:06:22,980 --> 00:06:25,980
That will install the twine third party library.

89
00:06:26,340 --> 00:06:30,000
And then you do twine upload.

90
00:06:31,020 --> 00:06:39,900
Minus, minus, skip minus existing dist and you want to upload everything from the dist folder.

91
00:06:39,900 --> 00:06:42,810
So that's a command you should run.

92
00:06:42,810 --> 00:06:44,790
So press enter to run that.

93
00:06:45,900 --> 00:06:47,130
Oh, I made a typo.

94
00:06:47,160 --> 00:06:48,370
Upload pad.

95
00:06:48,390 --> 00:06:49,080
Sorry.

96
00:06:51,070 --> 00:06:52,420
Let's run it again.

97
00:06:54,230 --> 00:06:55,160
Enter username.

98
00:06:55,160 --> 00:07:00,530
Now you need an account on the package index.

99
00:07:00,530 --> 00:07:06,640
So make sure to register and then try to log in to make sure the registration is successful.

100
00:07:06,650 --> 00:07:10,670
So I'm logging in with my username and my password here.

101
00:07:12,130 --> 00:07:13,250
So that's my account.

102
00:07:13,270 --> 00:07:21,010
Therefore, as username, I'll type in my username in here press enter and then you need to type in

103
00:07:21,010 --> 00:07:22,120
your password.

104
00:07:22,660 --> 00:07:26,110
So I'm pasting my password since I copied it before.

105
00:07:27,050 --> 00:07:28,610
It will be invisible.

106
00:07:28,610 --> 00:07:33,350
So even though you are typing it or pasting it, you will not see it, but you can press enter and be

107
00:07:33,350 --> 00:07:36,020
sure that it will be recognized.

108
00:07:36,020 --> 00:07:38,960
So that was my username and password for pi.

109
00:07:39,000 --> 00:07:39,370
Pi.

110
00:07:40,100 --> 00:07:42,140
And so my uploading was successful.

111
00:07:42,140 --> 00:07:44,000
I can view my package at this.

112
00:07:45,190 --> 00:07:45,790
Page.

113
00:07:45,790 --> 00:07:47,130
So there we go.

114
00:07:47,140 --> 00:07:52,380
Invoicing minus PDF 1.0 0.0 and you can install it with this command.

115
00:07:52,390 --> 00:07:57,340
So just copy that command and let's install it as a user.

116
00:07:57,960 --> 00:08:01,010
So let's install with that command Pip install invoicing.

117
00:08:01,020 --> 00:08:03,030
The last part here is not necessary.

118
00:08:03,030 --> 00:08:07,590
So if you want to install this particular version, you should do this.

119
00:08:07,590 --> 00:08:11,010
In this case we only have one version, so it doesn't make any difference.

120
00:08:11,010 --> 00:08:13,740
But I'll just do the general command.

121
00:08:13,740 --> 00:08:15,870
So that was successfully installed.

122
00:08:15,870 --> 00:08:17,280
Let's try it now.

123
00:08:17,700 --> 00:08:22,050
But I want to create a directory here.

124
00:08:22,050 --> 00:08:28,650
Just write test and inside this directory I want to create a main.py file.

125
00:08:28,650 --> 00:08:33,360
Why didn't I put main dot pi in the root directory you would ask?

126
00:08:33,390 --> 00:08:41,520
Because if I did that and then I imported invoicing that would import the local package, not the actual

127
00:08:41,520 --> 00:08:42,690
package which we installed.

128
00:08:42,690 --> 00:08:49,320
So I'm doing this nesting here so that I make sure that I'm not importing any local files.

129
00:08:49,680 --> 00:08:50,280
Right.

130
00:08:50,280 --> 00:08:55,860
And then you want to do from invoicing import invoice rates.

131
00:08:57,210 --> 00:09:00,000
And then you use it as invoice generate.

132
00:09:00,030 --> 00:09:04,590
Now, you would ask, well, should we do invoicing PDF?

133
00:09:04,620 --> 00:09:10,920
Well, no, because this is like the official name of the package which is the name of the package is

134
00:09:10,920 --> 00:09:12,810
listed on pi pi.

135
00:09:12,840 --> 00:09:16,620
So this one and also the name you use for installing.

136
00:09:16,620 --> 00:09:24,840
However, when you import it, you should import the name of the package You remember in Setup.py we

137
00:09:24,840 --> 00:09:25,740
had this.

138
00:09:26,280 --> 00:09:27,210
That's the name.

139
00:09:27,210 --> 00:09:28,860
That's the package.

140
00:09:28,860 --> 00:09:33,480
So you are importing this name now in Main.py, right?

141
00:09:33,570 --> 00:09:39,990
Usually, though, the name here of the package, the official name is the name as the the practical

142
00:09:39,990 --> 00:09:41,310
name of the package.

143
00:09:41,310 --> 00:09:42,900
That's usually the case.

144
00:09:42,900 --> 00:09:50,250
There are cases, though, like scikit, learn that library has a scikit learn name, the official name,

145
00:09:50,250 --> 00:09:53,580
but it's imported as sklearn.

146
00:09:53,790 --> 00:09:55,920
And that's also the case here.

147
00:09:59,270 --> 00:10:01,760
So if you run this, you're not going to get an error.

148
00:10:01,790 --> 00:10:06,530
Of course, you can call this function as we did previously, but I'm not going to do that now.

149
00:10:06,530 --> 00:10:11,400
So that was how to upload your package to Pypi.

150
00:10:11,420 --> 00:10:18,560
If you ever want to do a change to your code, to your package, you do the change in your code and

151
00:10:18,560 --> 00:10:20,900
then you want to upload it again.

152
00:10:20,900 --> 00:10:26,790
But before uploading you want to go to setup.py and change the version to something else.

153
00:10:26,810 --> 00:10:31,130
So depending on on how big of a change that was.

154
00:10:31,130 --> 00:10:34,890
So if you just fix the bug, you do 1.0 0.1.

155
00:10:34,910 --> 00:10:44,120
If it was just a bug, if it was something else which doesn't break the code of users, you do one point,

156
00:10:44,120 --> 00:10:45,340
1.0.

157
00:10:45,350 --> 00:10:55,220
So not breaking the code of the users means that if I as a user had some some program where I import

158
00:10:55,220 --> 00:11:04,890
your invoicing pdf package, then in that code I'm using the generate function using all those arguments

159
00:11:04,890 --> 00:11:08,430
right as it was in the existing version.

160
00:11:08,580 --> 00:11:13,710
The change you want to do is, for example, you don't want to change any of these arguments because

161
00:11:13,710 --> 00:11:19,670
then my code will not work if I update the version, right?

162
00:11:19,680 --> 00:11:22,650
So in that case you do it here.

163
00:11:22,650 --> 00:11:29,490
If you do some major change which breaks the code of the user, like you change some argument names,

164
00:11:29,490 --> 00:11:32,790
you remove some arguments from the generate function and so on.

165
00:11:32,790 --> 00:11:36,480
Then you want to change the first major version in here.

166
00:11:36,480 --> 00:11:42,930
So that's like the communication you give to users that, Oh, we have made a big change here, so your

167
00:11:42,930 --> 00:11:43,950
code will break.

168
00:11:43,980 --> 00:11:50,190
Therefore you need to look at your code and update it with the current requirements of the library.

169
00:11:50,190 --> 00:11:54,960
So depending on, on, on what changes do you want to change one of these numbers?

170
00:11:57,420 --> 00:11:59,430
And that's it in here.

171
00:12:02,310 --> 00:12:03,390
And then you do again.

172
00:12:03,390 --> 00:12:08,010
Python setup.py s dist.

173
00:12:09,430 --> 00:12:16,900
So that's command to read the updated setup.py file and generate the dist files again.

174
00:12:16,900 --> 00:12:29,410
So you execute that and then after that twine upload, skip minus existing dist everything you execute

175
00:12:29,410 --> 00:12:34,990
that and that will upload the new updated library to pypi.

176
00:12:35,320 --> 00:12:38,260
That's how you make a change to your library.

177
00:12:40,550 --> 00:12:46,580
And yeah, that concludes this video and the production of our package.

178
00:12:46,640 --> 00:12:48,050
Thanks a lot for following.

179
00:12:48,080 --> 00:12:51,740
This was a major achievement for taking this course.

180
00:12:51,740 --> 00:12:57,210
So even though perhaps you didn't take it entirely, I hope you still learned something.

181
00:12:57,230 --> 00:12:59,220
So all the best and see you again.

182
00:12:59,240 --> 00:12:59,960
Thanks.

