Client

Initialization

The main client for interacting with the T2G API.

The PerseusClient can be initialized in several ways depending on your use case.

When working in an asynchronous environment, the client should be used as an async context manager. This ensures proper initialization and cleanup of underlying resources.

import asyncio
from perseus_client import PerseusClient

async def main():
    async with PerseusClient() as client:
        await client.build_graph_async(
            file_path="assets/pizza.txt",
        )

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

For synchronous scripts and applications, the client can be used as a standard context manager. This is the safest synchronous option, as the client is automatically closed when exiting the with block.

from perseus_client.client import PerseusClient

with PerseusClient() as client:
    client.build_graph(
        file_path="assets/pizza.txt",
    )

You may also manage the client lifecycle manually. In this case, you must explicitly close the client once you are done.

In this case, you must explicitly close the client once you are done.

from perseus_client.client import PerseusClient

client = PerseusClient()
client.build_graph(
    file_path="assets/pizza.txt",
)
client.close()