diff --git a/pyproject.toml b/pyproject.toml index 3cd30ad..8723d28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" } diff --git a/rubix/client.py b/rubix/client.py index 0929ef1..7eb294f 100644 --- a/rubix/client.py +++ b/rubix/client.py @@ -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, @@ -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) @@ -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)