1 00:00:00,009 --> 00:00:01,669 Welcome to a brand new section. 2 00:00:01,679 --> 00:00:05,860 And here we're going to be talking about libraries and modules. 3 00:00:05,869 --> 00:00:08,319 So what exactly are these? 4 00:00:08,600 --> 00:00:13,670 Let's print this scenario, right? What if we wanted to write a program 5 00:00:14,010 --> 00:00:18,479 that will hash plain text, right? So say, for example, we wanted to store our 6 00:00:18,700 --> 00:00:22,659 passwords in a file. Obviously, we'd want to hash them. 7 00:00:22,889 --> 00:00:27,469 We don't want to stop passwords in a plain text. So how would we write a program 8 00:00:27,809 --> 00:00:30,309 that will hash these passwords? 9 00:00:30,909 --> 00:00:32,209 There are two options. OK? 10 00:00:32,220 --> 00:00:35,650 We could either decide to write the program from scratch, 11 00:00:35,659 --> 00:00:38,090 which might take a lot of time or 12 00:00:38,380 --> 00:00:39,680 very simply, 13 00:00:40,020 --> 00:00:42,490 we can use something called a module 14 00:00:42,610 --> 00:00:45,209 that already has the code 15 00:00:45,639 --> 00:00:49,090 that we would need to hash our text. So 16 00:00:49,709 --> 00:00:53,319 a module is typically a Python file 17 00:00:53,470 --> 00:00:55,409 that already contains code. 18 00:00:55,419 --> 00:00:59,250 It could be functions, variables, classes, statements, you name it 19 00:00:59,770 --> 00:01:02,799 that serves a specific purpose 20 00:01:03,869 --> 00:01:07,519 while a library as you might now have imagined 21 00:01:08,139 --> 00:01:16,080 is often a package group of these modules organized around a broader goal. 22 00:01:16,529 --> 00:01:19,000 So you can think of modules as very 23 00:01:19,010 --> 00:01:22,769 specific functions that serve a very specific purpose. 24 00:01:22,889 --> 00:01:27,849 While a library would be a collection of such modules 25 00:01:28,239 --> 00:01:29,559 as an example, 26 00:01:29,769 --> 00:01:33,000 we do have the datetime pi 27 00:01:33,250 --> 00:01:34,790 this is a module 28 00:01:35,230 --> 00:01:39,849 that has functions specifically for working with dates and times. 29 00:01:40,559 --> 00:01:43,790 We also have a library called the Hashlib, 30 00:01:45,269 --> 00:01:48,040 the hash library which would be 31 00:01:48,480 --> 00:01:54,110 the library we would have to use in order to hash our plain text. 32 00:01:54,190 --> 00:01:56,930 Now, what do we have in the hash library? 33 00:01:57,180 --> 00:01:59,419 We have different types of algorithms. 34 00:01:59,620 --> 00:02:03,639 We have the MD5 that will create a 128 bit hash. 35 00:02:03,650 --> 00:02:06,029 We have the sha one that will generate a 160 36 00:02:06,040 --> 00:02:09,008 bit hash sha 256 which will generate the 256. 37 00:02:09,020 --> 00:02:13,389 And of course, the sha 512 which will then generate a 512 bit hash. 38 00:02:13,490 --> 00:02:18,220 There are also other types of functions within this library like the hashlib dot new 39 00:02:18,380 --> 00:02:20,669 that will accept two parameters name data 40 00:02:20,990 --> 00:02:28,210 which we can then use to create a hash with a specific algorithm name. 41 00:02:28,860 --> 00:02:29,320 So 42 00:02:30,070 --> 00:02:31,169 moving forward 43 00:02:31,529 --> 00:02:32,850 libraries 44 00:02:32,960 --> 00:02:36,919 can either be built in, we call them standard libraries. 45 00:02:36,929 --> 00:02:40,490 This will come default with your Python installation or 46 00:02:40,910 --> 00:02:45,889 we can also use libraries that are external. We refer to them as third party. 47 00:02:46,059 --> 00:02:48,330 These libraries don't come 48 00:02:48,559 --> 00:02:53,009 with your Python installation. So you'll have to install them manually yourself 49 00:02:53,289 --> 00:02:57,330 and they're developed by the Python community. 50 00:02:57,899 --> 00:03:03,610 So one more time modules have very specific code that sells very specific function 51 00:03:03,860 --> 00:03:08,020 while libraries will be a collection of these modules. 52 00:03:08,479 --> 00:03:10,360 One other thing I want you to 53 00:03:10,550 --> 00:03:14,699 realize is that within the Python community, 54 00:03:14,940 --> 00:03:19,000 you may also hear of another term called packages. 55 00:03:19,490 --> 00:03:24,240 Packages are somewhere in between modules and libraries 56 00:03:24,600 --> 00:03:27,210 and that they are also a collection of modules. 57 00:03:27,500 --> 00:03:32,169 But the modules tend to be very closely related in purpose. 58 00:03:32,250 --> 00:03:34,190 They're not quite as broad 59 00:03:34,460 --> 00:03:37,899 as library. So for example, you can have your email package 60 00:03:38,339 --> 00:03:41,559 and in the email package, you'll have modules like your email message, 61 00:03:41,570 --> 00:03:42,369 your email dot 62 00:03:42,589 --> 00:03:43,389 MIME, your email 63 00:03:44,240 --> 00:03:45,800 TS and so much more. 64 00:03:45,990 --> 00:03:49,279 Another advantage of packages is that they can allow us to 65 00:03:49,289 --> 00:03:55,199 organize these modules in a hierarchical structure by using folders and 66 00:03:55,380 --> 00:03:57,199 sub folders. 67 00:03:57,440 --> 00:04:01,559 So each package typically will contain the 68 00:04:01,869 --> 00:04:04,300 init dot py file 69 00:04:04,679 --> 00:04:06,660 which tells Python that hey, 70 00:04:06,850 --> 00:04:11,539 this particular directory, it's not a library, it's actually a package. 71 00:04:11,850 --> 00:04:15,380 This is how we can help Python differentiate between 72 00:04:15,509 --> 00:04:17,428 the package and the library. 73 00:04:17,678 --> 00:04:22,089 The the package will have a file specific specifically called 74 00:04:22,290 --> 00:04:22,619 the 75 00:04:22,760 --> 00:04:23,220 init dot 76 00:04:23,559 --> 00:04:28,709 py file. So that's it for libraries, modules and packages German 77 00:04:28,859 --> 00:04:28,940 Linux 78 00:04:29,130 --> 00:04:29,880 video where 79 00:04:30,040 --> 00:04:32,260 we will not begin to work with them.