Memfabric Hybrid Python API
The `memfabric-hybrid` library provides a Python API client for interacting with the Memfabric Hybrid data platform. It simplifies operations like endpoint management and data access within a hybrid cloud environment. The current version is 1.0.8, with releases appearing to be made as features are developed or bugs are fixed, indicating an active development status.
Common errors
-
ModuleNotFoundError: No module named 'memfabric_hybrid'
cause The `memfabric-hybrid` package has not been installed in the current Python environment.fixRun `pip install memfabric-hybrid` to install the library. -
memfabric_hybrid.exceptions.AuthError: Authentication failed. Please check your API key.
cause The `MEMFABRIC_API_KEY` environment variable is either missing, incorrect, or expired.fixVerify that `MEMFABRIC_API_KEY` is set to a valid and active API key for your Memfabric account. Example: `export MEMFABRIC_API_KEY="your_valid_key"` -
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.memfabric.com', port=443): Max retries exceeded with url: /api/v1/endpoints (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x...>: Failed to establish a new connection: [Errno 111] Connection refused'))cause The client could not establish a connection to the specified `MEMFABRIC_API_URL`. This could be due to an incorrect URL, network issues, or the API being unavailable.fixCheck the value of `MEMFABRIC_API_URL` environment variable. Ensure there are no network restrictions (e.g., firewalls) preventing access to the Memfabric API. Verify the API endpoint status if possible.
Warnings
- gotcha The `MemfabricClient` relies heavily on environment variables (`MEMFABRIC_API_KEY`, `MEMFABRIC_API_URL`) for configuration. If these are not set or are incorrect, the client will fail to authenticate or connect.
- gotcha Direct network connectivity to the Memfabric API endpoint is crucial. Connection issues, firewalls, or incorrect `MEMFABRIC_API_URL` can lead to `requests.exceptions.ConnectionError`.
- gotcha API operations can raise specific exceptions like `AuthError` (for authentication failures) or `APIError` (for general API-side errors). Generic `Exception` catching might hide specific issues.
Install
-
pip install memfabric-hybrid
Imports
- MemfabricClient
from memfabric_hybrid import MemfabricClient
from memfabric_hybrid.client import MemfabricClient
Quickstart
import os
from memfabric_hybrid.client import MemfabricClient
from memfabric_hybrid.exceptions import AuthError, APIError
# Configure API credentials and URL using environment variables
# For example:
# export MEMFABRIC_API_KEY="your_api_key_here"
# export MEMFABRIC_API_URL="https://api.memfabric.com"
# Ensure environment variables are set for a successful connection
api_key = os.environ.get('MEMFABRIC_API_KEY', '')
api_url = os.environ.get('MEMFABRIC_API_URL', '')
if not api_key or not api_url:
print("Warning: MEMFABRIC_API_KEY and MEMFABRIC_API_URL environment variables are not set.")
print("Please set them to run this example successfully.")
else:
try:
client = MemfabricClient()
print("MemfabricClient initialized successfully.")
# Example: List available endpoints
endpoints = client.get_endpoints()
print(f"Available endpoints: {endpoints}")
except AuthError as e:
print(f"Authentication error: {e}. Check your API key.")
except APIError as e:
print(f"Memfabric API error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")