Python SDK for Infino API with AWS SigV4 authentication
Project description
Infino Python SDK
Python SDK for interacting with Infino's API, providing AWS SigV4 authenticated access to search, analytics, and AI capabilities.
Installation
pip install infino-sdk
Quick Start
from infino_sdk.lib import InfinoSDK
import asyncio
async def main():
# Create SDK instance with your credentials
async with InfinoSDK(
access_key="your_access_key",
secret_key="your_secret_key",
endpoint="http://localhost:9200"
) as sdk:
# Check connection
info = await sdk.ping()
print(f"Connected to: {info}")
# Create an index
await sdk.create_index("my_index")
# Search documents
query = '{"query": {"match_all": {}}}'
results = await sdk.search("my_index", query)
print(f"Search results: {results}")
# Run the async function
asyncio.run(main())
Usage Examples
Basic Operations
from infino_sdk.lib import InfinoSDK
async with InfinoSDK(access_key, secret_key, endpoint) as sdk:
# Index operations
await sdk.create_index("products")
await sdk.delete_index("old_products")
indices = await sdk.get_cat_indices()
# Document operations
doc = await sdk.get_document("products", "doc_id")
source = await sdk.get_source("products", "doc_id")
# Search operations
results = await sdk.search("products", '{"query": {"term": {"category": "electronics"}}}')
ai_results = await sdk.search_ai("products", "find all smartphones")
# SQL queries
sql_results = await sdk.sql("SELECT * FROM products WHERE price > 100")
# Bulk operations
bulk_data = '{"index": {"_id": "1"}}\n{"name": "Product 1"}\n'
await sdk.bulk_ingest("products", bulk_data)
WebSocket Connections
async with InfinoSDK(access_key, secret_key, endpoint) as sdk:
# Connect to WebSocket endpoint with automatic SigV4 authentication
ws = await sdk.websocket_connect("/_conversation/ws")
try:
# Send message
await ws.send('{"type": "message", "content": "Hello"}')
# Receive response
response = await ws.recv()
print(f"Received: {response}")
finally:
await ws.close()
Security Operations
async with InfinoSDK(access_key, secret_key, endpoint) as sdk:
# User management
user_config = {
"password": "strong_password",
"backend_roles": ["admin"]
}
await sdk.create_user("new_user", user_config)
users = await sdk.list_users()
# Role management
role_config = {
"cluster_permissions": ["indices:admin/*"],
"index_permissions": [{
"index_patterns": ["*"],
"allowed_actions": ["read", "write"]
}]
}
await sdk.create_role("custom_role", role_config)
# Role mapping
mapping_config = {
"users": ["new_user"],
"backend_roles": ["custom_role"]
}
await sdk.create_role_mapping("my_mapping", mapping_config)
ML Commons Operations
async with InfinoSDK(access_key, secret_key, endpoint) as sdk:
# Register a model
model_config = {
"name": "my_model",
"version": "1.0",
"model_type": "text_embedding"
}
result = await sdk.register_model(model_config)
model_id = result["model_id"]
# Deploy the model
await sdk.deploy_model(model_id)
# Make predictions
input_data = {"text": "Sample text for embedding"}
prediction = await sdk.predict(model_id, input_data)
# Undeploy when done
await sdk.undeploy_model(model_id)
Account Management
async with InfinoSDK(access_key, secret_key, endpoint) as sdk:
# Create a new account (no authentication required)
account_data = {
"public": "account_name",
"private": "account_password"
}
new_account = await sdk.create_account(account_data)
account_id = new_account["account_id"]
# Get account information
account_info = await sdk.get_account(account_id)
# Rotate API keys
new_keys = await sdk.rotate_api_keys("username")
print(f"New access key: {new_keys['access_key']}")
# Delete account
await sdk.delete_account(account_id)
Manual Session Management
If you need more control over the session lifecycle:
from infino_sdk.lib import InfinoSDK
# Create SDK instance
sdk = InfinoSDK(access_key, secret_key, endpoint)
# Initialize session manually
await sdk._ensure_session()
try:
# Use SDK methods
await sdk.ping()
results = await sdk.search("my_index", query)
finally:
# Always close the session when done
await sdk.close()
API Reference
Core Methods
ping()- Test connection to the Infino endpointclose()- Close the underlying HTTP session
Index Operations
create_index(index_name)- Create a new indexcreate_index_with_mapping(index_name, mapping)- Create index with custom mappingdelete_index(index_name)- Delete an indexget_index(index_name)- Get index informationget_cat_indices()- List all indices
Document Operations
get_document(index, doc_id)- Retrieve a documentget_source(index, doc_id)- Get document sourcedocument_exists(index, doc_id)- Check if document existsdelete_by_query(index, query)- Delete documents matching query
Search Operations
search(index, query)- Execute a search querysearch_ai(index, query_text)- AI-powered natural language searchmsearch(queries)- Multi-search across indicessql(query)- Execute SQL querycount(index, query)- Count matching documents
Bulk Operations
bulk_ingest(index, payload)- Bulk index documents (NDJSON format)metrics(index, payload)- Ingest metrics data
WebSocket
websocket_connect(path, headers=None)- Connect to WebSocket with SigV4 auth
Security APIs
create_user(),get_user(),update_user(),delete_user(),list_users()create_role(),get_role(),update_role(),delete_role(),list_roles()create_role_mapping(),get_role_mapping(),update_role_mapping(),delete_role_mapping()rotate_api_keys(username)- Rotate user API keys
Authentication
The SDK uses AWS SigV4 authentication. All requests are automatically signed with your access key and secret key. For WebSocket connections, authentication is provided via query parameters.
Error Handling
from infino_sdk.lib import InfinoError
try:
await sdk.get_document("index", "missing_doc")
except InfinoError as e:
if e.status_code() == 404:
print("Document not found")
else:
print(f"Error: {e.message}")
Requirements
- Python 3.7+
- requests
- websockets
- backoff
License
See LICENSE file in the repository root.
Development & Publishing
Setup Development Environment
pip install -e .[dev]
Pre-Publication Checklist
Before publishing to PyPI, ensure:
- Version number updated in
pyproject.tomland__init__.py - CHANGELOG.md updated with release notes
- README.md reviewed and accurate
- LICENSE file present in package root
- Dependencies verified and correct
- Build succeeds:
python -m build - Package installable locally:
pip install dist/*.whl - Import works:
python -c "from infino_sdk import InfinoSDK; print('OK')" -
twine check dist/*passes without warnings
Publishing Workflow
1. Test with TestPyPI
Build the package:
cd sdk/python
python -m build
Check the distribution:
twine check dist/*
Upload to TestPyPI:
twine upload --repository testpypi dist/*
Test installation from TestPyPI:
pip install --index-url https://test.pypi.org/simple/ --no-deps infino-sdk
python -c "from infino_sdk import InfinoSDK; print('Success!')"
2. Publish to PyPI
Once tested on TestPyPI, publish to production PyPI:
twine upload dist/*
Verify installation:
pip install infino-sdk
Notes
- Package name on PyPI:
infino-sdk(kebab-case) - Import name in Python:
infino_sdk(snake_case) - Always test on TestPyPI before production PyPI
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 infino_sdk-0.1.0.tar.gz.
File metadata
- Download URL: infino_sdk-0.1.0.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c90bd045edd39c86cbe04ae278d6e11acdf29247351bff9524d5a5f42e28a01c
|
|
| MD5 |
d1e1e87750ed0b81af0b8e036be2f019
|
|
| BLAKE2b-256 |
07b498446927c9cf3e1e6aebc840f45ad3309751168d7755b2d215b976f0811d
|
File details
Details for the file infino_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: infino_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afd776acebfbc67251742d4d82eddcb7e0d789acbf59fec06c0b19890ffc3177
|
|
| MD5 |
9eb7dce88472d50128f8f81b4a6d233e
|
|
| BLAKE2b-256 |
229a59459491fa086e08bb89ad7b4f159ee9c8e54e338f104ed563e74e57eced
|