Skip to content

About

Python3 SDK for the Truto API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

41 Commits

Folders and files

Repository files navigation

truto-python-sdk

truto-python-sdk is a Python SDK to interact with the Truto API, a powerful integration platform for connecting multiple SaaS applications. The SDK mirrors the Truto REST API endpoints, which are documented in the Truto Postman Collection.

Run in Postman

Requires

Python 3.12+

Installation

Install the package via pip:

pip install truto-python-sdk

Usage

import asyncio
from truto_python_sdk import TrutoApi

truto_api = TrutoApi(token="<your_api_token>")

async def main():
    # Fetch all installed integrations for the environment
    installed_integrations = truto_api.environment_integrations.list()
    async for integration in installed_integrations:
        print(integration)

    # Fetch integrated accounts for a tenant
    integrated_accounts = truto_api.integrated_accounts.list(tenant_id="acme-1")
    print(await integrated_accounts.to_array())

    # Make a request to the unified API
    unified_cursor = truto_api.unified_api.list(
        "accounting",
        "accounts",
        {
            "integrated_account_id": "766cc1ee-6637-4aa1-a73e-a0c89ccc867c",
            "created_at": "2023-05-01T00:00:00.000Z",
        },
    )
    async for account in unified_cursor:
        print(account)

    unified_resource = await truto_api.unified_api.get(
        "accounting",
        "accounts",
        "1",
        {"integrated_account_id": "766cc1ee-6637-4aa1-a73e-a0c89ccc867c"},
    )
    print(unified_resource)

asyncio.run(main())

List Calls and Pagination

The SDK uses async iterators for list calls. This allows you to iterate through resources without manually handling pagination.

cursor = truto_api.unified_api.list(
    "ticketing",
    "tickets",
    {"integrated_account_id": "c54bc595-486e-4bbb-8c17-20810fa4a86c"},
)
async for ticket in cursor:
    print(ticket)

You can also call to_array() to auto-paginate and collect all resources:

tickets = await truto_api.unified_api.list(
    "ticketing",
    "tickets",
    {"integrated_account_id": "c54bc595-486e-4bbb-8c17-20810fa4a86c"},
).to_array()

Or fetch one page at a time with next_page():

page = await truto_api.unified_api.list(
    "ticketing",
    "tickets",
    {"integrated_account_id": "c54bc595-486e-4bbb-8c17-20810fa4a86c"},
).next_page()

Errors

A 4xx or 5xx response raises TrutoApiError. It subclasses aiohttp.ClientResponseError, so .status, .message and .headers work as before, and it also carries the response body Truto sent:

from truto_python_sdk import TrutoApiError

try:
    await truto_api.integrated_accounts.get("missing-id")
except TrutoApiError as e:
    print(e.status)               # 404
    print(e.error)                # Truto's error message, if the body is JSON
    print(e.truto_error_insight)  # extra detail Truto attaches to some errors, or None
    print(e.data)                 # the full parsed JSON body, or None
    print(e.body)                 # the raw body as text

Full reference

Every resource and method, with examples, is documented at truto.one/docs/sdks/python: the Unified, Proxy and Custom APIs, MCP, integrated accounts, tenants, integrations, unified models and mappings, sync jobs, webhooks, workflows, datastores, analytics, and more.

Contributing

We welcome contributions to improve truto-python-sdk. Please submit issues or pull requests on the GitHub repository.

License

MIT

About

Python3 SDK for the Truto API

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages