Getting Started

This guide will help you get up and running with the T2G SDK.

Installation

You can install the SDK using pip:

pip install t2g-sdk

Quick Start

To start using the SDK, you will need an API key from Lettria.

To create an API key, please visit our preview instance here.

Access to the API is managed by whitelisting. If you require access, please contact us at hello@lettria.com to request whitelisting.

Configuration

The SDK can be configured by setting the following environment variable:

  • LETTRIA_API_KEY: Your Lettria API key.

Alternatively, you can pass this value directly to the T2GClient constructor. For more details, see the Configuration page.

Example: Indexing a File

This example demonstrates how to index a local text file and save the resulting graph to Neo4j.

import asyncio
from t2g_sdk.client import T2GClient
from t2g_sdk.exceptions import T2GException
from t2g_sdk.models import Job

async def main(): # It is recommended to use the client as a context manager
async with T2GClient() as client:
try: # Index a file and save the result to Neo4j
job: Job = await client.index_file(
file_path="path/to/your/document.txt", # You can also specify an ontology file # ontology_path="path/to/your/ontology.ttl",
save_to_neo4j=True,
)
print("🎉 Job completed successfully!")
print("Job details:", job)
except T2GException as e:
print(f"An API error occurred: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")

if **name** == "**main**":
asyncio.run(main())