Skip to main content

Indent Python Quickstart

Learn how to submit your first approval request using the Indent Python SDK.

Prerequisites

1. Install

Start by installing the Indent Python SDK:

pip install approvals

# or for direct API usage
pip install indentapi

2. Get your API Key

First, you'll need an Indent space and API token which you can find here: indent.com/api-keys

Current User
Sign in to get API key
  • Can take actions on your behalf
  • Appears in audit log as you
Indent Space
Access Token
Note: this token is short lived and will expire soon
.env
INDENT_SPACE=
INDENT_API_TOKEN=************************************************************************************

The INDENT_SPACE is the Indent account you want to use for requests and an INDENT_API_TOKEN which is used for authentication. There are two kinds of API tokens: short-lived user access tokens and long-lived service account tokens. Read more about API authentication.

3. Add await approval

Next, let's take a simple but sensitive workflow like user password reset. This workflow will be used to request approval for a user to reset their password.

reset_password.py
import os
from approvals import approval

async def reset_password(userId, reason):
await approval({
"reason": reason,
"resources": [
{
"kind": "action",
"id": f"reset-password:{userId}"
"displayName": f"Reset Password (user:{userId})"
},
],
})

# by default, wait up to 10 seconds for approval
# 95% of approvals take less than 10 seconds

# -> do something to reset the user's password
print f"done: password reset user:{userId}"

reset_password(os.getenv('USER'), os.getenv('REASON'))

Configure the following environment variables:

.env
INDENT_SPACE=acmecorp
INDENT_API_TOKEN=s38...65e # Copy from indent.com/api-keys

3. Try it for yourself

Once you run the script with python reset_password.py and the environment variables for user ID and reason, you'll see the following output:

$ USER=123 REASON="to recover account" python reset_password.py

⏵ Requested approval #acmecorp/aec1b116-42b3-11ee-824e-42010aac000d
↳ Waiting for approval... (2s elapsed)
↳ Waiting for approval... (4s elapsed)
↳ Waiting for approval... (8s elapsed)
✅ Granted

done: password reset user:123

Remember that your API key is a secret!

Do not share it with others or expose it in any client-side code (browsers, native apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service

4. Use the full Indent API

Install indentapi for access to the full Indent API to list resources, create petitions, and more.

pip install indentapi

Here's an example of how to use the Python bindings to list resources and create a petition:

request-prod.py
import os
from indentapi import IndentAPI

indent = IndentAPI(
space_name=os.getenv('INDENT_SPACE'), # default
api_token=os.getenv('INDENT_API_TOKEN'), # from indent.com/api-keys
)

resources = indent.resource.list(view='requestable')

pet = indent.petition.create(
reason='to debug production',
resources=[r for r in resources if r['displayName'] == 'Production'],
)

print(f'Requested: indent.com/access/{pet["spaceName"]}/{pet["name"]}')
$ python request-prod.py

Requested: indent.com/access/example/aec1b116-42b3-11ee-824e-42010aac000d