Skip to main content

Access Shuttle AI's API via an easy-to-use Python wrapper. Dashboard: https://shuttleai.com Discord: https://discord.gg/shuttleai

Project description

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

We recommend using --upgrade or -U to ensure you have the latest version of the library.

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

Below is a non-streamed sync and async example for the ShuttleAI API. You can find more examples in the examples/ directory.

Synchronous Client

from shuttleai import ShuttleAI

shuttleai = ShuttleAI()

response = shuttleai.chat.completions.create(
    model="shuttle-3",
    messages=[{"role": "user", "content": "What day is today?"}],
    internet=False
)

print(chunk.choices[0].message.content)

Asynchronous Client

import asyncio
from shuttleai import AsyncShuttleAI

async def main():
    shuttleai = AsyncShuttleAI()

    response = await shuttleai.chat.completions.create(
        model="shuttle-3",
        messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
    )

    print(response.choices[0].message.content)

asyncio.run(main())

ShuttleAI CLI

Scroll down to the Scripts 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.com 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>"

[!Note] This will only work in the current terminal session. To set it permanently, you can use the setx command with the /m flag.

setx SHUTTLEAI_API_KEY "<your_api_key>" /m

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! :smile:

Scripts

Formatting/Checks

  • poetry run ruff check shuttleai - Check ruff
  • poetry run black shuttleai --diff --color - Check black
  • 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 contr - Display contributors

ShuttleAI CLI

  • poetry run shuttleai or shuttleai - Run the ShuttleAI CLI. 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shuttleai-4.7.3.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

shuttleai-4.7.3-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file shuttleai-4.7.3.tar.gz.

File metadata

  • Download URL: shuttleai-4.7.3.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11

File hashes

Hashes for shuttleai-4.7.3.tar.gz
Algorithm Hash digest
SHA256 50992d21bcb0b599379a4340afad99b7f220a41ec0787f6c8efb0961ed65d013
MD5 4dc42c3b5e29baa1d6d27522ddc37333
BLAKE2b-256 e2e739ab475fa95640e80c942185f412ba4e430eac2e5e00d64a4878c41e6196

See more details on using hashes here.

File details

Details for the file shuttleai-4.7.3-py3-none-any.whl.

File metadata

  • Download URL: shuttleai-4.7.3-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Windows/11

File hashes

Hashes for shuttleai-4.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ace13cbb95df9c94691d6444d87527894064ce9024f72c7958019bcc4126b0b7
MD5 c8a0a2c466630e355c7b9f8deb5174b4
BLAKE2b-256 8bf0e258844bb2fc25e7eb2a12b133c00256ca04bc40ea3a11624b5fef1253a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page