Access Shuttle AI's API via an easy-to-use Python wrapper. Dashboard: https://shuttleai.app Discord: https://discord.gg/shuttleai
Project description
The Official Python Library for the ShuttleAI API
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-2-turbo",
messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
)
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-2-turbo",
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.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>"
[!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 ruffpoetry run black shuttleai --diff --color
- Check blackpoetry run black shuttleai
- Format codepoetry run mypy shuttleai
- Check for type errors
Tools
poetry run clean
- Clean up the project directorypoetry run key
- Display your default API key (if set by environment variable)poetry run contr
- Display contributors
ShuttleAI CLI
poetry run shuttleai
orshuttleai
- Run the ShuttleAI CLI.
[!Important] We support auto TAB completion of commands and model names! Just press
TAB
!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for shuttleai-4.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 450ee4d547d71794592e9d6f05e88f13874810d9e9ad7731c5b885c33f1eb15b |
|
MD5 | 1bbb5db1a31fea07c6e8dfad4ec7caf8 |
|
BLAKE2b-256 | 419f381dc8b9262d2a7abc0e9f5b6b6cdfa563271fefcdc7b590dcca89ea3c76 |