Python

Install the Python SDK and start building AI applications with semantic memory.

Build AI applications with Python using the Graphlit SDK.

New to Graphlit? Complete the Quickstart tutorial for a hands-on introduction.


Installation

Install the Graphlit client with pip:

pip install graphlit-client

Requirements:


Quick Start

import asyncio
import os
from graphlit import Graphlit
from graphlit_api import *

async def main():
    # Reads from environment variables automatically
    graphlit = Graphlit()
    
    # Ingest content
    response = await graphlit.client.ingest_text(
        name="Product Requirements",
        text="Our AI agent needs persistent memory across sessions..."
    )
    
    print(f"✅ Memory created: {response.ingest_text.id}")

asyncio.run(main())

Configuration

Environment Variables (Production)

Create a .env file (never commit this):

GRAPHLIT_ORGANIZATION_ID=your_actual_org_id
GRAPHLIT_ENVIRONMENT_ID=your_actual_env_id
GRAPHLIT_JWT_SECRET=your_actual_jwt_secret

Load it with python-dotenv:

import asyncio
from dotenv import load_dotenv
from graphlit import Graphlit

load_dotenv()  # Loads .env file

async def main():
    graphlit = Graphlit()  # Reads from environment
    # Your code here
    
asyncio.run(main())

Install python-dotenv:

pip install python-dotenv

Alternative: Explicit Configuration

Only use if you need to override environment variables:

from graphlit import Graphlit
import os

graphlit = Graphlit(
    organization_id=os.environ['GRAPHLIT_ORGANIZATION_ID'],
    environment_id=os.environ['GRAPHLIT_ENVIRONMENT_ID'],
    jwt_secret=os.environ['GRAPHLIT_JWT_SECRET']
)

Common Patterns

Ingest Content

# From URL
response = await graphlit.client.ingest_uri(
    uri="https://example.com/document.pdf"
)

# From text
response = await graphlit.client.ingest_text(
    name="Meeting Notes",
    text="Discussion about Q4 planning..."
)

Search Memory

response = await graphlit.client.query_contents(
    filter=ContentFilter(
        search="quarterly planning"
    )
)

for content in response.contents.results:
    print(f"📄 {content.name}")

Chat with Context

# Create conversation
conversation = await graphlit.client.create_conversation(
    conversation=ConversationInput(
        name="AI Assistant"
    )
)

# Ask questions
response = await graphlit.client.prompt_conversation(
    prompt="What did we discuss about Q4 planning?",
    id=conversation.create_conversation.id
)

print(response.prompt_conversation.message.message)

Next Steps

Quickstarts:

Examples:

Resources:

Last updated

Was this helpful?