Skip to main content

SDK for the T2G API

Project description

Lettria's Text-to-Graph SDK 🚀

PyPI version License: MIT

Welcome to the official Python SDK for Lettria's Text-to-Graph (T2G) API! This SDK provides a convenient way to interact with the T2G API, allowing you to unlock the power of knowledge graphs from your text data directly within your Python applications.

🌟 Overview

Lettria's Text-to-Graph (T2G) technology transforms unstructured text into structured knowledge graphs. This SDK is designed to simplify the process of sending your data to the T2G API and retrieving the results, whether you are indexing a single document, a collection of files, or building complex graph system.

This SDK is built with developers in mind, providing a clean, asynchronous client to handle API requests efficiently.

✨ Features

  • Asynchronous Client: Built with asyncio and aiohttp for high-performance, non-blocking API calls.
  • Simple Interface: Easy-to-use methods for indexing files and managing jobs.
  • Data Validation: Leverages pydantic for robust and reliable data modeling.
  • Neo4j Integration: Directly save your graph data to a Neo4j instance.
  • Flexible Configuration: Configure the SDK via environment variables or directly in your code.
  • Built-in Error Handling: Gracefully handles API errors with custom exceptions.

📦 Installation

pip install t2g-sdk==1.0.0-rc.12

🚀 Getting Started

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.

Quick Example: Building a graph

This example demonstrates how to build a graph from 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():
    async with T2GClient() as client:
        try:
            await client.build_graph(
                file_path="path/to/your/document.txt",
                ontology_path="path/to/your/ontology.ttl",
                output_path="path/to/your/output",
                save_to_neo4j=True,
            )
            print("🎉 Graph builded successfully")
        except Exception as e:
            print(f"An unexpected error occurred: {e}")


if __name__ == "__main__":
    asyncio.run(main())

📚 API Reference

The main entry point of the SDK is the T2GClient class.

t2g_sdk.client.T2GClient

The asynchronous client for interacting with the T2G API.

Methods:

  • async def build_graph(file_path: str, ontology_path: str = None, output_path: str = None, save_to_neo4j: bool = False) -> Job: Build a knowledge graph from a file by uploading it, running a job, and downloading the output.
    • file_path: Path to the file to process.
    • ontology_path (optional): Path to an ontology file (e.g., .ttl).
    • output_path (optional): The path to save the output to. If not provided, a default path will be used.
    • save_to_neo4j (optional): If True, saves the result to your configured Neo4j instance.

⚙️ Configuration Details

The SDK uses pydantic-settings for configuration management. You can configure the client by passing arguments to its constructor, or by setting environment variables.

Argument Environment Variable Description
api_key LETTRIA_API_KEY Required. Your Lettria API key.
neo4j_uri NEO4J_URI (Optional) The URI for your Neo4j instance.
neo4j_user NEO4J_USER (Optional) The username for your Neo4j instance.
neo4j_password NEO4J_PASSWORD (Optional) The password for your Neo4j instance.

Note: The Neo4j configuration options (neo4j_uri, neo4j_user, neo4j_password) are only required if you set save_to_neo4j=True when calling build_graph.

📂 Examples

You can find more examples in the examples/ directory. Each example includes a README.md with instructions on how to run it.

  • build_graph/: A simple demonstration of how to build a knowledge graph from a file.
  • simple-reporting/: An advanced example of how to generate a report from the produced knowledge graph data.
  • upload_ontology/: A basic example of how to upload an ontology file.

🤝 Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you have any feedback or suggestions.

📧 Contact

For any feedback, questions, or support, please reach out to us at hello@lettria.com.

📄 License

This SDK is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

t2g_sdk-1.0.0rc12.tar.gz (4.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

t2g_sdk-1.0.0rc12-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file t2g_sdk-1.0.0rc12.tar.gz.

File metadata

  • Download URL: t2g_sdk-1.0.0rc12.tar.gz
  • Upload date:
  • Size: 4.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for t2g_sdk-1.0.0rc12.tar.gz
Algorithm Hash digest
SHA256 77a22dfdb8fe7d4762dd15f9f3debcd85701e90515fef3642f93e4aeb3ff6b95
MD5 30210da3ae2f6588f631215be30cbac7
BLAKE2b-256 0a2c344f175751a60fa440d3e906586fae927f7aee78f865faad61c9a1fd8ec6

See more details on using hashes here.

File details

Details for the file t2g_sdk-1.0.0rc12-py3-none-any.whl.

File metadata

  • Download URL: t2g_sdk-1.0.0rc12-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for t2g_sdk-1.0.0rc12-py3-none-any.whl
Algorithm Hash digest
SHA256 f0cd77aa79b015a697c40ea7505af0555ff907ea6729b1d2b1c542ae9fd59a8b
MD5 bd835279f420d3ecd95a18cbcef6c95c
BLAKE2b-256 da53caf68d7f7608063c4e92bba519d7e8a7845f72d5cc34ceb860cf1cb8c628

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page