00:0.34 You saw how to take an existing package and get going with it,
00:3.73 add features and play with it and test it and so on.
00:6.44 Let's now go and create a new package and notice over here in our course demos
00:12.42 we've got this package folder around create something called 'calc' you can imagine this might be
00:19.29 a silly little calculator package that we could import and do basic math with something like
00:24.26 that. The way these packages usually get structured,
00:27.74 the willow look back, for example,
00:29.28 at requests. The folder really this GitHub thing is called request but in there
00:34.65 there's the package name and the package has a dunder init_py in python
00:40.02 To make something a package technically all you need is a folder and a Dunder
00:44.58 init.py. So for example,
00:46.6 I could say 'calc' and then here is used in Mac the creative files to just
00:51.8 do this touch. There doesn't have to be anything in this file.
00:57.8 It's zero bytes. It's an empty.
01:0.04 If we have a folder that contains this file to python,
01:2.53 that means a package but it doesn't mean a package in the PyPI pip,
01:6.23 install sense of things. We're going to need more details.
01:9.23 We need also an implementation. So what's pretty common is to have the source older
01:13.41 the top level folder for the package and then the package itself to be a
01:17.84 subdirectory with the same name in there.
01:20.04 Let's go and open this in PyCharm and turn it into a full blown package
01:23.77 Let's go and add a new virtual environment.
01:33.23 We're going to want one to install our package and possibly its dependencies into over here
01:38.32 We've got our Dunder init.
01:40.67 It's red. We open it up,
01:42.62 you can see that it's empty.
01:43.91 I'm gonna command 'Alt+A' and mac os that adds it to turn it green so
01:49.11 it doesn't look broken or anything like that.
01:51.44 So we've got this calculator package and let's just give it a couple of functions.
01:56.06 Sometimes people put the implementation directly in this Dunder,
01:59.46 init_py others as we saw with the request there might be like an 
02:3.27 API folder and then they use an import statement to add it in.
02:7.64 So I'm just gonna do this simple thing right now and put a couple of functions
02:14.44 and you know what the implementation is going to be nice and easy.
02:17.92 So we're gonna 'return x + y'.
02:19.95 Let's have another one called subtract like this.
02:27.19 So this is what our calculator is going to do.
02:29.03 You're going to say import calc,
02:30.5 then count.add and count.subtract and get your numbers back.
02:34.44 But in order for us to use this again,
02:36.36 it has to be a proper python package,
02:38.41 Not just in the local sense,
02:39.71 but we want to share it.
02:40.68 It needs to have more information.
02:42.84 So check this out. Remember we saw the tools run setup py don't have a
02:47.44 run setup.py  Why we don't have a setup py but check this out,
02:51.24 create a setup.py So this will help you get everything set up just like you're
02:55.58 supposed to. So let's type a little info in here.
03:0.14 Alright. It fills it out.
03:1.02 We hit go and look what we've got.
03:2.91 We've got all the little details that we need right here before I apparently misspelled calculator
03:7.42 We know that the name of the packages,
03:11.76 calc the version is this. If we had sub packages like if I had a
03:16.35 folder in here that was for advanced math,
03:19.3 we could have, you know,
03:21.44 'calc.advanced' and so on. So there might be more than one of those here
03:26.6 That's why that's a list I made up some fake URL for mit
03:30.55 michael kennedy in my email and the best calculator ever.
03:34.77 Don't you think? So it looks like things are pretty good to go.
03:38.54 We could do things like pull the version.
03:41.14 We could also go and set other values like the description.
03:45.44 We could set the long description,
03:46.94 we could set the long description format to say mark down but this is a good
03:50.87 starting place and this is really all we need.
03:53.74 So if we want to test this app we could go and write unit tests or
03:58.32 we could go and create a folder directory called 'bin' maybe and then I'll write a
04:2.48 little test app. What I want to do is actually go to my test app
04:8.71 and import this package. The safest best way to do that is just like we
04:12.66 saw before now run a set up,
04:16.44 develop experience here, make sure everything gets set up.
04:20.14 So now python button this is installed as part of this and we can just go
04:24.24 down here and say import there it is and check it out.
04:29.44 And let's just get some numbers here.
04:31.34 We'll say we're just going to have no error checking and just assume this is an
04:36.72 integer. Who knows if that's a good idea?
04:38.73 Probably not in general, but we're gonna cast it over to an integer and then
04:43.86 we're going to just print out a couple of things.
04:49.34 We're adding the calculator using the 'calculator.ad'.
04:53.16 And then we're gonna do the subtract.
04:58.64 Here's our little app. You want to see if the package that we've created and
05:1.87 installed by running python setup py develop or we could do the pip,
05:6.22 install command as well. Let's run it and see what we got.
05:12.54 First number is 7, 200.
05:15.32 The sum is 207. The difference is negative 193.
05:17.65 1 93. Done how cool is that?
05:20.34 So we've created this package and let's go see what else we can do with it
05:24.3 Let's try this python. See if we can create a wheel and what do
05:34.99 we get up here? Let's see we've got a Dist folder and then there's our
05:40.33 wheel. This is what we could do 'wnl' or some tool like that to upload
05:43.96 to PyPI. You can bet there's already a 'calc' available on PyPI in some
05:49.33 way or another. But we've got our dist and we've got our build here as
05:53.31 well. We're building stuff. We'd want to ignore this folder probably and not put
05:57.06 it in source control. I'm guessing that's up to you.
05:59.84 But because we have this setup py that was created,
06:2.84 we can now do, first of all,
06:4.61 we can work with it properly in our app and be sure that it's installed into
06:8.35 python locally. But then we can do things like this where we're actually using the
06:13.84 tooling to build distributable versions of our package.
06:17.64 But then on PyPI we could put that on an internal Py Dev server bunch
06:21.74 of options where to go from here.
