Installation

This guide will walk you through installing Sagely and setting up all required dependencies.

Prerequisites

  • Python 3.8 or higher

  • pip (Python package installer)

  • OpenAI API key

Installing Sagely

Install Sagely using pip:

pip install sagely

Or install from the latest development version:

pip install git+https://github.com/superpandas-ai/sagely.git

For development installation with all dependencies:

git clone https://github.com/superpandas-ai/sagely.git
cd sagely
pip install -e ".[dev]"

API Key Setup

Sagely requires an OpenAI API key to function. You can set it up in several ways:

Environment Variable (Recommended):

export OPENAI_API_KEY='your-api-key-here'

In your shell profile (bash/zsh):

Add to your ~/.bashrc or ~/.zshrc:

echo 'export OPENAI_API_KEY="your-api-key-here"' >> ~/.bashrc
source ~/.bashrc

In Python (temporary):

import os
os.environ['OPENAI_API_KEY'] = 'your-api-key-here'

Using a .env file:

Create a .env file in your project directory:

OPENAI_API_KEY=your-api-key-here

Then load it in your Python code:

from dotenv import load_dotenv
load_dotenv()

Optional Dependencies

Tavily API Key (for enhanced web search):

If you want to use Tavily as your web search provider:

export TAVILY_API_KEY='your-tavily-api-key'

LangSmith API Key (for tracing):

For debugging and monitoring with LangSmith:

export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_API_KEY='your-langsmith-api-key'
export LANGCHAIN_PROJECT='your-project-name'

Verifying Installation

To verify that Sagely is installed correctly:

import sagely
print(f"Sagely version: {sagely.__version__}")

You should see the version number printed without any errors.

Testing Basic Functionality

Test that everything is working:

import sagely
import json

# This should work and print an answer
json.sage.ask("What is the difference between json.dumps and json.dump?")

If you see a helpful response, your installation is working correctly!

Troubleshooting

Import Error: No module named ‘sagely’

Make sure you installed Sagely in the correct Python environment:

python -c "import sagely; print('Sagely is installed')"

OpenAI API Key Error

Verify your API key is set correctly:

import os
print(f"API Key set: {'OPENAI_API_KEY' in os.environ}")
if 'OPENAI_API_KEY' in os.environ:
    print(f"Key starts with: {os.environ['OPENAI_API_KEY'][:10]}...")

Permission Errors

If you encounter permission errors during installation, try:

pip install --user sagely

Or use a virtual environment:

python -m venv sagely_env
source sagely_env/bin/activate  # On Windows: sagely_env\Scripts\activate
pip install sagely

Jupyter Integration Issues

If IPython magic commands don’t work:

%load_ext sagely
%sagely json what is json?

Make sure you have IPython installed:

pip install ipython

Next Steps

Now that you have Sagely installed, check out: