Omar  Amin

Omar Amin


Export Worksheets as CSV file with Google Sheets API in Python

In this tutorial, I will be covering how to export Google Sheets worksheets to CSV files with Google Sheets API in Python.

To install Google Client library

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib Source Code:…

Google Sheets API Reference:…

Source Code:…



What is GEEK

Buddha Community

Export Worksheets as CSV file with Google Sheets API in Python
Ray  Patel

Ray Patel


top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

1) swap two numbers.

2) Reversing a string in Python.

3) Create a single string from all the elements in list.

4) Chaining Of Comparison Operators.

5) Print The File Path Of Imported Modules.

6) Return Multiple Values From Functions.

7) Find The Most Frequent Value In A List.

8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

Ray  Patel

Ray Patel


Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map

Marcelle  Smith

Marcelle Smith


Google Sheets, Meet Pandas DataFrame

Maybe it’s from too many hours behind the keyboard. But sometimes my reading and watching on the internet gives me the feeling I’m one of an endangered species of developer. One who’s working inside spreadsheets. Every single day.

Can you believe it? Developers, going about their lives like spreadsheets don’t exist. If you are one of these people, I’d like to meet you. To know that you exist, and this isn’t all a paranoid rant raging between my ears.

For the rest of us, spreadsheets are very much a thing. Love them or hate them, those binary rows and columns are going nowhere. To cut the philosophy lesson short: spreadsheets are. Every non-developer employee save the cleaning staff lives inside spreadsheets.

“Spreadsheets are.” Submit this existential bombshell to a university; an honorary doctorate in philosophy is sure to follow.

Excel and Google Sheets, they’re going nowhere; neither is our productivity until we put automation between us and the knowledge worker ritual of passing the spreadsheet.

My Two Cents in Three Paragraphs

Personally, I love a good spreadsheet. For munging data, quick and dirty calculations, visualizing 1-dimensional times series… 4 out of 5 times I will open Excel or Google Sheets, rather than fire up a Jupyter server.

Except, spreadsheetitis in a business is a symptom of not knowing how to move data. I have personally seen the “human router” problem so bad where more than 20 (twenty!) people touched a version of a spreadsheet before it was finally–mercifully–put to rest in “the database” (another spreadsheet).

And THE Spreadsheet. You know the business is in data hell when there’s The Spreadsheet, with a capital “S”. The one managers think is the business.

Automate Your Way to Sanity

There’s a few libraries we will talk about using for Google Sheets I/O in Python. No matter the approach, you have to enable the Google Sheets API inside the maze-like console for Google Cloud Platform (Google’s version of AWS and Azure). Fortunately Google–go figure–has a great search feature in the console that we’ll use to get you set up.

Insanity First — Getting a credentials.json file from Google Cloud Platform

Go to, sign in with the Google account with access to the spreadsheet you want to automate. The API is available for both GSuite and free Google accounts. If it’s a work-owned spreadsheet, the admin with GCP access is going to have to follow these steps and give you the credentials file.

Select the project in the navbar on the top. Every resource is kept inside a project, like resource groups in Azure. If you do not have one yet, select the project dropdown and “NEW PROJECT”. Then search for “Google Sheets API”, which if you are a sadist and want to explore the dashboard by mouse, is under “APIs & Services”.

Image for post

“Enable” the API.

Now you need to do the same for Google Drive API.

Image for post

Next up, you need to create a service account, which you will then create credentials for.


  • You are in Google Cloud Platform > Google Sheets API at
  • Go to credentials 🗝 Credentials on the sidebar.
  • Select + CREATE CREDENTIALS > Service Account. OAuth is a different story. This article covers a server-side, in-house use. Create the service account.
  • Next view is to select an IAM role for the service account. This is optional, skip it.
  • Next up is “Grant users access to this service account (optional)”. Also skip.

Image for post

Image for post

Now you are back on the “Service accounts for project [PROJECT NAME]” screen. Select the service account in the table, either clicking on the hyperlinked Email field, or hamburger menu (three dots) > Create key.

Either way, ADD KEY or Create key, select JSON key type and CREATE. This downloads a JSON file to your computer.

Image for post

Last thing: the spreadsheet. Here I created one for this example. Note the highlighted section of the URL in the Omnibar. That is the document’s ID. Most libraries give the choice of referencing the whole URL or just this ID.

Image for post

You can take a look at and download the spreadsheet from here.

Open the credentials.json file you downloaded from GCP for the service account. Copy the email value in the client_email property. Share the Google Sheet with this email. This gives the service account access to the spreadsheet, which was created on another account (not the service account).

Phew. That’s all the Google infrastructure stuff. I promise.

Now we can get down to business writing Python code.

#google-sheets #python-programming #python-libraries #google-drive-api #google-cloud-platform #api

Top 10 API Security Threats Every API Team Should Know

As more and more data is exposed via APIs either as API-first companies or for the explosion of single page apps/JAMStack, API security can no longer be an afterthought. The hard part about APIs is that it provides direct access to large amounts of data while bypassing browser precautions. Instead of worrying about SQL injection and XSS issues, you should be concerned about the bad actor who was able to paginate through all your customer records and their data.

Typical prevention mechanisms like Captchas and browser fingerprinting won’t work since APIs by design need to handle a very large number of API accesses even by a single customer. So where do you start? The first thing is to put yourself in the shoes of a hacker and then instrument your APIs to detect and block common attacks along with unknown unknowns for zero-day exploits. Some of these are on the OWASP Security API list, but not all.

Insecure pagination and resource limits

Most APIs provide access to resources that are lists of entities such as /users or /widgets. A client such as a browser would typically filter and paginate through this list to limit the number items returned to a client like so:

First Call: GET /items?skip=0&take=10 
Second Call: GET /items?skip=10&take=10

However, if that entity has any PII or other information, then a hacker could scrape that endpoint to get a dump of all entities in your database. This could be most dangerous if those entities accidently exposed PII or other sensitive information, but could also be dangerous in providing competitors or others with adoption and usage stats for your business or provide scammers with a way to get large email lists. See how Venmo data was scraped

A naive protection mechanism would be to check the take count and throw an error if greater than 100 or 1000. The problem with this is two-fold:

  1. For data APIs, legitimate customers may need to fetch and sync a large number of records such as via cron jobs. Artificially small pagination limits can force your API to be very chatty decreasing overall throughput. Max limits are to ensure memory and scalability requirements are met (and prevent certain DDoS attacks), not to guarantee security.
  2. This offers zero protection to a hacker that writes a simple script that sleeps a random delay between repeated accesses.
skip = 0
while True:    response ='' + skip),                      headers={'Authorization': 'Bearer' + ' ' + sys.argv[1]})    print("Fetched 10 items")    sleep(randint(100,1000))    skip += 10

How to secure against pagination attacks

To secure against pagination attacks, you should track how many items of a single resource are accessed within a certain time period for each user or API key rather than just at the request level. By tracking API resource access at the user level, you can block a user or API key once they hit a threshold such as “touched 1,000,000 items in a one hour period”. This is dependent on your API use case and can even be dependent on their subscription with you. Like a Captcha, this can slow down the speed that a hacker can exploit your API, like a Captcha if they have to create a new user account manually to create a new API key.

Insecure API key generation

Most APIs are protected by some sort of API key or JWT (JSON Web Token). This provides a natural way to track and protect your API as API security tools can detect abnormal API behavior and block access to an API key automatically. However, hackers will want to outsmart these mechanisms by generating and using a large pool of API keys from a large number of users just like a web hacker would use a large pool of IP addresses to circumvent DDoS protection.

How to secure against API key pools

The easiest way to secure against these types of attacks is by requiring a human to sign up for your service and generate API keys. Bot traffic can be prevented with things like Captcha and 2-Factor Authentication. Unless there is a legitimate business case, new users who sign up for your service should not have the ability to generate API keys programmatically. Instead, only trusted customers should have the ability to generate API keys programmatically. Go one step further and ensure any anomaly detection for abnormal behavior is done at the user and account level, not just for each API key.

Accidental key exposure

APIs are used in a way that increases the probability credentials are leaked:

  1. APIs are expected to be accessed over indefinite time periods, which increases the probability that a hacker obtains a valid API key that’s not expired. You save that API key in a server environment variable and forget about it. This is a drastic contrast to a user logging into an interactive website where the session expires after a short duration.
  2. The consumer of an API has direct access to the credentials such as when debugging via Postman or CURL. It only takes a single developer to accidently copy/pastes the CURL command containing the API key into a public forum like in GitHub Issues or Stack Overflow.
  3. API keys are usually bearer tokens without requiring any other identifying information. APIs cannot leverage things like one-time use tokens or 2-factor authentication.

If a key is exposed due to user error, one may think you as the API provider has any blame. However, security is all about reducing surface area and risk. Treat your customer data as if it’s your own and help them by adding guards that prevent accidental key exposure.

How to prevent accidental key exposure

The easiest way to prevent key exposure is by leveraging two tokens rather than one. A refresh token is stored as an environment variable and can only be used to generate short lived access tokens. Unlike the refresh token, these short lived tokens can access the resources, but are time limited such as in hours or days.

The customer will store the refresh token with other API keys. Then your SDK will generate access tokens on SDK init or when the last access token expires. If a CURL command gets pasted into a GitHub issue, then a hacker would need to use it within hours reducing the attack vector (unless it was the actual refresh token which is low probability)

Exposure to DDoS attacks

APIs open up entirely new business models where customers can access your API platform programmatically. However, this can make DDoS protection tricky. Most DDoS protection is designed to absorb and reject a large number of requests from bad actors during DDoS attacks but still need to let the good ones through. This requires fingerprinting the HTTP requests to check against what looks like bot traffic. This is much harder for API products as all traffic looks like bot traffic and is not coming from a browser where things like cookies are present.

Stopping DDoS attacks

The magical part about APIs is almost every access requires an API Key. If a request doesn’t have an API key, you can automatically reject it which is lightweight on your servers (Ensure authentication is short circuited very early before later middleware like request JSON parsing). So then how do you handle authenticated requests? The easiest is to leverage rate limit counters for each API key such as to handle X requests per minute and reject those above the threshold with a 429 HTTP response. There are a variety of algorithms to do this such as leaky bucket and fixed window counters.

Incorrect server security

APIs are no different than web servers when it comes to good server hygiene. Data can be leaked due to misconfigured SSL certificate or allowing non-HTTPS traffic. For modern applications, there is very little reason to accept non-HTTPS requests, but a customer could mistakenly issue a non HTTP request from their application or CURL exposing the API key. APIs do not have the protection of a browser so things like HSTS or redirect to HTTPS offer no protection.

How to ensure proper SSL

Test your SSL implementation over at Qualys SSL Test or similar tool. You should also block all non-HTTP requests which can be done within your load balancer. You should also remove any HTTP headers scrub any error messages that leak implementation details. If your API is used only by your own apps or can only be accessed server-side, then review Authoritative guide to Cross-Origin Resource Sharing for REST APIs

Incorrect caching headers

APIs provide access to dynamic data that’s scoped to each API key. Any caching implementation should have the ability to scope to an API key to prevent cross-pollution. Even if you don’t cache anything in your infrastructure, you could expose your customers to security holes. If a customer with a proxy server was using multiple API keys such as one for development and one for production, then they could see cross-pollinated data.

#api management #api security #api best practices #api providers #security analytics #api management policies #api access tokens #api access #api security risks #api access keys

Autumn  Blick

Autumn Blick


Public ASX100 APIs: The Essential List

We’ve conducted some initial research into the public APIs of the ASX100 because we regularly have conversations about what others are doing with their APIs and what best practices look like. Being able to point to good local examples and explain what is happening in Australia is a key part of this conversation.


The method used for this initial research was to obtain a list of the ASX100 (as of 18 September 2020). Then work through each company looking at the following:

  1. Whether the company had a public API: this was found by googling “[company name] API” and “[company name] API developer” and “[company name] developer portal”. Sometimes the company’s website was navigated or searched.
  2. Some data points about the API were noted, such as the URL of the portal/documentation and the method they used to publish the API (portal, documentation, web page).
  3. Observations were recorded that piqued the interest of the researchers (you will find these below).
  4. Other notes were made to support future research.
  5. You will find a summary of the data in the infographic below.


With regards to how the APIs are shared:

#api #api-development #api-analytics #apis #api-integration #api-testing #api-security #api-gateway