Python SDK for EnkaliPrime Chat API - RAG-enabled AI conversations
Project description
๐ EnkaliPrime Python SDK
The official Python client for EnkaliPrime Chat API
Build intelligent, RAG-enabled conversational AI experiences in Python
Installation โข Quick Start โข Examples โข API Reference โข Contributing
โจ Features
๐ค AI-Powered Chat
|
โก Modern Python
|
๐ Real-time Streaming
|
๐ Framework Ready
|
๐๏ธ Architecture
flowchart TB
subgraph Client["๐ Python Application"]
App[Your App]
SDK[EnkaliPrime SDK]
App --> SDK
end
subgraph EnkaliBridge["โ๏ธ EnkaliBridge Gateway"]
Resolve["/resolve"]
Chat["/chat"]
end
subgraph Backend["๐ง EnkaliPrime Backend"]
Auth[Authentication]
RAG[RAG Engine]
KB[(Knowledge Base)]
AI[AI Model]
end
SDK -->|"1. Resolve API Key"| Resolve
Resolve -->|"2. Return Connection"| SDK
SDK -->|"3. Send Message"| Chat
Chat --> Auth
Auth --> RAG
RAG --> KB
RAG --> AI
AI -->|"4. Stream Response"| SDK
SDK -->|"5. Return to App"| App
style Client fill:#1e293b,stroke:#3b82f6,color:#fff
style EnkaliBridge fill:#0f172a,stroke:#8b5cf6,color:#fff
style Backend fill:#0f172a,stroke:#22c55e,color:#fff
๐ฆ Installation
From PyPI (Recommended)
pip install enkaliprime
From Source
pip install git+https://github.com/enkaliprime/python-sdk.git
With Development Dependencies
pip install enkaliprime[dev]
๐ Quick Start
1๏ธโฃ Get Your API Key
- Log in to EnkaliPrime Dashboard
- Navigate to SDK Hub โ Create Connection
- Copy your
unified_api_key(starts withek_bridge_)
2๏ธโฃ Initialize the Client
from enkaliprime import EnkaliPrimeClient
client = EnkaliPrimeClient({
"unified_api_key": "ek_bridge_your_key_here",
"base_url": "https://sdk.enkaliprime.com"
})
3๏ธโฃ Start Chatting
# Create a session
session = client.create_session(agent_name="AI Assistant")
# Send a message
response = client.send_message(
message="Hello! What can you help me with?",
session_id=session.id
)
print(response)
# "Hi there! I can help you with..."
๐ Data Flow
sequenceDiagram
participant App as ๐ Your App
participant SDK as ๐ฆ SDK
participant Bridge as โ๏ธ EnkaliBridge
participant AI as ๐ค AI Engine
App->>SDK: EnkaliPrimeClient(config)
Note over SDK: Initialize client
App->>SDK: create_session()
SDK-->>App: ChatSession
App->>SDK: send_message("Hello!")
SDK->>Bridge: POST /resolve (first call)
Bridge-->>SDK: Connection details
SDK->>Bridge: POST /chat
Bridge->>AI: Process with RAG
AI-->>Bridge: Generate response
alt Streaming Enabled
Bridge-->>SDK: Stream chunks
SDK-->>App: on_chunk callback
else Standard Response
Bridge-->>SDK: Full response
end
SDK-->>App: "Hi! How can I help?"
App->>SDK: end_session()
SDK-->>App: Session closed
๐ Examples
Basic Chat
from enkaliprime import EnkaliPrimeClient
# Initialize
client = EnkaliPrimeClient({
"unified_api_key": "ek_bridge_xxx",
"base_url": "https://sdk.enkaliprime.com"
})
# Chat
session = client.create_session()
response = client.send_message("What's the weather?", session.id)
print(response)
# Cleanup
client.close()
Async Usage
import asyncio
from enkaliprime import EnkaliPrimeClient
async def chat():
async with EnkaliPrimeClient({
"unified_api_key": "ek_bridge_xxx",
"base_url": "https://sdk.enkaliprime.com"
}) as client:
session = client.create_session()
response = await client.send_message_async(
message="Tell me a joke",
session_id=session.id
)
print(response)
asyncio.run(chat())
Streaming Responses
from enkaliprime import EnkaliPrimeClient
client = EnkaliPrimeClient({...})
session = client.create_session()
# Stream with callback
def on_chunk(text):
print(text, end="", flush=True)
client.send_message(
message="Write a poem about coding",
session_id=session.id,
stream=True,
on_chunk=on_chunk
)
Context Manager
from enkaliprime import EnkaliPrimeClient
# Automatic cleanup
with EnkaliPrimeClient({...}) as client:
session = client.create_session()
response = client.send_message("Hello!", session.id)
# Client automatically closed
๐ Framework Integrations
FastAPI
from fastapi import FastAPI
from pydantic import BaseModel
from enkaliprime import EnkaliPrimeClient
app = FastAPI()
client = EnkaliPrimeClient({...})
class ChatRequest(BaseModel):
message: str
session_id: str
@app.post("/chat")
async def chat(request: ChatRequest):
response = await client.send_message_async(
message=request.message,
session_id=request.session_id
)
return {"response": response}
Flask
from flask import Flask, request, jsonify
from enkaliprime import EnkaliPrimeClient
app = Flask(__name__)
client = EnkaliPrimeClient({...})
@app.route("/chat", methods=["POST"])
def chat():
data = request.json
response = client.send_message(
message=data["message"],
session_id=data["session_id"]
)
return jsonify({"response": response})
Django
# views.py
from django.http import JsonResponse
from enkaliprime import EnkaliPrimeClient
import json
client = EnkaliPrimeClient({...})
def chat_view(request):
data = json.loads(request.body)
response = client.send_message(
message=data["message"],
session_id=data["session_id"]
)
return JsonResponse({"response": response})
๐ API Reference
EnkaliPrimeClient
The main client class for interacting with EnkaliPrime.
client = EnkaliPrimeClient(config)
Config Options
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
unified_api_key |
str |
โ | โ | Your EnkaliBridge API key |
base_url |
str |
โ | โ | EnkaliBridge gateway URL |
user_id |
str |
โ | None |
User identifier for tracking |
timeout |
int |
โ | 30 |
Request timeout (seconds) |
max_retries |
int |
โ | 3 |
Maximum retry attempts |
Methods
| Method | Description | Returns |
|---|---|---|
send_message(message, session_id, ...) |
Send a message synchronously | str |
send_message_async(message, session_id, ...) |
Send a message asynchronously | str |
create_session(agent_name, ...) |
Create a new chat session | ChatSession |
end_session() |
End the current session | ChatSession | None |
get_connection() |
Get resolved connection info | ResolvedConnection |
clear_history() |
Clear conversation history | None |
get_history() |
Get conversation history | list[dict] |
close() |
Close HTTP clients | None |
Data Models
classDiagram
class ChatMessage {
+str id
+str text
+bool is_user
+str timestamp
+MessageStatus status
+str session_id
+to_dict() dict
}
class ChatSession {
+str id
+str agent_name
+bool is_active
+str start_time
+str? end_time
+to_dict() dict
}
class ResolvedConnection {
+str connection_id
+str widget_id
+str widget_name
+str base_url
+bool is_active
}
class ChatApiConfig {
+str unified_api_key
+str base_url
+str? user_id
+int timeout
+validate() None
}
Exceptions
| Exception | Description | HTTP Code |
|---|---|---|
EnkaliPrimeError |
Base exception for all SDK errors | โ |
AuthenticationError |
Invalid or expired API key | 401 |
ConnectionError |
Network connectivity issues | โ |
APIError |
API returned an error response | varies |
StreamingError |
Error during streaming | โ |
ValidationError |
Invalid request parameters | 400 |
from enkaliprime import (
EnkaliPrimeClient,
AuthenticationError,
ConnectionError,
APIError
)
try:
response = client.send_message(...)
except AuthenticationError:
print("Check your API key!")
except ConnectionError:
print("Network issue, retrying...")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")
๐งช Testing
Run the Test Suite
# Install dev dependencies
pip install enkaliprime[dev]
# Run tests
pytest
# With coverage
pytest --cov=enkaliprime
Quick Verification
from enkaliprime import EnkaliPrimeClient, __version__
print(f"SDK Version: {__version__}")
client = EnkaliPrimeClient({
"unified_api_key": "ek_bridge_xxx",
"base_url": "https://sdk.enkaliprime.com"
})
# Test connection
connection = client.get_connection()
print(f"Connected to: {connection.widget_name}")
๐ Project Structure
enkaliprime/
โโโ __init__.py # Package exports
โโโ client.py # EnkaliPrimeClient class
โโโ models.py # Data models (ChatMessage, etc.)
โโโ exceptions.py # Custom exceptions
โโโ py.typed # PEP 561 type marker
examples/
โโโ basic_usage.py # Simple usage example
โโโ streaming_example.py
โโโ async_example.py
โโโ interactive_chat.py
โโโ fastapi_integration.py
tests/
โโโ test_client.py
โโโ test_models.py
๐ก๏ธ Security
- โ API keys are never logged
- โ HTTPS-only communication
- โ Secure credential handling
- โ No sensitive data in errors
Best Practices
import os
from dotenv import load_dotenv
load_dotenv()
# โ
Good: Use environment variables
client = EnkaliPrimeClient({
"unified_api_key": os.getenv("ENKALI_API_KEY"),
"base_url": os.getenv("ENKALI_BASE_URL")
})
# โ Bad: Hardcoded credentials
client = EnkaliPrimeClient({
"unified_api_key": "ek_bridge_xxx", # Never do this!
})
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
# Clone the repo
git clone https://github.com/enkaliprime/python-sdk.git
cd python-sdk
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black enkaliprime
isort enkaliprime
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
๐ Links
| Resource | Link |
|---|---|
| ๐ Documentation | docs.enkaliprime.com |
| ๐ Website | enkaliprime.com |
| ๐ฆ PyPI | pypi.org/project/enkaliprime |
| ๐ GitHub | github.com/enkaliprime/python-sdk |
| ๐ง Support | support@enkaliprime.com |
Built with โค๏ธ by the EnkaliPrime Team
ยฉ 2024 EnkaliPrime. All rights reserved.
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 enkaliprime-1.0.0.tar.gz.
File metadata
- Download URL: enkaliprime-1.0.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c91f74fcb65987e100543b8f223ea282ce7e5e68db08166419d6487ec578800c
|
|
| MD5 |
3c01a8fbf6da94eef7fba1d122c45f30
|
|
| BLAKE2b-256 |
3a39ebd7456493964c781c45a40d0eaf764b6165bebea92286da1907382bc599
|
File details
Details for the file enkaliprime-1.0.0-py3-none-any.whl.
File metadata
- Download URL: enkaliprime-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fa908d1510574a80ba9756600569c4ee91b4d92e47bc1012617bc3890889cc
|
|
| MD5 |
3171f93658dc962aba89f02771341701
|
|
| BLAKE2b-256 |
aae12c67666bbab81c493ae58b03e5e669ba9835b7cc596b9b3ae32140a88c44
|