Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "rubix-py"
version = "0.6.0"
version = "0.7.0"
description = "Rubix Client SDK for Python"
requires-python = ">=3.10"
license = { text = "MIT" }
Expand Down
27 changes: 23 additions & 4 deletions rubix/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
from urllib.parse import urljoin

class RubixClient:
def __init__(self, node_url: str = "http://localhost:20000", timeout: int = 300):
def __init__(
self,
node_url: str = "http://localhost:20000",
timeout: int = 300,
api_key: Optional[str] = None
):
"""
Initialize Rubix client.

Args:
node_url: Base URL of the Rubix node
timeout: Request timeout in seconds (default: 300)
api_key (str, Optional): API Key passed in request header
"""

self.node_url = node_url.rstrip('/') # Remove trailing slash
self._timeout = timeout
self._api_key = api_key

def _make_get_request(
self,
Expand Down Expand Up @@ -85,12 +92,18 @@ def _make_post_request(
# Build full URL
url = urljoin(self.node_url, endpoint)

# Add headers
headers: Dict[str, str] = {}
if self._api_key:
headers["X-API-Key"] = self._api_key

try:
response = requests.post(
url,
json=json_data,
params=params,
timeout=self._timeout
timeout=self._timeout,
headers=headers
)

# Raise for HTTP errors (4xx, 5xx)
Expand Down Expand Up @@ -138,14 +151,20 @@ def _make_form_data_request(
"""
# Build full URL
url = urljoin(self.node_url, endpoint)


# Add Headers
headers: Dict[str, str] = {}
if self._api_key:
headers["X-API-Key"] = self._api_key

try:
response = requests.post(
url,
files=files,
data=data,
params=params,
timeout=self._timeout
timeout=self._timeout,
headers=headers
)

# Raise for HTTP errors (4xx, 5xx)
Expand Down