Python SDK for Eloq API
Project description
Eloq SDK Python
Python SDK for interacting with the Eloq API. This SDK provides a simple and intuitive interface for managing Eloq clusters, SKUs, and organizations.
Features
- Type-safe API: Uses Pydantic dataclasses for structured input/output
- Enum-based parameters: No need to guess parameter values - use enums for type safety
- Automatic error handling: Comprehensive exception handling with clear error messages
- Simple result objects: Operations return clear success/failure results
- Auto-detection: Automatically retrieves organization and project IDs from user context
Installation
Using pip
pip install eloq-sdk
Development Installation
git clone https://github.com/monographdb/eloq-sdk-python.git
cd eloq-sdk-python
pip install -e ".[dev]"
Requirements
- Python 3.7 or higher
requests>=2.25.0pydantic>=1.8.0
Quick Start
from eloq_sdk import EloqAPI
from eloq_sdk import schema
# Initialize client from environment variable
client = EloqAPI.from_environ()
# Get organization information
org_info = client.info()
print(f"Organization: {org_info.org_info.org_name}")
# List clusters
clusters = client.clusters()
print(f"Found {clusters.total} clusters")
Environment Setup
Set the ELOQ_API_KEY environment variable:
export ELOQ_API_KEY="your-api-key-here"
Authentication & Client Initialization
The SDK provides three ways to initialize the client:
1. From Environment Variable
from eloq_sdk import EloqAPI
client = EloqAPI.from_environ()
This reads the API key from the ELOQ_API_KEY environment variable.
2. From API Key
from eloq_sdk import EloqAPI
client = EloqAPI.from_key("your-api-key-here")
3. From API Key and Custom URL
from eloq_sdk import EloqAPI
client = EloqAPI.from_key_and_url(
"your-api-key-here",
"https://api-prod.eloqdata.com/api/v1/"
)
API Reference
Organization Management
info()
Get detailed organization and project information for the current user.
Input: None (automatically detected from user context)
Output: UserOrgInfoDTO object containing:
auth_provider(str): Authentication provider (e.g., "github")create_at(str): User account creation timestampemail(str): User email addressorg_info(OrgInfo): Organization information objectorg_id(int): Organization IDorg_name(str): Organization nameorg_create_at(str): Organization creation timestampprojects(List[SimpleProjectInfo]): List of projectsroles(List[str]): User roles
user_name(str): Username
Example:
org_info = client.info()
print(f"User: {org_info.user_name}")
print(f"Organization: {org_info.org_info.org_name}")
print(f"Projects: {len(org_info.org_info.projects)}")
org()
Get simplified organization information.
Input: None
Output: SimpleOrgInfo object containing:
org_name(str): Organization nameorg_id(int): Organization IDorg_create_at(str): Organization creation timestamp
Example:
org = client.org()
print(f"Organization: {org.org_name}")
print(f"ID: {org.org_id}")
Cluster Management
clusters(page=1, per_page=20)
List all clusters in the current project.
Input:
page(int, optional): Page number for pagination (default: 1)per_page(int, optional): Number of items per page (default: 20)
Output: ClusterList object containing:
cluster_list(List[ClusterListItem]): List of cluster itemstotal(int): Total number of clusters
ClusterListItem fields:
cloud_provider(str): Cloud provider (e.g., "AWS", "GCP")cluster_name(str): Cluster namecreate_at(str): Creation timestampmodule_type(str): Module type (e.g., "eloqkv", "eloqdoc")region(str): Regionstatus(str): Cluster statusversion(str): Versionzone(str): Availability zone
Example:
clusters = client.clusters(page=1, per_page=10)
print(f"Total clusters: {clusters.total}")
for cluster in clusters.cluster_list:
print(f"- {cluster.cluster_name} ({cluster.status})")
cluster(cluster_name)
Get detailed information about a specific cluster.
Input:
cluster_name(str): Cluster display name
Output: DescClusterDTO object containing:
admin_password(str): Base64-encoded admin passwordadmin_user(str): Base64-encoded admin usernamecloud_provider(str): Cloud providercluster_deploy_mode(str): Deployment modecreate_at(str): Creation timestampdisplay_cluster_name(str): Display nameelb_addr(str): Load balancer addresselb_port(int): Load balancer portelb_state(str): Load balancer statelog_cpu_limit(float): Log CPU limitlog_memory_mi_limit(float): Log memory limit (Mi)log_replica(int): Log replica countmodule_type(str): Module typeorg_name(str): Organization nameproject_name(str): Project nameregion(str): Regionstatus(str): Cluster statustx_cpu_limit(float): Transaction CPU limittx_memory_mi_limit(float): Transaction memory limit (Mi)tx_replica(int): Transaction replica countversion(str): Versionzone(str): Availability zone
Example:
cluster_info = client.cluster("my-cluster")
print(f"Status: {cluster_info.status}")
print(f"Region: {cluster_info.region}")
print(f"Module: {cluster_info.module_type}")
cluster_create(cluster_name, region, sku_id)
Create a new cluster.
Input:
cluster_name(str): Cluster display name (required)region(str): Region where the cluster will be created, e.g., "us-west-1" (required)sku_id(int): SKU ID for the cluster (required). Useget_skus()to find available SKU IDs
Output: OperationResult object containing:
success(bool): True if operation succeeded, False otherwisemessage(str): Human-readable message describing the result
Example:
from eloq_sdk import schema
# First, get available SKUs
skus = client.get_skus(
sku_type=schema.SKUType.SERVERLESS,
eloq_module=schema.EloqModule.ELOQKV,
cloud_provider=schema.CloudProvider.AWS
)
# Create the cluster
result = client.cluster_create(
cluster_name="my-cluster",
region="us-west-1",
sku_id=skus[0].sku_id
)
if result.success:
print(f"✅ {result.message}")
else:
print(f"❌ {result.message}")
cluster_delete(cluster_name)
Delete a cluster. The cluster must be in 'available' status to be deleted.
Input:
cluster_name(str): Cluster display name (required)
Output: OperationResult object containing:
success(bool): True if operation succeeded, False otherwisemessage(str): Human-readable message describing the result
Example:
result = client.cluster_delete("my-cluster")
if result.success:
print(f"✅ {result.message}")
else:
print(f"❌ {result.message}")
Note: The cluster must be in 'available' status to be deleted.
cluster_credentials(cluster_name)
Get cluster credentials (username and password) for database connection. The admin user ID and password are automatically decoded from base64 encoding.
Input:
cluster_name(str): Cluster display name (required)
Output: ClusterCredentials object containing:
username(str): Decoded admin usernamepassword(str): Decoded admin passwordhost(str): Load balancer addressport(int): Load balancer portstatus(str): Cluster status
Example:
credentials = client.cluster_credentials("my-cluster")
print(f"Username: {credentials.username}")
print(f"Password: {credentials.password}")
print(f"Host: {credentials.host}:{credentials.port}")
SKU Management
get_skus(sku_type, eloq_module, cloud_provider)
Get available SKUs filtered by SKU type, EloqDB module type, and cloud provider. Only SKUs available in the user's subscription plan are returned.
Input:
sku_type(SKUType enum): SKU type filterSKUType.SERVERLESS: Serverless SKUSKUType.DEDICATED: Dedicated SKU
eloq_module(EloqModule enum): EloqDB module type filterEloqModule.ELOQKV: EloqKV moduleEloqModule.ELOQDOC: EloqDoc module
cloud_provider(CloudProvider enum): Cloud provider filterCloudProvider.AWS: Amazon Web ServicesCloudProvider.GCP: Google Cloud Platform
Output: List of SKUInfo objects, each containing:
sku_id(int): SKU IDsku_name(str): SKU namesku_type(str): SKU type ("serverless", "dedicated", "unspecified")module_type(str): Module type ("EloqSQL", "EloqKV", "EloqDoc")version(str): Versiontx_cpu_limit(float): Transaction CPU limittx_memory_mi_limit(float): Transaction memory limit (Mi)tx_ev_gi_limit(float): Transaction ephemeral volume limit (Gi)tx_pv_gi_limit(float): Transaction persistent volume limit (Gi)log_cpu_limit(float): Log CPU limitlog_memory_mi_limit(float): Log memory limit (Mi)log_pv_gi_limit(float): Log persistent volume limit (Gi)cloud_provider(str): Cloud provider ("AWS", "GCP")tx_replica(int): Transaction replica countlog_replica(int): Log replica count
Example:
from eloq_sdk import schema
skus = client.get_skus(
sku_type=schema.SKUType.SERVERLESS,
eloq_module=schema.EloqModule.ELOQKV,
cloud_provider=schema.CloudProvider.AWS
)
print(f"Found {len(skus)} available SKUs:")
for sku in skus:
print(f" - SKU ID: {sku.sku_id}, Name: {sku.sku_name}")
print(f" Type: {sku.sku_type}, Module: {sku.module_type}")
print(f" Cloud: {sku.cloud_provider}")
Data Structures
OperationResult
Result object returned by create and delete operations.
@dataclass
class OperationResult:
success: bool # True if operation succeeded, False otherwise
message: str # Human-readable message describing the result
SKUInfo
SKU information object.
@dataclass
class SKUInfo:
sku_id: int
sku_name: str
sku_type: str
module_type: str
version: str
tx_cpu_limit: float
tx_memory_mi_limit: float
tx_ev_gi_limit: float
tx_pv_gi_limit: float
log_cpu_limit: float
log_memory_mi_limit: float
log_pv_gi_limit: float
cloud_provider: str
tx_replica: int
log_replica: int
ClusterList
List of clusters with pagination information.
@dataclass
class ClusterList:
cluster_list: List[ClusterListItem]
total: int
DescClusterDTO
Detailed cluster information.
@dataclass
class DescClusterDTO:
admin_password: str
admin_user: str
cloud_provider: str
cluster_deploy_mode: str
create_at: str
display_cluster_name: str
elb_addr: str
elb_port: int
elb_state: str
log_cpu_limit: float
log_memory_mi_limit: float
log_replica: int
module_type: str
org_name: str
project_name: str
region: str
status: str
tx_cpu_limit: float
tx_memory_mi_limit: float
tx_replica: int
version: str
zone: str
ClusterCredentials
Cluster credentials for database connection.
@dataclass
class ClusterCredentials:
username: str
password: str
host: str
port: int
status: str
UserOrgInfoDTO
User organization information.
@dataclass
class UserOrgInfoDTO:
auth_provider: str
create_at: str
email: str
org_info: OrgInfo
user_name: str
Enums
SKUType
class SKUType(Enum):
SERVERLESS = "serverless"
DEDICATED = "dedicated"
EloqModule
class EloqModule(Enum):
ELOQKV = "eloqkv"
ELOQDOC = "eloqdoc"
CloudProvider
class CloudProvider(Enum):
AWS = "aws"
GCP = "gcp"
Error Handling
The SDK provides comprehensive error handling with specific exception types:
Exception Types
EloqAPIError: Base exception for all API errorsEloqAuthenticationError: Authentication failed (401)EloqPermissionError: Permission denied (403)EloqNotFoundError: Resource not found (404)EloqRateLimitError: Rate limit exceeded (429)EloqValidationError: Invalid request (400)EloqServerError: Server error (500+)
Handling Errors
from eloq_sdk import EloqAPI
from eloq_sdk.exceptions import EloqAPIError, EloqNotFoundError
try:
cluster = client.cluster("non-existent-cluster")
except EloqNotFoundError:
print("Cluster not found")
except EloqAPIError as e:
print(f"API error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
Operation Results
For create and delete operations, errors are automatically handled and returned as OperationResult objects:
result = client.cluster_create(
cluster_name="my-cluster",
region="us-west-1",
sku_id=123
)
if not result.success:
print(f"Operation failed: {result.message}")
Complete Examples
Full Workflow: Get SKUs → Create Cluster → Check Status → Delete Cluster
from eloq_sdk import EloqAPI
from eloq_sdk import schema
# Initialize client
client = EloqAPI.from_environ()
# Step 1: Get available SKUs
skus = client.get_skus(
sku_type=schema.SKUType.SERVERLESS,
eloq_module=schema.EloqModule.ELOQKV,
cloud_provider=schema.CloudProvider.AWS
)
if not skus:
print("No SKUs available")
exit(1)
# Step 2: Create cluster
result = client.cluster_create(
cluster_name="my-cluster",
region="us-west-1",
sku_id=skus[0].sku_id
)
if not result.success:
print(f"Failed to create cluster: {result.message}")
exit(1)
print(f"✅ {result.message}")
# Step 3: Check cluster status
cluster_info = client.cluster("my-cluster")
print(f"Cluster status: {cluster_info.status}")
# Step 4: Get credentials
credentials = client.cluster_credentials("my-cluster")
print(f"Connection: {credentials.host}:{credentials.port}")
# Step 5: Delete cluster (when done)
result = client.cluster_delete("my-cluster")
if result.success:
print(f"✅ {result.message}")
More Examples
See the example/ directory for additional examples:
test_orginfo.py: Get organization informationtest_cluster.py: List and manage clusterstest_skus.py: Get available SKUstest_create_cluster.py: Create a new clustertest_delete_cluster.py: Delete a cluster
Requirements
- Python 3.7 or higher
requests>=2.25.0pydantic>=1.8.0
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Links
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 eloq_sdk-0.1.4.tar.gz.
File metadata
- Download URL: eloq_sdk-0.1.4.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d77a3ad4076e255c8e692184573ba8a6620500f72c101da4d8c75d1639290b1
|
|
| MD5 |
af1fe661ed379e50c4fc5b8628ad422a
|
|
| BLAKE2b-256 |
c603203af5cad30ad20236247cfeaf433b8267faf24173ed91f23f6e28dc2d10
|
File details
Details for the file eloq_sdk-0.1.4-py3-none-any.whl.
File metadata
- Download URL: eloq_sdk-0.1.4-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7577060bf705cd9c4798f0cdc84cb792db65b1748feda68b5bf53d9a44b03459
|
|
| MD5 |
00ee65a048ca58211509c01a6155b66b
|
|
| BLAKE2b-256 |
caa9381fad56022bf128ef3ffe5e51302b54a6d4a3b133793f6aff82b289bbb2
|