<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hemant Anand Khandare on Medium]]></title>
        <description><![CDATA[Stories by Hemant Anand Khandare on Medium]]></description>
        <link>https://medium.com/@hakhandare?source=rss-bed5cc4fc2cd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*oEDxOag1zX0u36AE</url>
            <title>Stories by Hemant Anand Khandare on Medium</title>
            <link>https://medium.com/@hakhandare?source=rss-bed5cc4fc2cd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:56:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hakhandare/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Send an email from Gmail using Python]]></title>
            <link>https://medium.com/@hakhandare/send-an-email-from-gmail-using-python-aa5a5d044fd0?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa5a5d044fd0</guid>
            <category><![CDATA[send-email]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Tue, 29 Mar 2022 15:48:40 GMT</pubDate>
            <atom:updated>2022-03-29T15:48:40.213Z</atom:updated>
            <content:encoded><![CDATA[<p>We will see how to send an email along with an attachment using your Gmail account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8C6K-QK7HOa74o9-j_1xQ.png" /></figure><p><strong>Prerequisite</strong>:<br>To get started I would suggest creating a new Gmail account and then trying this to make it work as we need to change the <strong>security settings</strong>.<br>Open the below link and turned on the less secure app setting.</p><p><a href="https://myaccount.google.com/lesssecureapps">https://myaccount.google.com/lesssecureapps</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KaQN3o1gpCpUEgYejcm9ag.png" /></figure><p>Once it is done, we can get started with the actual python code to send an email.</p><ol><li>import required python libraries.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*lpM8qssHMnEbFRNQIo20Ww.png" /></figure><p>2. Get <strong>to_address</strong>,<strong>from_address,</strong> and <strong>PWD</strong> from the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*_X2XYCgzUdLgXEdcAJeSAA.png" /></figure><p>3. initialize the MIMEMultipart instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*ep8E50Y8gSVuGO1A-pkbaQ.png" /></figure><p>4. declare the subject and body of the email and attach it to the MIMEMultipart instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCxy561nWJYT2OsHOlSEKQ.png" /></figure><p>5. create the sample text file under C: drive and name it <strong>“log.txt”</strong> and attach it to the MIMEMultipart instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*wpVkl7VxmU2g_yMALowZMA.png" /></figure><p>6. creates an SMTP session and set the SMTP details for the Gmail account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*9a9W5eb9qAApPcBUF8Hx3Q.png" /></figure><p>7. Authenticate with a Gmail account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*LEBb1bMmhDZeUmjCPraaCg.png" /></figure><p>8. Converts the Multipart msg into a string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*euL-OK1gCVIy9bGYNJqlgQ.png" /></figure><p>9. sending the mail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*MAWpR1I9uJ6t4snBiAtBWw.png" /></figure><p>10. terminating the session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*OmHYdUdpetAV_8XNuMFclg.png" /></figure><p>Execution log:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ktnlpQdECYj_vLddKhE8lg.png" /></figure><p>You would see, an email is received in your to address mailbox.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*XGRft_bFveSHspvYuMAuwQ.png" /></figure><p>Please refer to the below GitHub link for the code.<br><a href="https://github.com/hemantakhandare/Python/blob/master/send_email_from_python.py">https://github.com/hemantakhandare/Python/blob/master/send_email_from_python.py</a></p><p>Thanks for your time!!!</p><p>Enjoy your day!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa5a5d044fd0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Offload the BigQuery select result to the GCS bucket using Python.]]></title>
            <link>https://medium.com/@hakhandare/offload-the-bigquery-select-result-to-the-gcs-bucket-using-python-45e1f50a0a5f?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/45e1f50a0a5f</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[bigquery]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Fri, 25 Mar 2022 15:18:07 GMT</pubDate>
            <atom:updated>2022-03-25T15:18:07.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*Ii2Ur4TOkXWopxzgCtzhWQ.png" /></figure><p>You might be aware that, we can not write the bigquery result directly to the GCS bucket.</p><p>To do that, we first need to write the query result to the bigquery native table and then extract the data from that table to the target location as a GCS bucket.</p><p>Here we will see how we can directly write the bigquery query result to the GCS bucket without needing it to write the table.</p><p>As usual, to interact with GCP services using third-party applications, we need to set up the authentication with GCP.</p><p>To get started, we need to create the service account and download the service account key to your local system.</p><p>Please refer to the below article to create and download the service account key.</p><p><a href="https://medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899">How to set up Cloud Composer Environment and set up a connection to bigquery.</a></p><h3>Let’s dive into a practical demo to understand the concept.</h3><ol><li>Open the python IDE, I prefer the Jupiter Notebook.</li><li>Install the required libraries.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*7_l3dhp_5kMfek97uygNUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*lMfqsmget_qACMbXgRMYyw.png" /></figure><p>3. import the libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*ufmXGM-b2F-nyJGFqmC5xg.png" /></figure><p>4. Set up the authentication with GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KL87q5pWJN2lRzebjYCuSg.png" /></figure><p>5. Read query data into data frame using pandas_gbq.read_gbq() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kblEtLIhFX2hlkvJ2HgLdQ.png" /></figure><p>6. Write the data frame to the GCS bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gr2e-H0bIxNvGHuRQE6tcQ.png" /></figure><p>7. List blobs in a bucket to check the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*zVuYhYgIBCRSYLjHKVUO8w.png" /></figure><p>Please refer to the below Git-hub link for the code.</p><p><a href="https://github.com/hemantakhandare/Python/blob/master/write_panda_df_to_GCS.py">Python/write_panda_df_to_GCS.py at master · hemantakhandare/Python</a></p><p>Thanks for your time!!!</p><p>Enjoy your day!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45e1f50a0a5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCP Airflow template_searchpath Explained]]></title>
            <link>https://medium.com/@hakhandare/gcp-airflow-template-searchpath-explained-c2b1e7bec9dc?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2b1e7bec9dc</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[google-cloud-composer]]></category>
            <category><![CDATA[airflow]]></category>
            <category><![CDATA[gcp-data-engineer]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Wed, 23 Mar 2022 15:46:38 GMT</pubDate>
            <atom:updated>2022-03-23T15:46:38.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*AGQQ8jNt5tMxgp3cd-crAA.png" /></figure><p>Let’s assume you want to execute the long SQL code using Airflow on a daily basis using the Airflow orchestration tool.</p><p>How would you do that ??<br>Yes…. right. Using Airflow operator which supports Bigquery.</p><p>Airflow has provided multiple Bigquery Operators to execute the SQL and <strong>BigQueryInsertJobOperator</strong> is one of the operators which executes the SQL&#39;s specified in the Query parameter.</p><p>Now we know to execute the SQL or Long SQL statement Airflow has provided <strong>BigQueryInsertJobOperator </strong>which runs the SQL statement,</p><p>But the next question is how would you write a DAG file which is nothing but a python script to embed the SQL statement.</p><p>Would you simply hardcode the SQL statement inside the variable and refer to it in the Operator?</p><p>or</p><p>Would you keep the SQL file outside the code and refer to it?</p><p>The ideal code design approach is don&#39;t hardcode the SQL inside the script and refer to the SQL file path inside the DAG(python script).</p><p><strong>To create a python script in Airflow, we simply need to follow 5 steps</strong></p><ol><li>Import required libraries.</li><li>Set default argument variable.</li><li>initiate the DAG variable for all the task operators.</li></ol><p>4. define the task action using the operator. (three types of operator sensor, transform, transfer)</p><p>5. set dependency for the task.</p><h4>Let&#39;s dive into a practical demo to understand the concept.</h4><p><strong>Scenario:<br></strong>Write the Airflow DAG to execute the Long Bigquery SQL script.</p><ol><li>Open the text editor, I prefer notepad ++ and change the language to Python.</li><li>Let’s follow the steps mentioned above,</li></ol><p>Step 1. Import required libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfSiOrLnupnTzraGBsjHjQ.png" /></figure><p>Step 2: Set default argument variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*eLcSigKySiVg91S0CkJ6ZA.png" /></figure><p>Step 3: initiate the DAG variable for all the task operators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgTQ4jpCCBkB0phl24q2kA.png" /></figure><p>The template_searchpath argument in the DAG definition tells the DAG to look in the given folder for scripts, so we can now put our SQL scripts in the scripts/ directory. In this example, this script is <strong>‘testsql1.sql’</strong>, which contain the following SQL code respectively:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*1E6TNCNgBoW-XO5qpEgepQ.png" /></figure><p>Step 4: define the task action using the operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*Nr6m_cTUgKJBhJ9Fdji3HQ.png" /></figure><p>I have defined the <strong>BigQueryInsertJobOperator </strong>two times to show both ways to execute the SQL(with and without SQL hardcode)</p><p>For the second occurrence of <strong>BigQueryInsertJobOperator, </strong>I have used the jinja template to refer the SQL code file placed in the GCS bucket under the DAG_HOME/script directory.</p><p>If you want to include some files in your configuration you can use include clause of the Jinja template.</p><p>If you want to know the Airflow configuration path, go to the Admin&gt;&gt;Configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UFhCnmhu27gPH0mTZG7Frw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*qHu5dmRYrqkMqm91qNcjDQ.png" /></figure><p>Step 5: set dependency for the task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*hqTWfLIeMRZo9wLjFnUuPg.png" /></figure><p>3. Save the file as biquery_test.py</p><p>4. Place the file in the DAG folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMXbBqFg0BMZba5uB7B5uw.png" /></figure><p>5. Wait for some time to reflect the code in the Airflow web console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AO21vUXhrl_MtEyH9823wQ.png" /></figure><p>6 . Trigger the code manually to see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvE5BYgcIaHtb0wCOL13kw.png" /></figure><p>7. Check the output.</p><p>#I have used the insert table statement for this demo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*wQigj2ZEKsXvnApq-9wcFw.png" /></figure><p><strong>Please refer to the below Github link for the code.</strong></p><p><a href="https://github.com/hemantakhandare/Python/tree/master/Airflow_templatePath">Python/Airflow_templatePath at master · hemantakhandare/Python</a></p><p>Thanks for your time!!!</p><p>Enjoy your day!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2b1e7bec9dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load Data from CSV File to Bigquery using Python bigquery client Library.]]></title>
            <link>https://medium.com/@hakhandare/load-data-from-csv-file-to-bigquery-using-python-bigquery-client-library-543b677590e8?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/543b677590e8</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 09:48:20 GMT</pubDate>
            <atom:updated>2022-03-22T09:48:20.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*bOQUvXZK8GShDdEAie3pQQ.png" /></figure><p>We will explore the python bigquery client library to ingest the data into the Bigquery table.</p><p>As usual, to interact with GCP services using third-party applications, we need to set up the authentication with GCP.</p><p>To get started, we need to create the service account and download the service account key to your local system.</p><p>Please refer to the below article to create and download the service account key.</p><p><a href="https://medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899">How to set up Cloud Composer Environment and set up a connection to bigquery.</a></p><ol><li>Open the python IDE, I prefer the Jupiter Notebook.</li><li>Install the <strong>google-cloud-bigquery</strong> library.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*GOUWFXFpZ4oTXuxfyc0z_A.png" /></figure><p>3. import the <strong>google-cloud-bigquery, os</strong> library, and set up the authentication with GCP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2IukczjyADlavpVjvLKcvg.png" /></figure><p>4. Construct a BigQuery client object.</p><p><strong>client = bigquery.Client()</strong></p><p>5. set the table id (Project name.dataset name.table name) and local CSV file path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*ZLqTpqk09c-bNT8KrzGodg.png" /></figure><p>6. create the job_config to execute the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*No4KGnK5vWQJ6Mhrj6ErFA.png" /></figure><p>#this job config would create the table if the table does not exist.</p><p>7. read the CSV file in binary mode and use <strong>load_table_from_file()</strong> method to ingest the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kAFlaofX_p01KSI6lym72A.png" /></figure><p>8. wait for the job to complete the execution.</p><p>job.result() # Waits for the job to complete.</p><p>9. print the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EY2QAzeQD5Wi99pcyxZk5A.png" /></figure><p>10. check the table in bigquery to see the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*7tPZzAhCvleB0DW0Pltasg.png" /></figure><p>#Please refer to the below git link for the code.</p><p><a href="https://github.com/hemantakhandare/Python/blob/master/load_data_to_bq_from_csv_client_lib.py">Python/load_data_to_bq_from_csv_client_lib.py at master · hemantakhandare/Python</a></p><p>Thanks for your time!!!</p><p>Enjoy your day!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=543b677590e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect GCE VM (Unix) instance using Putty.]]></title>
            <link>https://medium.com/@hakhandare/how-to-connect-gce-vm-unix-instance-using-putty-a628baecb1b1?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a628baecb1b1</guid>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[putty]]></category>
            <category><![CDATA[gce]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Sun, 20 Mar 2022 07:44:36 GMT</pubDate>
            <atom:updated>2022-03-20T07:44:36.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YVNyVUMq04euxJSKCY1WWA.png" /></figure><p>This concept is based on the basics of a passwordless authentication system.</p><p>In an authentication system where Linux servers are involved, we first generate the ssh key using the <strong>ssh-keygen</strong> command, and then after successful execution, we get two files</p><p>1. private key</p><p>2. public key</p><p>Private will be kept at the user side while authenticating to the server.</p><p>The public key will have to be copied to the target server for authentication.</p><p>Let’s dive into the demo.</p><ol><li>Spin up the GCE instance.</li><li>Download and <a href="https://www.puttygen.com/download-putty">install the PuTTY</a> on your local machine.</li></ol><p>#PuTTYgen is used to generate public or private key pairs for creating SSH keys.</p><p>3. Once you <a href="https://www.puttygen.com/download-putty">install the PuTTY</a> on your machine, you can easily run PuTTYgen. For the same, go to Windows -&gt; Start Menu -&gt; All Programs -&gt; PuTTY -&gt; PuTTYgen.</p><p>4. Click on the generate button and hover your mouse over the blank area to generate the keys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*9Vwfllv-Z3pe3E2Rs7npKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*0-dv3Ngq2y6T5HJbqwiWcQ.png" /></figure><p>5. Under <strong>Key comment</strong> mention the name(user account) that you would like to create in the GCE instance.</p><p>6. Copy the complete ssh public key and paste it into the metadata under the GCP web console.</p><p>Under compute Engine&gt;&gt;Metadata&gt;&gt;edit&gt;&gt;ssh keys&gt;&gt;add items</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*reeI9E8lbqtdmiT4lfZfIw.png" /></figure><p>Paste the public key and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*MHYMcxLAok2OM6Yz3piciQ.png" /></figure><p>7. Click on the Save private key and save it to a local directory on your laptop and note down the path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*8Q0eeicymRbo54sBdC34Xw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*ENPqFGgGg8tU86qnxfTxsg.png" /></figure><p>8. Go to the VM instance and copy the external IP address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V8juFqN6vl8s1aScWIx8Ig.png" /></figure><p>9. Open the putty and locate the Auth and browse your downloaded private key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*xZlqkz1WdsKJ64Ook-9Rng.png" /></figure><p>11. Click on the session and paste the VM external IP address and hit on Open to connect the VM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*yGmoSIo9CarzwT2kn1mqZQ.png" /></figure><p>12. It would prompt you to enter the login name, type the name mentioned under step 4 Key comment, and you are done!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*vm3nwvrGmfGhC1zjC22yaQ.png" /></figure><p>Thanks for your time!!</p><p>Enjoy your day!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a628baecb1b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New Cool Features in GCP Feb-22]]></title>
            <link>https://medium.com/@hakhandare/new-cool-features-in-gcp-feb-22-3f13caf92416?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f13caf92416</guid>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 16:03:59 GMT</pubDate>
            <atom:updated>2022-03-13T16:03:59.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*KzODqQ-piOcwleNU-3pyxg.png" /></figure><p>Was navigating the google documentation for some work and found this very helpful.</p><ol><li>Google Launched a Cloud Architecture Diagramming tool.</li></ol><p>Link: <a href="https://googlecloudcheatsheet.withgoogle.com/architecture">https://googlecloudcheatsheet.withgoogle.com/architecture</a></p><p>2. New version of the <a href="https://goo.gle/GCdevelopercheatsheet">Google Cloud Developer Cheat Sheet</a></p><p>Link: <a href="https://googlecloudcheatsheet.withgoogle.com/">https://googlecloudcheatsheet.withgoogle.com/</a></p><ol><li><strong>Google Launched a Cloud Architecture Diagramming tool.</strong></li></ol><p>The very first step in the architecture is the diagram, which acts as a blueprint for every use case.</p><p>This tool would help us to visualize the entire pipeline right from data ingestion to the data consumer. We just need to drag and drop the GCP component and place it over the canvas.</p><p>Once you are done with it, we can deploy the entire pipeline with a single click.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cg8qSXpzF6g8y5fzlVXySw.png" /></figure><p>This feature is still under development but to get a look and feel you can try their prebuilt diagram and get the hands-on tool.</p><p>Link for prebuilt diagram:</p><ol><li><a href="https://googlecloudcheatsheet.withgoogle.com/architecture?diagram=SimpleComputeApp">https://googlecloudcheatsheet.withgoogle.com/architecture?diagram=SimpleComputeApp</a></li><li><a href="https://googlecloudcheatsheet.withgoogle.com/architecture?diagram=ThreeTierApp">https://googlecloudcheatsheet.withgoogle.com/architecture?diagram=ThreeTierApp</a></li></ol><p>Eg. I have created one use case where I wanted to add labels to the GCE instance as soon as someone spin-up the new instance in the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PFbiYbnw0d0LiBOhLCmWw.png" /></figure><p>2. <strong>New version of the Google Cloud Developer Cheat Sheet</strong></p><p>This new version has made the developer task very simpler to search the documents for the GCP services. It’s a dashboard of all the GCP services. We just need to click on the service you are interested in and get all documentation details.</p><p>It has a <strong>list view and map view</strong> to explore the services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7PzHTnLX-lESpb5GQtQsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KywjSwAYYjxdPjGBlS9TuA.png" /></figure><p>Thanks for your time!!!</p><p>Enjoy your day!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f13caf92416" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOW TO LOAD DATA INTO GOOGLE BIG QUERY FROM PYTHON PANDAS]]></title>
            <link>https://medium.com/@hakhandare/how-to-load-data-into-google-big-query-from-python-pandas-5d2b3196ff96?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d2b3196ff96</guid>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Wed, 09 Mar 2022 14:20:01 GMT</pubDate>
            <atom:updated>2022-03-09T15:37:11.128Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*5JF9t4exq7N6JlAeqGN4tQ.png" /></figure><p>We will explore the python pandas and start to interact with Google Bigquery to ingest and query data.</p><p>As usual, to interact with the GCP service we need to set up the authentication first using the service account JSON key.</p><p>For more details on how to create the service account and download the JSON key please refer to the below link.</p><p><a href="https://medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899">How to set up Cloud Composer Environment and set up a connection to bigquery.</a></p><ol><li>Open the python IDE, I prefer the Jupiter Notebook.</li><li>Install the pandas-gbq library.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*Xa46oGAAzKACknKnho4lMw.png" /></figure><p>3. Set the authentication with GCP using the service account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjF--jkdA12AlaYnar0Myg.png" /></figure><p>4. Import the gbq library.</p><p>import pandas_gbq</p><p>5. Set the project id.</p><p>project_id = “rising-cable-340114”</p><p>6. Store the SQL statement inside the variable.</p><p>sql = “””<br>SELECT * FROM `rising-cable-340114.mydataset1.<strong>emp1</strong>`<br>“””</p><p>7. execute the command.</p><p>df = pandas_gbq.read_gbq(sql, project_id=project_id)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yFq9bf_Fi28ZzRJPgYr5mQ.png" /></figure><p>8. Print the dataframe to see the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*CysDgjF-9al5kioYYtuARQ.png" /></figure><p>9. Load the data frame output to the bigquery table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVyyGY03HUOnLCr9La8pDg.png" /></figure><p>Please note the if_exists parameter=”<strong>replace</strong>” ,<br>This would re-create the new table every time the statement is executed.<br>There is another option “<strong>append</strong>” which would just append the new data to the table.</p><p>10. Check the table in bigquery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*5hLDSVRuFxvLYWaNZISw9g.png" /></figure><p><strong>Additional</strong>:</p><p>You may read the CSV file using panda and convert it to a data frame and that data frame can be dumped into the bigquery.</p><p>eg: #read CSV file to convert it to a data frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgC196SRoV_HaCdRo9Gcdg.png" /></figure><p>Github link for code reference:</p><p><a href="https://github.com/hemantakhandare/Python/blob/master/Working%20with%20panda%20GBQ%20bigquery.py">Python/Working with panda GBQ bigquery.py at master · hemantakhandare/Python</a></p><p>Thanks for your time!!!</p><p>Enjoy your day!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d2b3196ff96" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect GCP services using Python Jupiter Note Book.]]></title>
            <link>https://medium.com/@hakhandare/how-to-connect-gcp-services-using-python-jupiter-note-book-d62b8566f29b?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d62b8566f29b</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[jupiter]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[bigquery]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 11:03:06 GMT</pubDate>
            <atom:updated>2022-03-08T12:01:27.193Z</atom:updated>
            <content:encoded><![CDATA[<p>We will discuss here how we can set up GCP authentication using python Jupiter Notebook and test the different GCP services using client libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*E1qkoofExPPK_501inFrjQ.png" /></figure><ol><li>The first very basic step is to set up authentication with GCP using the service account.</li></ol><p>If you want to know how to create the service account and download the JSON key, refer to the below article.</p><p><a href="https://medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899">medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899</a></p><p>2. Note down the entire windows path where the file is downloaded or else keep that in another folder and copy the entire path.</p><p>3. Open the Jupiter Notebook.</p><p>4. We will try to connect Bigquery client. We need to install the required client lib for bigquery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*vWd3prLpfgdF4qh0f7VKWg.png" /></figure><p>5. Import the library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*tbFvs61ekdVVGYSN8eYZKA.png" /></figure><p>6. Set up GCP authentication with python notebook.</p><p><strong>os.environ[“GOOGLE_APPLICATION_CREDENTIALS”]</strong>=r”C:\Users\hemant.khandare\Desktop\python\rising-cable-340114–2e9cf13ab951.json</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWEe2thlPiqCYOn6xw6QVA.png" /></figure><p>7. Initialize the bigquery client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*Vm8RXCJNkdDYFHei_Q5G_Q.png" /></figure><p>8. Bigquery client is ready, we can now interact with bigQuery. Let’s try to run the select query.</p><p>Store the entire select query under the SQL variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*pI3vW5Ub_USe0eXGZ_qFFw.png" /></figure><p>9. create the variable query_job and pass the SQL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*TffzKsP0AspIb9vTLHdSIQ.png" /></figure><p>10. Execute the query_job and wait for the job to complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*gqO58Uz3SdPyZVvK_BQc7Q.png" /></figure><p>11. Read the query output, please note here the table in the select query has two columns of type string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*ppFlVkMMJ8IriAxKCzvgwQ.png" /></figure><p>You may try different methods such as insert, delete, create a table.</p><p>12. Let’s try to insert one record into the table using the insert method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOhNF2Yr6M-wIUFiCLqMFg.png" /></figure><p>13. Run all the statements from steps 9 to 11 and see the new row inserted into the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*u6CqOdkLJrxW6RITIwLRFA.png" /></figure><p>Thanks for your time!!!</p><p>Enjoy !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d62b8566f29b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to connect Google Bigquey using Microsoft excel.]]></title>
            <link>https://medium.com/@hakhandare/how-to-connect-google-bigquey-using-microsoft-excel-582bb7c3dbef?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/582bb7c3dbef</guid>
            <category><![CDATA[gcp-data-engineer]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 13:25:59 GMT</pubDate>
            <atom:updated>2022-03-04T13:44:52.301Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*8cus_tAGiAplGa4AiU5tOg.png" /></figure><p>This article is based on the concept of ODBC DSN connection. We just need to configure the DSN and get started.</p><p>If you are from an Oracle background you might have used this method to connect Oracle DB using ODBC DSN from your excel.</p><p>The only difference here is the driver, for google bigquery we need to download the driver first to appear under the driver’s list while configuring the ODBC connection.</p><p>Let’s go step by step :</p><p>1&gt;Download the ODBC driver for Bigquery.</p><p><a href="https://cloud.google.com/bigquery/docs/reference/odbc-jdbc-drivers">ODBC and JDBC drivers for BigQuery | Google Cloud</a></p><p>Depending on your Machine download the required version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*1ehGg1F-jJ3ARequgFIlrA.png" /></figure><p>2&gt; Installation is very simple, just click next ..next and Finish.</p><p>3&gt;On your windows machine, in the taskbar type ODBC and then open the ODBC page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*F-ZRAPiX0uW4XuPz7344gw.png" /></figure><p>4&gt;Click on the Add to create a new data source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*DyTZHVkw0ulmrCL8PwL44g.png" /></figure><p>5&gt;Select Simba ODBC Driver for Google Bigquery and click finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*V00SwqeslELHxWW7jwpotQ.png" /></figure><p>6&gt;Fill in the required details:</p><p>&gt; Data source name →“excel_to_biquery_conn”.<br>&gt;Under authentication Keep it as “Service Authentication”.<br>&gt;Under service authentication:<br> email — -&gt; This should be your service account email id.<br>eg. <a href="/service/mailto:bigquey-conn-test@rising-cable-340114.iam.gserviceaccount.com">bigquey-conn-test@rising-cable-340114.iam.gserviceaccount.com</a></p><p>Key File Path → File path of your downloaded service account json key.</p><p><strong>For more details on how to create the service account please refer to the below article.</strong></p><p><a href="https://medium.com/@hakhandare/how-to-set-up-cloud-composer-environment-and-set-up-a-connection-to-bigquery-e470efeee899">How to set up Cloud Composer Environment and set up a connection to bigquery.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*fDv3ABSN1SxaLssfk0iVPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*IAl94RXfWiyo6HegZWMqrQ.png" /></figure><p>7&gt;Select the project and dataset and hit on the test button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*9kuCsFc3aDncsM7g9W8YTw.png" /></figure><p>You would get the success message. Click ok &gt;&gt;ok</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*w3w7v4SRIgX5i0_o1Ron6w.png" /></figure><p>8&gt;Now, we are ready to use the newly configured bigquery DSN to connect bigquery from Excel.</p><p>9&gt;Open blank excel &gt;&gt;Go to Data tab&gt;&gt;Click on the Get Data&gt;&gt;From Other sources&gt;&gt;From ODBC</p><p>10&gt;select the DNS connection that we configured earlier. Click ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*GSXnyS6WguWmfo5pMvI8aw.png" /></figure><p>11&gt;Click on the Advanced options and in the SQL statement write your query.</p><p>Click ok.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*Xa2VOflz4UC3YFfoSSL6QA.png" /></figure><p>12&gt; This would open the authentication window.</p><p>user name: Your GCP project email which you use to log in GCP account.<br>password: add password<br>Leave the Credential details and click connect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*rIU7lAiBp8FofvN_P-D7qA.png" /></figure><p>You would see a new pop-up window with the desired resultset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFkduNe6-rCXqwP4XuQKIw.png" /></figure><p>13&gt; select the action as per your need from the available options.</p><p>Thanks for your time!!!</p><p>Enjoy your day :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=582bb7c3dbef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to execute shell script from GCE instance using Python.]]></title>
            <link>https://medium.com/@hakhandare/how-to-execute-shell-script-from-gce-instance-using-python-94ab3f336262?source=rss-bed5cc4fc2cd------2</link>
            <guid isPermaLink="false">https://medium.com/p/94ab3f336262</guid>
            <category><![CDATA[gcp-cloud-architect]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[gcp-data-engineer]]></category>
            <category><![CDATA[google-compute-engine]]></category>
            <category><![CDATA[gcp]]></category>
            <dc:creator><![CDATA[Hemant Anand Khandare]]></dc:creator>
            <pubDate>Wed, 02 Mar 2022 17:09:22 GMT</pubDate>
            <atom:updated>2022-03-03T04:41:27.699Z</atom:updated>
            <content:encoded><![CDATA[<p>I was going through one use-case wherein I wanted to execute small Unix shell script code residing on the GCE UNIX instance using Python programming. I did some research and finally achieved the results.</p><p>You can use this code for your cloud function code to automate the small shell script code execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*KY4sfHiHYcphzjvr9ELHZw.png" /></figure><p>Step 1. Spin up the GCE instance.</p><p>Step 2&gt; From the GCP console , open the GCE instance by clicking on the SSH .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ij-2ZnfF1485PbrDVE7AdQ.png" /></figure><p>Step 3&gt;fire the below command to login as root</p><p><strong><em>sudo su -</em></strong></p><p>Step 4&gt; edit the sshd file.</p><p><strong>root@instance-1:~# vim /etc/ssh/sshd_config</strong></p><p><strong>Search for keyword password authentication &gt;set it to yes from no</strong></p><p><strong>root@instance-1:~# service sshd restart</strong></p><p>Step 5&gt;create a new user and set the password</p><p>root@instance-2:~# useradd virat<br>root@instance-2:~# passwd virat<br>New password:<br>Retype new password: passed:<br>password updated successfully</p><p>Step 6&gt; Copy the code from github to your python IDE, I prefer Jupiter Notebook to test the result.</p><p><a href="https://github.com/hemantakhandare/Unix/blob/master/connect_gce_from_python/connect_GCE_instance_unix_v2.py">Unix/connect_GCE_instance_unix_v2.py at master · hemantakhandare/Unix</a></p><p>Step 6&gt; Install the client library <strong>paramiko </strong>before running the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVeFU_aVNCdgUGc-jqTznw.png" /></figure><p>Step 7&gt; Shell script output from GCE instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pcdSg-uQSdJgyoYiNWrKHw.png" /></figure><p>Thanks for your time!!</p><p>Enjoy!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94ab3f336262" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>