Blogs

Blogs

Python API Tutorials| Getting Started with API’s

API is the acronym for Application Programming Interface, which is a software middleman that allows two applications to interact with each other. Each time we use an application like Facebook, send an instant message or check the weather on your phone and any other apps, you’re using an API.  Another example of an API is when you use an application on your mobile phone. The application connects to the Internet and sends data to a particular server. The server will redeem that data, demystify it, and send it back to your phone. The application then interprets that data and presents you with the information you need in a readable way .In this article, you will learn the basics of Python API and the step-by-step process to get started with APIs. How to Get Started with Python APIs To use an API, you have two options. The first option is to authenticate and the second option is not to authenticate and it depends on the kind of API you’re working with. We will demonstrate with two different examples. For us to get started with getting data or pulling data via the API, we will use a particular library in Python known as the Requests Library. This library is a standard package for making HTTP Requests in Python. There are other libraries for making HTTP Requests such as httplib, urllib, httplib2, treq. We can install Requests using the command; pip install requests conda install requests We also have different standard HTTP Methods;GET; to request data from the server. POST; to submit data to be processed to the server. PUT: Update an API resource DELETE: Delete an API resource A request is also made up of different parts: The method – these are the methods which we just discussed now and theyare the GET, POST, PUT and DELETE The Endpoint – when sending a request to the server, we have an endpoint known as the URL which we used for communicating to that server. The headers – The headers in a request are used to provide information about the request context so the server can know how to tailor our response such as the content type = application/JSON, authentication keys, and so on. The data/body – The data/body is usually used in both POST and PUT, with this, we can parse in the credentials we want to use to authenticate with the server. We must also not forget the status code returned after we sent our request. This status code helps in knowing if our request was successful or not. Examples of these different status codes are; 200(Ok), 201(Created), 404(Not found), 401(Unauthorized), 500(Internal Server Error) etc.   Getting the Data We’ll demo this with two different options we mentioned earlier which is getting data with Authentication or not, we will use these two APIs to implement this: IPify – a free API that allows you to get your current IP address(No Authentication) Google Calendar – An API used for tracking events and more(With Authentication) No Authentication We will use Ipify API with our Requests library to get data. With this API, we will observe that we don’t need any credentials to perform authentication before we can use the API.  The reason for this is that the API is an open one which makes it not require authentication. Sample API Request: #import the request library import requests #we then use the GET methods along with the requests library to retrieve data from the ipify server data= requests.get(‘https://api.ipify.org?format=json’) #we now convert our response data to json json_response=data.json() #we also extract our values we want it to return back to us. my_ip=json_response[‘ip’] #Then print our result print(my_ip) With Authentication To implement this, we will use the Google Calendar API. To get started, we need to create a new project under the google developer account by using this URL https://console.cloud.google.com and then set our details under Oauth Consent screen and Credentials tab. After you have completed the whole setup, we will download the credentials.json from the console page and use that to authenticate with the server. We will write a code to retrieve our calendar events after we have gained access to the API. Sample code #import the libraries needed from __future__ import print_function import datetime import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials # If modifying these scopes, delete the file token.json. SCOPES = [‘https://www.googleapis.com/auth/calendar.readonly’,’https://www.googleapis.com/auth/calendar.readonly’,’https://www.googleapis.com/auth/calendar’,’https://www.googleapis.com/auth/calendar.events.readonly’,’https://www.googleapis.com/auth/calendar.events’] #we create an empty list all_events=[] #we create a function main which has all our functionality def main(): creds=None #this if statement checks if we have a token.json file in our working path if os.path.exists(‘token.json’): #when token.json exist, it execute function to recognize/authorize this user creds = Credentials.from_authorized_user_file(‘token.json’, SCOPES) #this is another if statement which checks if we don’t have the credentials or the credentials has expired or not valid if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) #this else is to perform an authentication with the server using our credentials.json file and the SCOPES we specified else: flow = InstalledAppFlow.from_client_secrets_file(‘credentials.json’, SCOPES) creds= flow.run_local_server(port=0) #After authenticating, it writes out our result which contains an access token and other details which we can use often in our project with open(‘token.json’, ‘w’) as token: token.write(creds.to_json()) #we then read in the token file which has the access token and use this with the build method to access our calendar events service = build(‘calendar’, ‘v3’, credentials=creds) now = datetime.datetime.utcnow().isoformat() + ‘Z’ #we use the service method to check our events using our primary calendarId events = service.events().list(calendarId=’primary’, timeMin=now, singleEvents=True, orderBy=’startTime’).execute() all_events.append(events) print(all_events) if __name__ == ‘__main__’: main()

Blogs

Problem-Solving Skills| Improve Your Problem-Solving Skills in 2021

Introduction -In our day-to-day activities, we are all faced with problems or challenges we must overcome for us to move ahead. Let’s define what a problem is. A problem is regarded as a situation unwelcomed or harmful that needs to be dealt with. It can also be a question raised for inquiry, consideration, or solution. Problem-solving skill is highly essential for survival. This article will guide you on how to improve your problem-solving skills. Let’s dive right in.  What is problem-solving? It is raining and you have to go to the mall down the road to buy groceries. How do you get to the mall without being beaten by the rain? You can pick up an umbrella and rush down to the mall. On the other hand, you can decide to drive down in your car to the mall. That’s two solutions to a problem. You are free to go with the one that suits you. Problem-solving is an act of defining a problem, identifying, finding the root cause, prioritizing, and finding solutions to a problem. In simple terms, problem-solving is providing solutions to challenges or problems. Is problem-solving a skill? Problem-solving is a soft skill which like other skills, can be learned through education or training. It is a skill you can develop when you accustom yourself to recurrent issues in your field or industry and by learning from professionals.  It is an essential skill in the workplace and also in daily life.  This skill helps you to navigate through the issues of life. Why is Problem Solving Skill Important?  Having problem-solving skills will not only help you in your workplace but also in your daily life. Human beings are created to solve problems. Problem-solving skills possessed by great scientists were the reason for the great inventions we enjoy today. Breakthroughs in Medicine, Engineering, business, law, and other fields are a result of people coming up with solutions to problems. Imagine Micheal Faraday (the father of electricity) did not invent electricity! You’d probably not be reading this article on your device at the moment. Steps in Problem-solving Here, we will discuss the effective steps to take when you are solving problems. It’s important to follow these steps in the correct order if you want to solve a problem effectively. We’d be discussing five steps you must take to solve a problem. STEP 1: Identify and Define the problem This is the first step in problem-solving. This is the most important and the foundation of problem-solving. When you identify the problem, you are halfway to the solution. This is where you have to separate fact from opinion; ensure your statements are backed up with data.  Find out the root cause of the problem and not just the symptoms. Here you can ask the following questions: What is the problem? when did the problem start? STEP 2: Generate Possible Solutions The next step is to come up with different solutions. Brainstorming is one of the ways you can use it to generate solutions. A brainstorming session is where you generate lots of ideas both the ones that will make it to the final stage and those that you will have to discard. The brainstorming session is not where you evaluate the solutions you come up with. An important thing to keep in mind while brainstorming is “quantity over quality”. The more solutions you come up with, the higher the chances of having the best solution. You can brainstorm individually or in teams although having a brainstorming session with your teammates is preferable. STEP 3: Decide on a Solution After you have generated possible solutions, now is the time for you to sieve your solutions. You have to separate the wheat from the chaff. During your brainstorming session, you must have come up with solutions that cannot be implemented but couldn’t discard them because that’s not the aim of brainstorming. This step is where you analyze and select the best solution for the problem. You must have considered factors such as cost, resources, and timeliness while going for the solution you considered to be the best. STEP 4: Implement the solution Now that you’ve decided on a solution, this is the time to implement the solution. You have to act on and execute the solution you chose. It will be a total waste of time if you do not implement the solution you chose after going through the previous steps. STEP 5: Evaluate the results This is the final step in problem-solving and this is where you carefully evaluate your results.  You can do this after some weeks or months of implementing your solutions. For better evaluation of your results, ask the following questions: Did any new problems arise as a result of this solution? Are there possibilities that the solved problem will return? Problem-Solving Tools Fishbone Diagram- This is also called cause and effect or Ishikawa diagram and it is a visualization tool used in problem-solving. From its name, it takes the shape of a fish skeleton.  It is used to identify the root cause of a problem. The root problem is placed as the fish’s head and the causes project to the left, representing the bones of the skeleton. The ribs which branch off the back represent major causes while the sub-branches branch off of the causes and represent root causes. Flowcharts- A flow chart is a simple diagram that maps out a process so you can easily communicate it to your teammates. You can use a flowchart to show the operations and sequences needed to solve a problem. See a flowchart as the blueprint of a design you have created for solving a problem. Mind maps– A mind map is a useful tool in problem-solving as it helps you visually represent and structure your thoughts. It allows you to visualize problems and see the bigger picture at a glance, reduces stress, and awakens your creativity. How to Improve your Problem-solving Skills 1. Develop the right attitude Having a positive mindset and the right attitude while approaching problem-solving is key. In fact, do not see it as a problem rather as a challenge and an

Blogs

What is Tableau? Features and Uses

It is no news that data skills are high in demand in every sector of the business world. Businesses of all sizes, ranging from small to large are searching continuously for individuals that possess excellent data skills and the wise thing anyone would do is to jump on this data train heading to the future and equip him/herself with these skills that are high in demand.  One of these skills is maximum proficiency in Tableau. You might be wondering, “what is Tableau?”, “what does it do?”, “How does it work?”, etc. In this blog post, you will discover what this software is used for and basically how it works. What is Tableau? Besides the fact that it is a powerful and the fastest-growing data analysis tool in the Business Intelligence industry, it is the most secure and easy-to-use platform for analyzing your data. The great thing about this software is that it doesn’t require any kind of programming or coding skills to be able to understand and operate it. It can help anyone see and understand their data without the need for any advanced skills in data science. There are quite a few data visualization tools in the BI industry, but Tableau software seems to be the major buzzword. This is because it does not just analyze your data, it turns your data into golden insights that help make excellent business decisions. so don’t be surprised to see it leading in Gartner’s magic quadrant Are you still wondering why every organization wants someone with excellent skills in Tableau? I don’t think I am; the handwriting is on the wall. Who wouldn’t want someone that can operate a growth insight software? The software is a product suite with five (5) different tools; Tableau Desktop, Tableau Public, Tableau Online, Tableau Server, and Tableau Reader.     For a better understanding of data analysis in Tableau, these tools can be divided into two (2) groups:  Developer Tools: As you probably guessed, these are the tools used for development like creating dashboards and charts, or generating workbooks, reports, and visualizations. The tools in this category are Desktop and Public.  Sharing Tools: they are for sharing the visualizations, reports, dashboards, and workbooks created by the developer tools. Products in this category are Tableau Online, Server and Reader.  How does Tableau work?  The major function of the Tableau software is to extract data stored in various places. It can pull data from any platform imaginable. Take a moment to think about all the databases you know, ranging from simple ones like an excel or a pdf to complex ones like Oracle or even a database in the cloud like Amazon Web services (AWS), Google Cloud SQL, or Microsoft Azure SQL, name it; Tableau can extract data from all of them. How does it do that? It’s almost too easy. Once you launch the software, data connectors are available to help you connect to any database. Although, the number of supported data connectors can vary depending on the version of the software that you purchased and installed. The data that is pulled is extracted to Tableau Desktop, the software’s data engine. This is where the data analyst/engineer develops visualizations with the pulled data. The dashboards created are shared with the users as a static file that can be viewed using Tableau Reader. The data analyst can publish the data from Tableau Desktop to Server; therefore, users can access the files better from any location and on any device.     After reading all about Tableau, it’s features and uses, it is completely normal that you are feeling the need to become a master at this skill and launch your career on a whole different level. To download the tableau software to your computer, visit www.tableau.com. Not sure where to start? Cndro’s Tableau Training is just what you need if you want to understand Tableau and stand out among other professionals. It is a fully packed 8 weeks training that will take your proficiency in Tableau from zero to one hundred real quick. Click here to find out more about it. Once you start learning about this tool, you will realize how much of an eye-opener it is. 

Blogs

Automate AWS EC2’s Start and Stop using Lambda and CloudWatch

This post is a quick guide on how to automatically start and stop EC2 instances on Amazon Web Services (AWS). Amazon Elastic Compute Cloud (EC2) instances are like virtual servers on AWS. AWS is a cloud computing platform and EC2s help business subscribers run application programs on AWS. Let’s say, for example, a particular EC2 instance has been placed in your care by your organization. It needs to be turned on by midnight and turned off by 8 pm in the evening, which is quite absurd. You can choose to wake up every midnight to turn it on and cut your dinner date short to turn it off. You can also choose to dedicate 30 minutes only this one time to automate the entire process. In this post, we will quickly walk through how to automatically turn on and turn off these EC2s using Lambda and CloudWatch. All you need is an AWS Console root user or an IAM user with Lambda, CloudWatch and EC2 access. Oh!… and of course, 30 minutes of your time. STAGE 1: CREATE THE LAMBDA FUNCTIONS TO AUTOMATICALLY START/STOP EC2 INSTANCES Login to AWS Console: This is, of course, the first thing to do. Click the ‘Services’ drop-down menu and select Lambda under the Compute service. Choose the ‘Author from scratch’ option and a Basic Information form pops up with three fields: Function, Runtime, and Permissions. Put in your function name; “Start EC2” for example. Input your preferred programming language in the Runtime field. Python 2.7 was used in this case. In the Permissions field, you can choose to create a new role with basic Lambda permissions or use an existing role, if you already have one. To learn how to create a new role, check out our article on How to create an EC2 role. Hit that orange Create Function button to display a page where you can input your code. To create a Lambda function that automatically turns on an EC2 instance. Edit the code in the snippet below with the region and instance ID of the EC2 you are trying to automatically start. import boto3 region = ‘insert ec2 region’ instances = [‘insert ec2 instance ID’] ec2 = boto3.client(‘ec2’, region_name=region) def lambda_handler(event, context):     ec2.start_instances(InstanceIds=instances)     print(‘started your instances: ‘ + str(instances)) To create a Lambda function that automatically turns off an EC2 instance. The code is similar to the one in the snippet above, ‘start’ is just replaced with ‘stop’: import boto3 region = ‘insert ec2 region’ instances = [‘insert ec2 instance ID’] ec2 = boto3.client(‘ec2’, region_name=region) def lambda_handler(event, context):     ec2.stop_instances(InstanceIds=instances)     print(‘stopped your instances: ‘ + str(instances)) Our lambdas are ready, up next is CloudWatch. STAGE 2: CREATE CLOUDWATCH RULES TO TRIGGER THE LAMBDA FUNCTIONS Back to AWS Console.  Click the ‘Services’ drop-down menu and select CloudWatch under the Management and Governance service. In the CloudWatch dashboard, select Rules Hit the Create Rule button, select the ‘Schedule’ option and input the date and time you want your EC2 to start in the Cron expression field. In this study, the EC2 was set to start at 1:05 am every Monday to Thursday with a Cron expression of : 05 01 ? * MON-THUR* If you want to start your EC2 at 8 pm every working day of the week, for example, your Cron expression is going to be: 00 20 ? * MON-FRI* In the Targets section, select the Lambda function created earlier to turn on an EC2 instance. Hit the Configure details button, type in your preferred rule name and Create. The same process is undergone to create a rule that will trigger the stop Lambda function. The only thing that changes is the Lambda function you are targeting. Follow these steps properly to automatically turns on and off EC2 instances with Lambda and CloudWatch on Amazon Web Services (AWS).

Blogs

How to integrate Python with Tableau

It is no news that Tableau, as a business intelligence software, has made data visualization completely easy for both programmers and non-programmers. Python, on the other hand, is a programming language widely used in the world of data and it is most popular for its strengths in predictive analysis and machine learning. If somehow, we could possibly merge these two data analysis power tools together, integrate python with tableau; wouldn’t that result in a dream data science team for every organization?   In this article, I am going to walk you through how to leverage Python to enhance Tableau’s capabilities and use Tableau to visualize model outputs from Python. This integration completely eradicates the back and forth process of using Tableau to visualize data, going back to Python to structure the model, and bringing it back to Tableau again. All of these can be done in one place using the Tableau + Python server, also known as the Tabpy server. So, sit tight, and let’s get right to it.  To integrate Python with Tableau Desktop, there are, of course, a few steps that must be followed:  Step 1: Install TabPy   Download and install Anaconda. To do this, go to www.anaconda.com/distribution. Downloading Anaconda automatically installs Python and Pip for you. This will save you from the stress of trying to configure parameters for Tabpy.  Open the anaconda prompt, type pip install tabpy-server, hit the “enter” button on your keyboard to install the TabPy server. This may take 3 to 4 minutes.  Still, on the anaconda prompt, type pip install tabpy–client, hit the “enter” button on your keyboard to install the TabPy client. This may take 1 to 2 minutes.  Next, type pip install tabpy to install TabPy. This step is mostly omitted but it is quite necessary, to avoid bugs later into the integration. This may take about a minute. Finally, type tabpy on the anaconda prompt and “enter”. TabPy starts and listens on port 9004. Step 2: Integrate TabPy with Tableau Desktop  Now that we have the TabPy server up and running, the next thing to do is to integrate it with Tableau Desktop. To do this, follow these steps:  Launch Tableau Desktop.  Select “Help” in the top menu bar to display a dropdown menu.  Click “Settings and Performance” in the dropdown menu displayed.  Select the “Manage External Services Connections” option to display a popup.  In the popup displayed, fill in the following details:             Host Name: Local Host          Port: 9004  Select the Test Connection button to integrate TabPy with Tableau Desktop.  Once connection is successful, it only means that you have successfully integrated Python with Tableau using the TabPy server.  If you find this walkthrough helpful, please share. You can also leave a comment in the comments section if you have any question(s). 

Blogs

How to integrate R with Tableau

There are many languages used in the world of data analysis and R, as you probably just guessed, is one of them. According to Wikipedia, R is a language mostly used by statisticians and data miners to build statistical software and data analysis. Integrating R with Tableau will help you take advantage of R functions, packages and even models. Read on to find out how to integrate R with Tableau. Before integrating R with Tableau, it is important that you have both R and RStudio installed on your computer. To download and install R, visit www.cran.r-project.org/bin/windows/base/. For R studio, you can click here. It is important that you have both installed, because their individual functionalities depend on each other. Now, that you have both tools installed, let us proceed to set up Rserve. In case you have been wondering, “how EXACTLY am I going to integrate R with Tableau?” Rserve is the missing link, so let’s get right to it. Step 1: Launch your RStudio. Step 2: Type in “Install.packages(“Rserve”)” and hit the enter button on your keyboard. This process will install Rserve Step 3: Type “library(Rserve)” and hit the enter button to call the Rserve packages Step 4: Finally, type “Rserve()” to start R-Server. From the image below, you can see a walkthrough of all the steps I just listed. The next phase of integrating R with Tableau is going to be carried out on your Tableau Desktop. Open up your Tableau desktop, select Help in the top menu bar to display a dropdown menu. Click on Setting and performance, and select the “Manage external services” option as shown below: Fill in the same credentials (Server: Localhost, Port: 6311) as shown below and click Test connection.  Once the connection is successful, then it means that you have completely integrated R with Tableau

Scroll to Top