Cliente Python para a API do StackSpot
Project description
StackSpot Client Python
A Python client library for interacting with the StackSpot API. This library provides a simple and intuitive interface to authenticate, execute commands, and retrieve results from the StackSpot platform.
Features
- 🔐 Automatic authentication handling
- 🔄 Automatic token refresh
- ⚡ Retry mechanism for failed requests
- 🛡️ Comprehensive error handling
- 📦 Support for different response types
- 🧪 Type hints for better IDE support
Installation
You can install the package using pip:
pip install stackspot-client
Quick Start
from stackspot_client import StackSpotConfig, StackSpotClient
# Configure the client
config = StackSpotConfig(
base_url='https://genai-code-buddy-api.stackspot.com',
auth_url='https://idm.stackspot.com/stackspot-freemium/oidc/oauth/token',
client_id='your_client_id',
client_secret='your_client_secret'
)
# Create client instance
client = StackSpotClient(config)
# Execute a command
execution_id = client.execute_command('your_command', {'data': 'example'})
# Get the result
result = client.get_execution_result(execution_id)
print(result)
Configuration
The StackSpotConfig class accepts the following parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| base_url | str | Yes | - | Base URL for the StackSpot API |
| client_id | str | Yes | - | Your StackSpot client ID |
| client_secret | str | Yes | - | Your StackSpot client secret |
| auth_url | str | No | https://idm.stackspot.com/stackspot-freemium/oidc/oauth/token | Authentication URL |
| max_retries | int | No | 30 | Maximum number of retries for result polling |
| retry_interval | int | No | 5 | Interval between retries in seconds |
Usage Examples
Basic Command Execution
from stackspot_client import StackSpotConfig, StackSpotClient
config = StackSpotConfig(
base_url='https://genai-code-buddy-api.stackspot.com',
client_id='your_client_id',
client_secret='your_client_secret'
)
client = StackSpotClient(config)
# Execute a simple command
execution_id = client.execute_command('analyze-code', {
'code': 'def hello(): print("Hello, World!")',
'language': 'python'
})
# Get the result
result = client.get_execution_result(execution_id)
print(result)
Error Handling
from stackspot_client import StackSpotClient, StackSpotConfig, AuthenticationError, APIError
try:
client = StackSpotClient(config)
result = client.execute_command('invalid-command', {})
except AuthenticationError as e:
print(f"Authentication failed: {e}")
except APIError as e:
print(f"API error occurred: {e}")
Response Format
The get_execution_result method returns a dictionary with the following structure:
{
'status': 'COMPLETED', # or 'FAILED', 'RUNNING'
'answer': '...', # The actual response
'progress': { # Optional progress information
'status': 'COMPLETE',
'percentage': 100
}
}
Error Types
The library provides several error types for better error handling:
StackSpotError: Base exception classAuthenticationError: Raised when authentication failsAPIError: Raised when API calls fail
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For support with the StackSpot API, please refer to the official documentation.
Changelog
0.1.0
- Initial release
- Basic authentication and command execution
- Result polling with retry mechanism
- Comprehensive error handling
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 stackspot_client-0.1.1.tar.gz.
File metadata
- Download URL: stackspot_client-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da66c3d5ca7cd31904987f9851ed3a06f9c7b59629d7617cd72b5f6dd96996b8
|
|
| MD5 |
97f58a529f6e02e0b6a14b67bd8c7a53
|
|
| BLAKE2b-256 |
26fdd8141582a7e270f6cb33a75ebdee650f31c09bcd2182b55131586267e041
|
File details
Details for the file stackspot_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stackspot_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bccd97aaf61421c58b1bbd7c463bb8c22598b438115722ca467f8a5b6decb728
|
|
| MD5 |
66c1dca1b9bc2537220be2a8240bae6d
|
|
| BLAKE2b-256 |
ad28b0e448994fe3aa2b5c9352f261f0cb17b5929750c2a57b94fae61fee6547
|