SDK for the T2G API
Project description
Lettria's Text-to-Graph SDK 🚀
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
asyncioandaiohttp. - 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
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 to get started.
Configuration
Create a .env file and add your credentials:
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.
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
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/ directory. Each example has its own README with instructions.
Simple Examples
- Build Graph: Build a knowledge graph from a text file.
- File Operations: Upload and manage files.
- Ontology Operations: Upload and manage ontologies.
- Delete Operations: Delete files and ontologies.
Advanced Example
- 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.
📄 License
This SDK is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file t2g_sdk-1.0.0rc14.tar.gz.
File metadata
- Download URL: t2g_sdk-1.0.0rc14.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddc243e78d738a4549bc9b0c71313cd33a579ef11e7d438afe3f600a9b70f21e
|
|
| MD5 |
18aa4f2b73ccada6190eee01d32d9e95
|
|
| BLAKE2b-256 |
c1f7f61d38db31f4e4d8c27a54abff95e860a8ff494318651ba577704d0a1f7b
|
File details
Details for the file t2g_sdk-1.0.0rc14-py3-none-any.whl.
File metadata
- Download URL: t2g_sdk-1.0.0rc14-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cfcfd58f376c03ea3bc95c0f5591a627abcc14c9343c60086ac2b4e23af4dec
|
|
| MD5 |
b90b1c4afde22cbc832a815b43836fb0
|
|
| BLAKE2b-256 |
0bdc276ccaff2339b52bc84ff8d7d50db4d1c5a1b80a36ee5abe6fbbf21b1070
|