Python SDK for ExnestAI API service
Project description
ExnestAI Python SDK
This is the Python SDK for the ExnestAI API service. It provides both a simple wrapper and an advanced client for interacting with the ExnestAI API.
Installation
pip install exnestai
Quick Start
Simple Wrapper Usage
from exnestai.wrapper import ExnestAIWrapper
from exnestai.models import ExnestMessage
# Initialize the wrapper
exnest = ExnestAIWrapper("your-api-key-here")
# Simple chat
response = await exnest.chat("gpt-4o-mini", [
ExnestMessage(role="user", content="Hello, how are you?")
])
print(response)
# Quick response
result = await exnest.response("gemini-2.0-flash-exp", "What is Python?")
# Get models
models = await exnest.get_models()
Advanced Client Usage
from exnestai.client import ExnestAI
from exnestai.models import ExnestClientOptions, ExnestChatOptions, ExnestMessage
# Initialize the advanced client
exnest = ExnestAI(ExnestClientOptions(
api_key="your-api-key-here",
timeout=30,
retries=3,
debug=True
))
# Advanced chat with options
response = await exnest.chat(
"gemini-2.0-flash-exp",
[
ExnestMessage(role="system", content="You are a helpful assistant."),
ExnestMessage(role="user", content="Explain async/await in Python")
],
ExnestChatOptions(
temperature=0.7,
max_tokens=500,
timeout=15
)
)
print(response)
Features
- Simple Wrapper: Lightweight interface for basic AI interactions
- Advanced Client: Full configuration options with error handling and retry logic
- Streaming Responses: Support for real-time streaming of AI responses
- Model Management: Access to all available models and model information
- Error Handling: Comprehensive error handling with automatic retries
- Async Support: Fully asynchronous implementation for better performance
API Reference
ExnestMessage
class ExnestMessage:
role: str # "system", "user", or "assistant"
content: str
ExnestResponse
class ExnestResponse:
success: bool
status_code: int
message: str
data: Optional[ExnestResponseData]
error: Optional[Dict[str, Any]]
meta: Optional[ExnestMeta]
Authentication
The API supports Bearer token authentication:
# Using the Authorization header (recommended)
exnest = ExnestAI(ExnestClientOptions(
api_key="your-api-key-here"
))
Configuration Options
ExnestClientOptions
class ExnestClientOptions:
api_key: str # Required: Your ExnestAI API key
base_url: str # Optional: API base URL (default: https://api.exnest.app/v1)
timeout: int # Optional: Request timeout in seconds (default: 30)
retries: int # Optional: Number of retries (default: 3)
retry_delay: int # Optional: Delay between retries in seconds (default: 1)
debug: bool # Optional: Enable debug logging (default: False)
ExnestChatOptions
class ExnestChatOptions:
temperature: Optional[float] # Optional: Model temperature (0-2)
max_tokens: Optional[int] # Optional: Maximum tokens to generate
timeout: Optional[int] # Optional: Request-specific timeout
openai_compatible: Optional[bool] # Optional: Return OpenAI-compatible format
stream: Optional[bool] # Optional: Enable streaming response
Streaming Responses
The SDK supports streaming responses for real-time output:
# Using the advanced client
async for chunk in exnest.stream(
"gpt-4o-mini",
[ExnestMessage(role="user", content="Tell me a story")],
ExnestChatOptions(max_tokens=300)
):
if chunk.choices and len(chunk.choices) > 0:
delta = chunk.choices[0].get("delta", {})
content = delta.get("content")
if content:
print(content, end="", flush=True)
Error Handling
The advanced client provides comprehensive error handling with automatic retries:
try:
response = await exnest.chat(model, messages)
if not response.success:
print('API Error:', response.error)
except Exception as error:
print('Network Error:', error)
Examples
See examples.py for comprehensive usage examples including:
- Simple wrapper usage
- Advanced client configuration
- Streaming responses
- Error handling patterns
- Configuration updates
- Model operations
- Controller integration
Requirements
- Python 3.8+
- httpx 0.23.0+
Development
Setup
# Clone the repository
git clone https://github.com/fazza-abiyyu/sdk-exnestai-py.git
cd sdk-exnestai-py
# Install dependencies
pip install -r requirements.txt
# Install development dependencies
pip install pytest pytest-asyncio
Testing
# Run all tests
python -m pytest tests/ -v
Git Workflow
See GIT_WORKFLOW.md for detailed information about our Git workflow.
License
MIT License
Contributing
- Fork it
- Create your feature branch (
git checkout -b feature/your-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin feature/your-feature) - Create a new Pull Request
Changelog
See CHANGELOG.md for detailed information about changes in each release.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exnest_ai-1.0.3.tar.gz.
File metadata
- Download URL: exnest_ai-1.0.3.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aebb34a5e5e9004fd98adb40eb1061a818e909fe4eb522a26b757f4b00a1e58
|
|
| MD5 |
73d4340ba232cd9f0840a98f802837be
|
|
| BLAKE2b-256 |
459a156a3d8b15fcf550a15e11fe80b1755d79bdde13327ef8b89837acdc10ee
|
File details
Details for the file exnest_ai-1.0.3-py3-none-any.whl.
File metadata
- Download URL: exnest_ai-1.0.3-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
857d77b876c9daebe51cc5f9d06a84520ba0822ac8316910c659fa7b7cde0507
|
|
| MD5 |
ad2deb63402ef3e9fbefbae3e6a8877a
|
|
| BLAKE2b-256 |
e0a46e985824fb79a01f7e20dcebe6cdd74e8b0f79e07b038a5d3c4f1eb72357
|