Skip to content

shuttleai/shuttleai-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Official Python Library for the ShuttleAI API

Build, Lint, Format pypi Downloads Downloads/Month Python Versions

The ShuttleAI Python library provides easy access to the ShuttleAI REST API for Python 3.9+ applications. It includes type definitions for all request parameters and response fields, offering both synchronous and asynchronous clients powered by httpx and aiohttp, respectively.

We prioritize performance optimizations across the library. Beyond using orjson for near-instant JSON processing, we implement various techniques to reduce overhead and enhance speed, ensuring efficient and swift API interactions. These optimizations include minimizing built-in library usage, leveraging reusable aiohttp client sessions, and incorporating several small adjustments to streamline operations.

Installation

pip install shuttleai

From Source

This client uses poetry as a dependency and virtual environment manager.

You can install poetry with

pip install poetry

poetry will set up a virtual environment and install dependencies with the following command:

poetry install

Getting Started

Synchronous Client

from shuttleai import ShuttleAI

shuttleai = ShuttleAI()

for chunk in shuttleai.chat.completions.create(
        messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
        stream=True
    ):
    print(chunk.choices[0].delta.content, end="", flush=True)

Asynchronous Client

import asyncio
from shuttleai import AsyncShuttleAI

async def main():
    shuttleai = AsyncShuttleAI()

    async for chunk in shuttleai.chat.completions.create(
        messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
        stream=True
    ):
        print(chunk.choices[0].delta.content, end="", flush=True)

asyncio.run(main())

Interactive Chatbot

Scroll down to the Interactive Chatbot section for more information.

Run examples

You can run the examples in the examples/ directory using poetry run or by entering the virtual environment using poetry shell.

Using poetry run

cd examples
poetry run python chat_no_streaming.py

Using poetry shell

poetry shell
cd examples

>> python chat_no_streaming.py

API Key Setup

To use the ShuttleAI API, you need to have an API key. You can get a FREE API key by signing up at shuttleai.app and heading to the key management page.

After you have an API key, you can set it as an environment variable:

Windows

setx SHUTTLEAI_API_KEY "<your_api_key>"

macOS/Linux

export SHUTTLEAI_API_KEY=<your_api_key>

Contribution

We welcome and appreciate contributions to the ShuttleAI API Python SDK. Please see the contribution guide for more information. Benefits may apply! 😄

Scripts

Formatting/Checks

  • poetry run ruff check shuttleai - Check for code formatting issues
  • poetry run black shuttleai --diff --color - Check for code formatting issues
  • poetry run black shuttleai - Format code
  • poetry run mypy shuttleai - Check for type errors

Tools

  • poetry run clean - Clean up the project directory
  • poetry run key - Display your default API key (if set by environment variable)
  • poetry run contributors - Display contributors

Interactive Chatbot

  • poetry run shuttleai - Run the interactive chatbot Example of Chatbot Example response of Chatbot

Important

We support auto TAB completion of commands and model names! Just press TAB! Example of TAB of Chatbot