Skip to content

Getting Started

After you installed this package and set up your Google Credentials, the next step is to import the package into your code and start using its functions.

from botcity.plugins.googlesheets import BotGoogleSheetsPlugin

As a demonstration of the library, let's build a simple example together that will do something cool .

Step 1 of Example

To make the example we will...

# Instantiate the plugin
bot_sheets = BotGoogleSheetsPlugin(CLIENT_SECRET_PATH, 'SPREADSHEET_ID')

Step 2 of Example

# Adds some data
bot_sheets.add_row(['Name', 'Age'])
bot_sheets.add_rows(['Peter', '53'], ['Paulo', '35'])

# Sorts the columns by ascending age
bot_sheets.sort('B')

# Prints the resulting list
print(bot_sheets.as_list())

Complete code

Let's take a look into the complete code:

from botcity.plugins.googlesheets import BotGoogleSheetsPlugin

# Instantiate the plugin
bot_sheets = BotGoogleSheetsPlugin(CLIENT_SECRET_PATH, 'SPREADSHEET_ID')

# Adds some data
bot_sheets.add_row(['Name', 'Age'])
bot_sheets.add_rows(['Peter', '53'], ['Paulo', '35'])

# Sorts the columns by ascending age
bot_sheets.sort('B')

# Prints the resulting list
print(bot_sheets.as_list())

Pro Tip

This plugin allow you to use method chaining so the code above could be written as:

data = [['Name', 'Age'], ['Peter', '53'], ['Paulo', '35']]
sorted_data = BotGoogleSheetsPlugin(CLIENT_SECRET_PATH, 'SPREADSHEET_ID')
        .add_rows(rows)
        .sort('B')
        .as_list()

print(sorted_data)

Next Steps

Check our examples and experiment with the API. Let us know where it can be improved.

Have fun automating!

Back to top