Metadata-Version: 2.4
Name: t2g-sdk
Version: 1.0.0rc14
Summary: SDK for the T2G API
Project-URL: Homepage, https://github.com/pypa/sampleproject
Project-URL: Bug Tracker, https://github.com/pypa/sampleproject/issues
Author-email: Victor de La Salmonière <victor@lettria.com>
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Requires-Dist: aiohttp
Requires-Dist: certifi
Requires-Dist: neo4j
Requires-Dist: pydantic
Requires-Dist: pydantic-settings
Description-Content-Type: text/markdown

# Lettria's Text-to-Graph SDK 🚀

[![PyPI version](https://badge.fury.io/py/t2g-sdk.svg)](https://badge.fury.io/py/t2g-sdk)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Welcome to the official Python SDK for Lettria's Text-to-Graph (T2G) API! This SDK makes it easy to turn unstructured text into powerful knowledge graphs right from your Python applications. ✨

## 🌟 Features

- **Asynchronous Client**: High-performance, non-blocking API calls using `asyncio` and `aiohttp`.
- **Simple Interface**: Easy-to-use methods for file operations, ontology management, and graph building.
- **Data Validation**: Robust data modeling with `pydantic`.
- **Neo4j Integration**: Directly save your graph data to a Neo4j instance.
- **Flexible Configuration**: Configure via environment variables or directly in code.

## 📦 Installation

```bash
pip install t2g-sdk==1.0.0-rc.14
```

## 🚀 Quick Start

To use the SDK, you need an API key from Lettria. Get in touch with us at [hello@lettria.com](mailto:hello@lettria.com) to get started.

### Configuration

Create a `.env` file and add your credentials:

```env
LETTRIA_API_KEY="YOUR_LETTRIA_API_KEY"

# Optional Neo4j credentials
NEO4J_URI="bolt://localhost:7687"
NEO4J_USER="neo4j"
NEO4J_PASSWORD="password"
```

The `T2GClient` will automatically load these variables.

### Example: Build a Graph

This example shows how to build a graph from a text file.

```python
import asyncio
from t2g_sdk import T2GClient

async def main():
    async with T2GClient() as client:
        try:
            await client.build_graph(
                file_path="path/to/your/document.txt",
            )
            print("🎉 Graph built successfully!")
        except Exception as e:
            print(f"An error occurred: {e}")

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

## 📚 API Reference

### `client.build_graph`

```python
async def build_graph(
    file_path: str,
    ontology_path: Optional[str] = None,
    output_path: Optional[str] = None,
    save_to_neo4j: bool = False,
    refresh_graph: bool = False,
) -> Job:
```

Processes a file by uploading it, optionally with an ontology, running a job, and downloading the output.

| Parameter     | Type          | Description                                                                 | Default   |
|---------------|---------------|-----------------------------------------------------------------------------|-----------|
| `file_path`   | `str`         | The path to the file to process.                                            |           |
| `ontology_path` | `Optional[str]` | The path to the ontology file to use.                                       | `None`    |
| `output_path` | `Optional[str]` | The path to save the output to. If not provided, a default path will be used. | `None`    |
| `save_to_neo4j` | `bool`        | Whether to save the output to Neo4j.                                        | `False`   |
| `refresh_graph` | `bool`        | Whether to force a new job to be created (refresh the graph).               | `False`   |

## 📂 Examples

For more detailed examples, check out the [`examples/`](./examples/) directory. Each example has its own README with instructions.

### Simple Examples

- **[Build Graph](./examples/simple/build_graph/)**: Build a knowledge graph from a text file.
- **[File Operations](./examples/simple/file_operations/)**: Upload and manage files.
- **[Ontology Operations](./examples/simple/ontology_operations/)**: Upload and manage ontologies.
- **[Delete Operations](./examples/simple/delete_operations/)**: Delete files and ontologies.

### Advanced Example

- **[Simple Reporting](./examples/advanced/simple-reporting/)**: A complete workflow to index a PDF, build a graph, and generate a report.

## 🤝 Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

## 📧 Contact

For support or questions, please reach out at [hello@lettria.com](mailto:hello@lettria.com).

## 📄 License

This SDK is licensed under the MIT License.
