Python - Fire - A module from google to create CLI application | D谩niel Ern艖 Szab贸 | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Python - Fire - A module from google to create CLI application

teacher avatar D谩niel Ern艖 Szab贸, Pythonista in the making

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

10 Lessons (47m)
    • 1. Python Fire Course introduction

      2:13
    • 2. Python Fire Setting the stage

      3:22
    • 3. Python Fire Hello World

      11:31
    • 4. Python Fire Checking argument type

      2:57
    • 5. Python Fire based arguments to class functions

      5:01
    • 6. Python Fire Multi class demo for the sake of functionality

      5:56
    • 7. Python Fire Accessing class properties

      3:38
    • 8. Python Fire args and kwargs in function based CLI

      5:38
    • 9. Python Fire Climber and the end

      4:57
    • 10. Python Fire The end

      2:16
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

9

Students

--

Projects

About This Class

Did you ever wonder how to create command line apps with python? You want to be able to create apps that can be reused by the colleagues of yours? This course allows you to do just that! With this course you will increase your job security, and create CLI apps that echo your name across HR branches.

Source is at:聽https://github.com/r3ap3rpy/fire

Meet Your Teacher

Teacher Profile Image

D谩niel Ern艖 Szab贸

Pythonista in the making

Teacher

Hello, I'm Dániel Ernő.

I currently work as a devops engineer. I have several years of experience with various platforms and I'm here to teach some advanced techniques which may attribute your job security ;)

Cheers,

Daniel

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Python Fire Course introduction: Hello there and welcome to my course on the fire More you're off vital. So basically, this module can be found under the get hubs represent Torrey and on this module allows you to create very flexible common line applications. And the specialty of this module is that it allows you to, let's say, create applications, which can accept multitudes off arguments. And there are two main approaches based on which you can develop these common line applications. The 1st 1 is a class based approach. The 2nd 1 is a function based approach. Bulls have their advantages and disadvantages, but if you take this course, you will see the benefits of both off these approaches. So, ah, in this course, you will learn the foundations that are needed to create these kind of applications. And, let's say your system administrator ah, no apps engineer someone who has, ah to handle. Let's see some kind of tickets which relate to issues and, ah, you may want to accelerate and make your daily work more precise by creating such applications, which can, let's say, perform specific tasks. So let's say you receive a ticket. That Web server is down. Then you could create an application which takes the argument as the name off the Web server and just simply goes logs into server interested fix. And this approach is very popular. And in this course you will learn the so called foundations as to how you can create such applications. So if you are interested in such knowledge, I would like to welcome you to take my course. Thank you for what? 2. Python Fire Setting the stage: uh, hello there, and welcome back. Since you are watching this video, I think you may have enrolled in my course, and I'm happy to see that. So basically, this going this video is going to be about setting the stage by which I mean that I'm going to show you how I have lets to create the environment in which I'm going to introduce you to the script that I write, which are based on the documentation off this module. So let's get it. So as a best practice, I usually create ah border, which is going to hold my were trial environment and my scripts. So the folder is called Fire On Inside this folder, I issued the V actual m fire. That's call it and Goemon. Sorry, I brought the CD which has changed directory. So basically, yeah, this is the way to create the trial. And if you're not family are with the which are among you. I have another course which is fighting for absolute beginners. And it explains you why this module is kind off, no authority to mention, and it's really valuable toe because it allows you to separate different environments in your computer. So you don't mess up other projects by installing, let's say, modules which have different version based dependencies without a more use. And that can be, ah, really pain in the me s, so to speak. So basically seems the firearm was installed. We need to activate this environment. And after activating it, what we can do is issue the peopIe in stock fire and this is going to go out to the Internet. Or if you have ordered the instead of mute local cash jacket, there is any difference in case of the local cash. If not, then it is going to install them on your and other dependent values. So we have gotten this out of the way we need to create a script folder. And here in the scripts folder, we are going to store the demonstration fires and, ah, scenes. This module is platform independent. You should be able to run these demos on any platform. So I'd wring those UNIX or Mac OAS and basically discovers the setting the stage part and the next video I'm going toe show you how you can create a simple hello world application. Thank you for 3. Python Fire Hello World: uh, hello there. And the wild comeback. So the time has come to create our in famous hello world video of the Siri's. So, basically, in this video, I'm going to give you at least three examples as to how you can get started with fireman You. So that's cool. Our first demo, the hello, simplest not be why. And we will import the fire model. And here what we are going to do is to create it Two variables. So hello equals two. Welcome to my course. And the world is going to be equal to this is your reality from now on. And what we would like to do is to check is the name equals main. And we will just simply call the fire, not fire. Sorry, Typo. Let's save it and start comin from Well, may get that. So we need to navigate to our fire folder. Activate our fire amp with the following co month Fire scripts activity. And now what we can do is to navigate to the scripts folder and call our Hello, simplest that p y. And if you do this, it is going to give you a hint as to how and what you can invoke with the half off this milieu. So if I see simplest B y hello, it is going to return the welcome to my course. And if I say the world, it says that this is your reality from now on. So basically what we did here is to create a variables and those worry of us are taken as arguments. Now I'm going to show you how you can use functions so reimport fire and create the hello with the name argument on Let's save it. So hello, function based not be why. And now what we can do is to return the welcome toe, my course and we will say the name off the and they're old student. So this is a naff string, which is kind of a hot topic in Piketon now. So what we can do is to check if name equals main. And after that we can call the fire fire. Hello. So this approach allows you to expose specific functions to your common lines. So if I save it and now go like this soap item, a low function based and I say hello, Daniel, it says that there is something wrong, and this is because you need to use it a little bit differently because you have exposed that function by default. So it is going to take the arguments now if I run it with just the argument I wanted to specify. I can see that Welcome to my course, Danny off. And ah, basically what we could also do is to say, we want to have an ad function X and why, and we would like to return the X plus. Why a course with enough stink X plus why and now what we could do is to, let's say, create another fund, another script. So it is going to be four. So hello. More people function that be why, and let me delete this one here. Save it. And now what we would like to do is just simply delete that functioning from the invocation off the fire milieu, because we would like to expose every function that is defined. So now what I can do is to say, I would like to call the more tipper function part and say, Hello, Daniel, and you can see that the appropriate function was called because the volume of your Jack to see if there are any function definitions. And after that it signed the argument to the specific function called. So if I see, I would like cold hell Dona, it is going to give me an ad on my siege because there is no such function defined. But if I see I would like to ed then and 28 what you see is that 10 plus 28 equals to 38. So this is kind of a simple example as to how you can utilize it. And what I would like to do is to show you how you can create your class based approach, because that is also a very powerful concept. So hello, glass based that be why we need to import a fire module, create our call. And here we define our let's say welcome class. And this Rackham class is going to have an in it function. And the Senate function is going to take, uh, watch your dick. Let's just keep it clean. So we defined our hello function. We say self and name, and what we can do is return the welcome to my course with the named argument. You could also say that we would like to. Let's call it won't apply Seth Ex and why, and we would return something which was defined previously. So this one. And now if I would like to call my function, what I would do is to say I would like to assign the class as an argument to the fire corps and let's save it. And now, if it's clear our screen just to make sure we see everything as clean as possible, we could say you would like to use the class based approach and if we just simply invoke it , it is going to give us use these and B is under usage. If you call the hello student, it is going to return the return while you off the appropriate classes function definition . And if I say I would like to multiply and I think I made a mistake. So here we would like to use the Asterix and let's walk by 11 by 22 now. As you can see, the result is also quick. So basically this was almost all I wanted to show you, but ah, what we could also do is to, let's say we would like to expose only specific function definitions. So let's create another script. So we are at five now. So hello, Spacey fic expos and now what we could do. It's the repurpose, our import statement, our if statement and this sea is the one that we would also like to use. So hello divide and we would like to divide. Oh, and I think I should also change this one. So the sources are correct and ah, this one also, let's make it more by Danek. So now what we could do is to create a dictionary. And in the dictionary you define the let's say function and the assigned function definition. So let's call it welcome and this will be assigned to the Hello. Let's call the other one month and let's assign it to divide. Now If I say with and let's see, run the following serve item Hello specific exposed. You can see that we have two functions exposed. And if I see welcome student, you will see that the this argument called the appropriately marked function the hello. If I see I would like to call the math and sees this is a division we would like to divide 99 by 11 and this should return 9.0. So basically, that's all. As to the hello worth part. Stay tuned for more. Thank you for watching. 4. Python Fire Checking argument type: Hello, That and why I come back in this video, I'm going to show you, um, a little bit of treek which you can utilize to get Let's see the type off the argument that you passed to your fire application. So basically, this is just going to be a short, dim or so Let's import the fireman you and save it as our human types. That be why? And what we are going to do here is to call the fire that fire and here with specify alarm . But the object and this is going to be the type of the object. That name and what this allows you to do is tow. Let's say, uh, identify the type of the argument that you specify to your application. So basically, if we Iran the following script, you will see this. So argument types dash, dash object, then. And ah, what I have for got them to do is to let's say, um, specify the following. So, uh, let's save it and run it again. And ah, now you can see that the argument that we have passed is an integer and ah, if you want, you can pass afloat we could also pass a string and other types of arguments. So basically, what happens here? Is that you When you in walk the script, it is going to use this anonymous function and the suddenly miss function is great. Take the argument that you specify as a object. And, ah, it is going to return the name of the specific object. So this is why this is happening. And it can be used for when you would like to create the Skomal an application that would perform specific actions based on the boat argument. So Ah, yeah, basically this This was all this video was about. So stay tuned for more and thank you for what? 5. Python Fire based arguments to class functions: Hello there. And wel come back in this video. What? I'm going to show you as to how to create your class based approach and in this class based approach, what we will see. It's how we can define the functions which are going to in turn take arguments. And ah, I think this is Ah, we're really need and ah, that's Abita Nick way off the Indies Common Line scripts that we want to create. So let's get to it. First we need to import a fire more your and that's cool it glass dogs that be why? And after that, we create our class, which is going to be called Let's a calculator and we will inherit from the object based class And here at in it we will define the self and let's say nothing more. We will have a gnat function for steaks, ex and why, and produces the some off x and y, and we will have a multiply steak self ex and why? And ah, we will return the multiplication off these two numbers we will have Ah, Uh huh. That's called it Divide sef ex and why? And we were turned the x divided by why. And as usual, if the name a course main, we would just simply do the usual stuff. So fired on fire and the class, which is gold calculator. So if everything goes right and we have activated our natural environment, them my better is getting lower my keyboard. So basically, I have this Microsoft keyboard. I love it. I had it for, like, four years now, and the only problem with it is the every now and then. So let's say every year you have to replace the battery or the Yeah, but and ah, now what we will do is to navigate our scripts folder and let's see what happens when we call the class dogs that b y. It is going toe return AHAP message with stays. The usage off the scripts Ah, that we want to use a cli. So let's say we want to add two numbers, but we I do not know how we can specified all of humans if you're on the script like that, if you use us a message. So basically what happens here is that in case of the art function, he would specify that the X value is 15. And why, while you is 33 and if we run it, What we get is 40 it. So the calculation seems to be correct. And what we could do is to specify the divide. And we could also specify no multiply. And basically, this is it. So, um, what you could imagine further you have a class that can create users. And ah, you will specify that you would like to create user on the cli user name, Reaper pie and password whatever. This is not my area possible. So basically, this is ah, how easy it is to create ah class based approach to this topic I have just described. I heard you like this video. Thank you for watching. 6. Python Fire Multi class demo for the sake of functionality: Hello there. And welcome back in this video off my fire project. I'm going to show you how you can utilize multiple classes. Ah, to serve your cli application. So let's goal our script More tie glass, the mo Not be Why? And ah, what we, uh, going to do in this demo is toe first import the fire model, create our class which will serve as start stage. It really had it from the object, this class and we will have Ah, that's a start function and the start function were take the no argument sold. Only the staff will be passed And what we would like to do is, let's say, say, starting web service. Let's ah, call our other class stop stage and call it stop and let's say, stopping Web servers. So how do we bundle together these classes? What we could do is call on the Web server manager and this website where manager is going to have it from the object based class. And after that, we need to define the unit function and the Senate function is going toe. Have a start argument, and the start argument is going toe be populated with the star stage and the self that stop is also going to be populated by the stop stage. And what we could do is, let's say, create ah function, which is going to be called Bounce. This balance means that first, we would like to, let's say, stop the Web servers if they can be stopped and then started a Web server. So balance means technically a restart. So let's do this. And, ah, what we could do is to say, self stop and stop because we had it dysfunction from the stop stage and what we could also do is go this thought not start, and this is also inherited from the class. And, ah, let's call it. Ah, that's a status stage and status off the Web servers. Let's save it. And since we have a stop ah, bounce function, what we could do is let's a try and run our application. So if name equals main, what we could do is create our fire application and call it Web server manager. And now, if I open my console, me got this for you and navigate to the fire folder and in this fire folder I have my firearm, which needs activation and after activation. If I never get to my scripts folder, what you can see is that I have the multi clause demo. And, uh, if I just simply want to run this small type class, the more what you can see is that this is ah, that's a simplified have message. And ah, what we could do is to say that we would like to bounce in the Web servers, and, as you can see, it called the stopping and starting Web server stage. And what we could also do is to imbue this further so we could get the status speech, and the status page is going to come from the state of stage, and we could depend here. That's a verification part where we call it with the saft, that status, that status function. And if I rerun this part again, what you can see is that the servers were stopped, they started and ah, finally the States was sprinted. And I have written multiple common line applications with this your end. They are wary. Let's say, useful in a sense that if you permit arise right your classes, it can be a very flexible Swiss army knife in your tool set. So basically, this is all I wanted to show you in this video. I hope to like it. Thanks for watching. 7. Python Fire Accessing class properties: Hello there. And welcome back in this video, I'm going to show you how you can access class properties with the help of the fire millio . And it can be useful in many ways. But this demonstration is going to be for a simple etc calculator. So let's get to what we would like to do is to call it property access that for you, I Let's import the fireman your create our class, which is called Calculator that inherits from the object based class. And we will have this in its function and we will specify a number. And what we do is to create the instance for year bus. So physically the number equals number from the sev Daboo equals number times two saff tree pull. It was number times three and sef What the rule. Black Maybe equal still number times four. And now if we want to use it, you do the usual thing. So fire the fire and the cost class name, which is calculator. Let's save it and try to run it. So property access that b y. And it is ah requiring an argument, and we can specify it like this. So five And after that, what we could do is to let see Cole the following number five double and the double of five system. The triple it's 15 and quadruple plus is 20. So basically what is happening here is that these instance variables are signed as arguments to the specific dash dash argument. And ah, and this is kind of, uh, powerful concept because you could let's say that you have fighting scripted that is able to manage servers that B y and you specify with the dash. Dash the name off the server, which is God, Web Server one. And what you could see is just simply called stop function. And ah, based on this logic, it would go to the Web server and issue the command stop, which would, ah, let's say, realize in on action or steps performed in order to stop the Web server gracefully. So basically, this is what I wanted to show you in this video. I have like it. Thank you for watching 8. Python Fire args and kwargs in function based CLI: Uh hello, Dad. And while come back in this video, what I'm going to show you is to how you can utilize the ARDS and ah Kwok's arguments in your fire project. Namely, I'm going to show you how you can create so called Ah, what a member argument bees, the common line applications. So let's create our fires and call them worry able. Org's not be why and then this script, What I'm going to do is to create a function which is called kind Off, and we were past the dogs to the function, and what we are going to do is for each argh In dogs we were print the gut human and call it Argh! And let's make it an af string. So we are following the bite or hype. So if the name a course main, we will create our fire. Ah ah, class and ah, that's bus Our function there. Let's save it. And Lance ran the common prompt entered fire directory. Active it, I said, Activated. They were trailing vitamins. And let's goal our variable logs that p y. So it's not doing anything unless we specify the arguments. So 45678 And as you can see, it says that it got the argument. 4567 it. So this is how you pass These are eggs to your come online application and, ah, let's create another script, Water yearbook Wogs that p y. And ah, basically, we, uh, going to repurpose the previous one. But name them with the number start quirks and what we would do here. I still specified a key, the value, and we will reiterate over the quirks and we will say, Got key. We'd value. Well, you, um Let's also make it the af string. And now what we could do. It's the wrong our variable Kwok's that b y and we say dash a equals five cash being equal six flesh See equal seven and dash D because eight. What did just happen? I know. So we need to specify that there's bash in order to access the key. What arguments? And it's they're not working. Why is that so basically we have the key and the way you and ah, and the problem here we have is that we need to reiterate over the items or if you're not iterating over the items What we need to do ihsaa to restructure our function. So let me run the spot again. So as you can see, it's working now. And if you want, we could Ah, let's say just Ah, But you're right. It So let me comment this 1st 1 out. I don't know why, but I love the sublime text. It has a nice shortcuts, and it allows you to be kind off really efficient. So what we would do is to now replace the key and the value with a format string and ah, we would see key and quarters he And if everything goes well, we should get the same result. And we did. So, um, basically, this is all I wanted to show you in this video. I hope you like it. Thank you for watching 9. Python Fire Climber and the end: Hello there. And welcome back. So now this year, troubling doesn't matter. But basically what I want to show you. Get this microphone. Right. So what I want to show you is to how you can utilize a class based approach with Ah, let's a multiple arguments. So we will import the fire module. We will have a class called climber It really inherited from the object baseness and we will have on in its function. And the Senate function will have a name and the stories and the stories are going to equal . So three sev the name Nikolas name the stories, equal stories. And what we would do is to implement the climb, function and the stairs. Bad stories equals, let's say, seven. So this class is going to go from stare our story in range self, but stories and four each. There it go with the range stairs, past stories and what we will yield is the South. Ah, I mean stared. And after that we would also yield the, um exhausted and we would finally yield the It's over. And now what we can do is to check if the name equals main. My Ah, Brutus keyboard is, ah, low on batteries, so sometimes these depots can have them. So that's cool. Our fire, the fire with the climber class and what we could do is to issued ah Bytom climbing, and we can see in that we can name the arguments, So call it three per pie. And what we could do is to, let's say, specify the client function. And as you can see, based on different arguments, it is going to climb three stories and there are seven Stairs. Their stories and ah deal put reflect Beth. So let's say we would like toa utilize a different approach. So we have this climb function and, ah, we would like toe specify a stair past story as three. And this is not working because disclaim function is going to take a different approach to these. Ah, let's say arguments. So let's say our stories are not three but five, and what we could do is to issue the climb function, and, as you can see, it is going to climb, find stories in this approach. And ah, what we could also do is to specify of the addition argument, which would say how many stairs. Spare stories we have. So by these, you should get grasp off as to how you can assign arguments based on the place where these were defined. And, uh, technically, this is all I wanted to show you. Thank you for watching. 10. Python Fire The end: Hello That and why come back? So basically this is it. So this is the end off my course on the fire project which first provided by Ah, Google. And I think this is ah pretty Westheimer your and it could allow you to create Ah, let's a sense of job security in a way that you will be able to create common line applications which can take a variable number off arguments. And based on those arguments, they could specifically perform Tusk that you would otherwise but form by hand. And, ah, as always, in Beit on, I think this is a pretty powerful concept. So what you have learned in the scores is starting from the hello world. Ah, demonstrations. You learned how you can utilize the melodic, alas, multiple class approach to solve. Let's see whole infrastructure management problem. You learned how you can utilize property access. You can also excess what am a number of arguments and give it arguments. And, um, after taking the scores, I hoped you have ah, pretty good sense as to what you can achieve with this by tomorrow. Your so basically, this is it. I'm really thankful for you toe watching this course and ah, what I want you to do is to create an honest review or feedback off the score. So not just ah, you can become better by taking the scores. But ah, you allow me toe become a better version off myself by listening to your feedbacks. So I thank you for watching.