Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.lytix.co/llms.txt

Use this file to discover all available pages before exploring further.

Prerequisite Please see here to get and set your API Key environment variable.

Install the lytix SDK

pip3 install lytix-py

(Reccomended) Set you API key via the environment variable

export LX_API_KEY=<your-api-key-here>

Set your API key in the code

from optimodel import LytixCreds

LytixCreds.setAPIKey('<your-api-key-here>')

Error Class

You can now just replace all your raise Exception calls with raise LError. For example:
from lytix_py import LError, LLogger

async def backgroundProcess():
    logger = LLogger("background-logger", {"userId": '124'})
    logger.info("Some process is starting")
    raise LError("An unexpected error")

async def main(): 
    await backgroundProcess()


if __name__ == "__main__":
    logger  = LLogger("main")
    logger.runInAsyncContext(main)
The error, along with the last 20 log lines will automatically get pushed to the Lytix platform here. See example event here: title

Error Increment

You can also send an error along with related logs without throwing an error by using the increment method.
from lytix_py.LError import LErrorIncrement, LLogger

async def backgroundProcess():
    logger = LLogger("background-logger", {"userId": '124'})
    logger.info("Some context on the user here")
    try:
        raise Exception("LIncrement error happened")
    except Exception as e:
        logger.error("LIncrement error happened")
        LErrorIncrement("Some error")
                        
async def main(): 
    logger = LLogger("main-logger")
    logger.info("Starting in our main LIncrement process")
    await backgroundProcess()


if __name__ == "__main__":
    logger  = LLogger("main")
    logger.runInAsyncContext(main)

Examples

To see all examples please check the Github repo here