Open Source SDK

Check out the open-source Github Repo

Introduction

In addition to the Python SDK documentation, all Guides showcase code examples in Python.

Installation

To install the Python client, run the following command:

pip install literalai

You can use either the synchronous or asynchronous Literal AI Python client.

All APIs can be used both sync or async, except for functions on Dataset, which are always sync. All examples in the documentation are, for simplicity, using the synchronous client.

If you want to use the async functions, make sure to await the functions.

The Python client is not compatible with gunicorn’s --preload flag.

To instantiate the synchronous client:

import os
from literalai import LiteralClient

literalai_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY")) 

or, async:

import os
from literalai import AsyncLiteralClient

async_literalai_client = AsyncLiteralClient(api_key=os.getenv("LITERAL_API_KEY")) 

Additionally, you can pass the optional batch_size argument to batch multiple events - handled simultaneously by Literal. Events are batched up to batch_size. Defaults to 5.

Disable Logging

When instantiating the client, you have the option to disable logging. This can be useful when you want to disable the logs without changing the code.

import os
from literalai import LiteralClient

literalai_client = LiteralClient(api_key=os.getenv("LITERAL_API_KEY"), disabled=True) # Disable decorators