Building CLI with Google's Fire Python Package - Introduction

Building Command Line Tools with Python, Julia and Nodejs Module 02 - Building Command Line Tools in Python with Google's Fire
13 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.78
List Price:  €93.98
You save:  €28.19
£56.19
List Price:  £80.28
You save:  £24.08
CA$96.65
List Price:  CA$138.08
You save:  CA$41.42
A$109.01
List Price:  A$155.74
You save:  A$46.72
S$95.37
List Price:  S$136.25
You save:  S$40.88
HK$548.06
List Price:  HK$782.98
You save:  HK$234.91
CHF 63.79
List Price:  CHF 91.14
You save:  CHF 27.34
NOK kr768.84
List Price:  NOK kr1,098.40
You save:  NOK kr329.55
DKK kr490.83
List Price:  DKK kr701.21
You save:  DKK kr210.38
NZ$118.45
List Price:  NZ$169.22
You save:  NZ$50.77
د.إ257.03
List Price:  د.إ367.20
You save:  د.إ110.17
৳7,684.20
List Price:  ৳10,977.89
You save:  ৳3,293.69
₹5,855.32
List Price:  ₹8,365.11
You save:  ₹2,509.78
RM335.35
List Price:  RM479.10
You save:  RM143.74
₦84,069.65
List Price:  ₦120,104.65
You save:  ₦36,035
₨19,482.60
List Price:  ₨27,833.48
You save:  ₨8,350.88
฿2,577.20
List Price:  ฿3,681.88
You save:  ฿1,104.67
₺2,276
List Price:  ₺3,251.57
You save:  ₺975.56
B$370
List Price:  B$528.60
You save:  B$158.59
R1,331.99
List Price:  R1,902.92
You save:  R570.93
Лв128.63
List Price:  Лв183.76
You save:  Лв55.13
₩96,774.91
List Price:  ₩138,255.79
You save:  ₩41,480.88
₪263.45
List Price:  ₪376.37
You save:  ₪112.92
₱4,005.56
List Price:  ₱5,722.47
You save:  ₱1,716.91
¥10,822.37
List Price:  ¥15,461.20
You save:  ¥4,638.82
MX$1,188.83
List Price:  MX$1,698.40
You save:  MX$509.57
QR255.45
List Price:  QR364.94
You save:  QR109.49
P967.75
List Price:  P1,382.56
You save:  P414.81
KSh9,273.67
List Price:  KSh13,248.67
You save:  KSh3,975
E£3,415.20
List Price:  E£4,879.07
You save:  E£1,463.86
ብር3,983.99
List Price:  ብር5,691.67
You save:  ብር1,707.67
Kz58,616.62
List Price:  Kz83,741.62
You save:  Kz25,125
CLP$68,622.39
List Price:  CLP$98,036.19
You save:  CLP$29,413.80
CN¥506.62
List Price:  CN¥723.78
You save:  CN¥217.15
RD$4,136.69
List Price:  RD$5,909.81
You save:  RD$1,773.12
DA9,432.45
List Price:  DA13,475.51
You save:  DA4,043.05
FJ$159.25
List Price:  FJ$227.51
You save:  FJ$68.26
Q544.58
List Price:  Q778.01
You save:  Q233.42
GY$14,660.07
List Price:  GY$20,943.86
You save:  GY$6,283.78
ISK kr9,900.78
List Price:  ISK kr14,144.58
You save:  ISK kr4,243.80
DH712.14
List Price:  DH1,017.39
You save:  DH305.25
L1,250.72
List Price:  L1,786.82
You save:  L536.10
ден4,047.46
List Price:  ден5,782.34
You save:  ден1,734.87
MOP$564.82
List Price:  MOP$806.92
You save:  MOP$242.10
N$1,331.20
List Price:  N$1,901.80
You save:  N$570.60
C$2,577.12
List Price:  C$3,681.76
You save:  C$1,104.64
रु9,367.18
List Price:  रु13,382.26
You save:  रु4,015.08
S/261.74
List Price:  S/373.93
You save:  S/112.19
K265.15
List Price:  K378.80
You save:  K113.65
SAR262.54
List Price:  SAR375.07
You save:  SAR112.53
ZK1,755.70
List Price:  ZK2,508.25
You save:  ZK752.55
L327.30
List Price:  L467.60
You save:  L140.29
Kč1,658.88
List Price:  Kč2,369.93
You save:  Kč711.05
Ft25,827.61
List Price:  Ft36,898.16
You save:  Ft11,070.55
SEK kr766.20
List Price:  SEK kr1,094.62
You save:  SEK kr328.41
ARS$60,803.53
List Price:  ARS$86,865.91
You save:  ARS$26,062.38
Bs485.55
List Price:  Bs693.67
You save:  Bs208.12
COP$273,550.12
List Price:  COP$390,802.63
You save:  COP$117,252.51
₡35,067.63
List Price:  ₡50,098.77
You save:  ₡15,031.13
L1,728.60
List Price:  L2,469.54
You save:  L740.93
₲518,508.49
List Price:  ₲740,758.16
You save:  ₲222,249.67
$U2,722.73
List Price:  $U3,889.78
You save:  $U1,167.05
zł286.18
List Price:  zł408.85
You save:  zł122.66
Already have an account? Log In

Transcript

All right, so welcome back. Again, my name is Jessie. And in this session of the course, we try to see how to work with a very nice filmic library called fire to fire two by Google that allows you to automatically generate your life from any point, Python function, object or class. So let's see how to work with it. So first of all, to install it, just go with pip install file, or copy this one, and then I'll paste it here we are using Python three, which is good PIP three, then you'll be able to install it if it is very interesting. So it's easy to open of exposing your full component using this special option to fire fire class or you can also put a specific specific or particular function right.

So using a special option in which you pass in your function inside your class, they can to expose an entire class itself as well as variables. Then you can also expose a sink additionally of value of functions or values of any other stock disposal option of key value pair. So these are the various With you can actually export or convert your simple function object or class into a simple sealer. So in musi ally, when you're running hope you just go with this option without the dough justice. But in fact, to run help, you have to go with this option, right? It is an interactive option.

This is the trees that allow us to be able to check for trees step by step process to execute a particular function. So let's see what we did. So I've already started so let's move on to the way. And then let's create our sample file. It's going to create a sample file here called basic CRI, right? It's actually I've been doing, I'm going to be storing it inside our main file here.

To see space is going to be basic clr.pi. Very interesting. Now let's go to a credit. Listen, I've created a function called greet. That takes a name and then it prints out something like let's say hello Then, today Neela depends on us to run this particular function, how to fit a four quarter budget screen in our passing the name here, so let's say Tita Daniel, it, so I save it in the night he don't want to execute, it has to come back to my terminal, I'm using Windows 10. Now that I just go with my Python three, then I run it as basic CLR.

And it's going to execute it. I looked at it. Very, very interesting, because I want to change it up to keep on changing the name from Peter Daniel to Peter, Paul. And then if I run it again, it's going to bring it to picked up. So this is good, but it's not the best. So I want to commit a simple function into a CLA that I'll just have to pass in the name.

Daniel Dennett automatically gives me the result, right to make it reusable. So how do you do that to FFI gives you the option of doing that in a simple way. So let's see how to do that. We're just going to come back to this place to be for an input file. That is what I You need, then you take off this particular option, then you create an F made function, then you bring your fire, but fire classic. So this class is going to expose everything.

So it's going to expose everything, everything. Suppose every component that whether this class, whether it's a function or a bomb, so let's save it now. And let's come back again, without us and I hope it's going to give us instructions on how to use this selector. So this is going to be the name. So the name is going to be the name of the file, the synopsis, how to use it, so it's going to divide it into groups, which is a fact that itself right here, as you can see, or into commands, the commands are usually going to be the functions just trying to expose. So we have our grid function.

So to run this one, I have to come back again and go into grid. Then Peter, right. It's better not going to run it if it was Hello, PETA. Very, very simple, right? So with this option, it is good to expose everything that is a budget and To run it, you just call the function, they would have called a function from here, right with a grid, then you pass into the grid, and you pass in the name use. So this is giving you the option of doing this without actually writing that particular function by calling the function from the terminology, very interested in a very simple, right.

Very nice. Now, we can also export every component. So it's not only just functions, but in case I pass in a variable, so let's call it age, then I pass in the age of 24, for PETA, and I save it and I come back again. So this one to help is going to show me not only just the greet function, but also the age verb to start weakness group comma m value, right. Today group is a fire main class, the command is the function that we have here, right? And then you also have the value which is he right?

Very, very interested in real cool. So that is one of the ways of doing it. So without supplying it, it's going to give us the But to get the hook and just go with the justice, Justice help, it must be true, right? So it must be choose to allow to work around it. Now it's going to give us a CMT. Now we have added to be very interesting, very simple.

That is how to expose everything, and also expose class, let's create a simple class. That's good as employer. And now I can actually come back here, close this. And let's try it again. With the help, it's going to expose the class object also very interested to see we have our grid, we have our employee, right, very nice. So this option exposes every component, right?

Whether it is a function or a class. So let's see how to expose only a function to this puzzle a function is going to fire. So let me comment this one out. Let's create another one. So let's just also fire then to a spoon with a function. We have only the grid today.

So this is supposedly the grid Good, we're only going to explore the good and ignore the rest, right? So if I save it, do we have our employee class here, our ADA, only the greet will be exposed. So let's click off this and then let's run it again. That's only going to suppose holiday greets right to holiday great. It's been a spoof and it's picking up this particular brand name. So, it gets out you run it now, I can run it by this option by since you see that the center of the visit usually just how to use it.

So I just go with the ally, then Danny is referring to this particular name is Alisha Gute is been exposed by passing the name Jessie Hello Jessie very, very interested is how to expose a single function right? With this option is this exposes a single function right? That is how to expose a single function. So it gives you two we want to expose the class. Yes, do the same Then copy this one here. Then let's come back to this place and then pass in the class employee.

That's going to expose all the employee. So I can just see expose a single class. This one was needed to split a class or description. So let's come back here. And then let's run it again. To see that we have our basic position after the name and then we forgot listing of this to that at least we see one, then let's initialize it, right.

This one again, pivoted, and now it's giving us the employee as the only thing that we have right? As well as the x. So it gives these x a name. So let's say this one was named, making it quite nicer. To claim it's going to show that one maybe that's the x here, right? Just as we have x is equal to x.

Now see that not as his name, right so to to use it just go with the basic see Li then the name right to be able to exclude so let's print something from it. You can just make it like this for Deaf then presentation as you always do itself well let's go it's a print, print and we are printing employee brackets. format. Now Patsy my so totally saved this one and I come back here. See this play of this. Run it again.

Good to see that now that name is going to be specific Right, pivot, right. So for me to run it out, just run it in this particular option. So I just go with this Python, then I run it with the name, printed the name of the employer. And I specify the name as usual, it's going to print it perfectly for us retain it equals retention. So this is employee name, to show a premium to show plain English, that is how to work with it. Right?

Very, very interesting, very simple. So that is how to expose not just only the entire component, but a single function in a class. So let's see the next one of exposing multiple functions, who to expose multiple functions are going to be this option to fire that. Fire. Now passing the classes or the functions that own to expose the listing of this one, this command all of these and out. Let's create another function here.

Call it a C bye Passing the name doing the same thing day two or copy the sentence was only the same function I created, which is going to be this function and then we call it us Goodbye Goodbye right pivot. So, to expose these two functions are just without this right without passing it here, as we learnt is going to expose every function every component is also going to expose them together. can actually use it to get data to show move they see in a grid as the commands to greet see to so to run it is have to come back to the same thing here as greet. didn't pass in the name. There's going to write Hello, Peter, to work with the sea. Say bye.

Right? Goodbye PETA. So this option, and then this is going to expose everything as related. To specify these particular functions, you can just come back He said our function here, and then give it like we did here. So the simplest way is just create additional, right. So it's going to be, if I have this, you got to take the grid, as in, that's what you use, then grid, the grid function, right, then I can just come back again and see by so let's put it together like this.

And then you go with C by function. So this so this is how we are going to be calling it right. So we'll be calling it with this one. If I save it now, in the list, come back again. Close and then Randy hope to see how it works. For now you're going to have to greet and then they say bye.

So we have a greet see by right because as you can see you have our greet. Now see by so to qualify, you have to just go with this then greet suspended grades, then I can put it Yes. For the grades for the query to see by just go with C. Notice that there is no dash D, unlike the function that we have here, which has the dash right, because we are using this key value pay to export them, basically ran it again and see Hello, or goodbye. Or the basic idea about how to convert your functions your objects, your classes into a CLR using fire. So, the basic idea this input player, right your normal function, then you just expose it, expose everything with this option or expose a particular single function with this option. expose a class with this option or expose several functions, multiple functions with this custom bunches.

So I can actually make this one custom by going with I make this one ad right Let's see. Hi. Now if I come back into town to run it, it's going to be the high school. Let's go with to help me see that now is Heidi switch through it, I have to close this and then now run it again. They see to vote very well Hi. So I have to run it as Hi, Jane.

Right. Good to bring the Hello Jane. So that is very, very interesting. So we can you decide to customize the particular function or to call it how you wanted to call it. So thank you for watching and see you next session. Stay blessed

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.