Before diving in, ensure that you have the following:
A system running Linux, macOS, or Windows.
Python 3.8 or above (recommended for running CLI tools and scripts).
Access to Clore’s API (an API key, available in your Clore developer account).
Basic knowledge of the command line.
Step 1: Installing the Toolkit
To begin, download and install the Clore Developer Toolkit. Use the following commands to install it directly from Clore’s GitHub repository.
# Clone the Clore Developer Toolkit repositorygitclonehttps://github.com/clore-ai/clore-dev-toolkit.gitcdclore-dev-toolkit# Install dependenciespipinstall-rrequirements.txt
If you’re using a virtual environment, activate it first to keep the dependencies isolated:
# Create and activate a virtual environmentpython3-mvenvclore_envsourceclore_env/bin/activate# Install dependencies within the virtual environmentpipinstall-rrequirements.txt
Step 2: Configuration and Authentication
Once installed, the next step is configuring the toolkit with your Clore API key. This key is essential for authentication.
Navigate to “API Keys” and click on “Generate New Key.”
Save the key securely; you’ll need it in the configuration step.
Configuring the Toolkit
Create a .env file in the clore-dev-toolkit directory for secure storage of your API key and other configuration settings.
Load this configuration in the toolkit using a Python script:
Step 3: Verifying API Connection
With the toolkit installed and configured, verify the API connection by making a test request. Here’s an example Python script to fetch account information.
Run this script to confirm that the API key is correctly configured and that your system can connect to Clore’s API. A successful output will show your account details.
Step 4: Running Sample Scripts
The toolkit includes sample scripts to help you get started quickly. To run a sample script, execute the following:
Example Code from sample_rent_server.py
Here’s a portion of the script to rent a server:
This example script demonstrates the basics of API interaction for renting servers and can be expanded for custom configurations and error handling.
Step 5: Customizing the Toolkit
For more advanced users, the toolkit can be customized to add additional functionalities or tailored requests. Consider adding modules or helper functions for tasks such as bulk server management or real-time monitoring.
Adding Helper Functions
Create a helpers.py file to store utility functions that streamline repetitive tasks. For instance:
Now, you can use api_request() in other scripts for a cleaner code structure:
Final Step: Testing and Troubleshooting
With everything set up, perform a full test of your toolkit installation by running each script in the examples/ directory. Monitor for any errors, and consult the toolkit’s logs if needed.
Common Troubleshooting Tips
Connection Issues: Verify network access and API endpoint availability.
Authentication Errors: Double-check the API key configuration.
Dependency Issues: Reinstall dependencies with pip install -r requirements.txt in case of errors.
By following these steps, you should now have a fully operational Clore Developer Toolkit setup, enabling you to explore more advanced features and start building your Clore-based applications.
from dotenv import load_dotenv
import os
# Load environment variables from the .env file
load_dotenv()
CLORE_API_KEY = os.getenv("CLORE_API_KEY")
# Test the API key loading
print("API Key Loaded Successfully:", CLORE_API_KEY is not None)
import requests
# Base URL for Clore API
API_BASE_URL = "https://api.clore.ai/v1"
def get_account_info():
headers = {
"Authorization": f"Bearer {CLORE_API_KEY}",
"Content-Type": "application/json"
}
response = requests.get(f"{API_BASE_URL}/account", headers=headers)
# Check if the request was successful
if response.status_code == 200:
return response.json()
else:
print("Failed to fetch account info:", response.status_code, response.text)
return None
# Fetch and print account information
account_info = get_account_info()
print("Account Information:", account_info)
python examples/sample_rent_server.py
import requests
import json
def rent_server(server_id, duration):
payload = {
"server_id": server_id,
"duration": duration
}
headers = {
"Authorization": f"Bearer {CLORE_API_KEY}",
"Content-Type": "application/json"
}
response = requests.post(f"{API_BASE_URL}/rent", headers=headers, json=payload)
if response.status_code == 200:
print("Server rented successfully:", response.json())
else:
print("Error renting server:", response.status_code, response.text)
# Example usage
rent_server(server_id=123, duration=6) # Rent server with ID 123 for 6 hours