Python SDK

Install Guru's Python SDK, authenticate, and read card content in a few lines of code.

The Guru SDK is a Python module that wraps the Guru API. Tasks like inviting users to your team and assigning their groups take just a few lines of code. The SDK lives on GitHub at guruhq/guru-py-sdk.

Install the SDK

In a terminal, run:

pip install git+https://github.com/guruhq/guru-py-sdk.git

The SDK is hosted on GitHub, but you don't need a GitHub account to install it.

Generate an API token

You need an API token to use the SDK. See the Help Center for how to generate one.

Use the SDK

The SDK provides its functionality through the Guru class in the guru module. An instance of the Guru class wraps all of your API calls: when creating the object, you give it your username and API token, and it uses them for every call it makes.

import guru
g = guru.Guru("[email protected]", "your-api-token")

You can pass your username and API token as parameters, or put them in the GURU_USER and GURU_TOKEN environment variables. Environment variables are handy for a few reasons:

  1. If you generate a new API token, you only have to update it in one place.
  2. If you share your scripts or check code into GitHub, your token isn't in the code.
  3. When you start a new script, guru.Guru() with no arguments just works.

Here's how to use the Guru object to get all cards in a particular collection:

import guru
g = guru.Guru()
cards = g.find_cards(collection="HR")
print(f"There are {len(cards)} cards in the HR collection.")

This handles pagination for you and returns every card in the HR collection.

Read card content

Suppose you want to scan all HR cards and see which Dropbox files they link to:

import guru
g = guru.Guru()

for card in g.find_cards(collection="HR"):
  for link in card.doc.select("a[href*=dropbox.com]"):
    print(card.collection.name, card.title, card.url, link.attrs.get("href"))
  • find_cards returns a list of Card objects.
  • Card content is stored as HTML, and the Card object parses it with BeautifulSoup, so card.doc gives you a parsed document to work with.
  • card.doc.select() takes a CSS selector to find specific elements in the card. Here it finds links to any dropbox.com URL.
  • Other card properties are available directly, like card.title and card.collection.name.

To load content into Guru with the SDK, see Using the SDK for Syncs or Imports. To push cards out to another system, see Exporting Cards to an External System.