Python SDK for OASM platform
Project description
OASM SDK for Python
The OASM SDK for Python provides a convenient interface to interact with the OASM (Open API Service Manager) API. This SDK allows you to easily manage workers and communicate with the OASM service.
Features
- Easy-to-use client for OASM API
- Functional options pattern for flexible client configuration
- Built-in retry mechanism for robust API communication
- Support for worker registration and keep-alive signals
- Comprehensive error handling with custom exceptions
- Full type hints for better development experience
Installation
To install the OASM SDK, you can use pip:
pip install oasm-sdk
Or if you have the source code:
pip install .
Requirements
- Python 3.7 or higher
- requests>=2.25.0
- urllib3>=1.26.0
Quick Start
Creating a Client
from client import Client, with_api_url, with_api_key
# Create a client with default settings
client = Client()
# Create a client with custom settings
client = Client(
with_api_url("https://api.oasm.com"),
with_api_key("your-api-key-here")
)
Health Check
try:
is_healthy = client.health()
print(f"API is {'healthy' if is_healthy else 'unhealthy'}")
except Exception as e:
print(f"Health check failed: {e}")
Worker Management
Joining a Worker
from worker import worker_join
try:
response = worker_join(client)
print(f"Worker joined with ID: {response.id}")
print(f"Worker token: {response.token}")
except Exception as e:
print(f"Failed to join worker: {e}")
Sending Keep-Alive Signal
from worker import worker_alive
try:
token = "your-worker-token"
response = worker_alive(client, token)
print(f"Keep-alive response: {response.alive}")
except Exception as e:
print(f"Keep-alive failed: {e}")
API Reference
Client
The Client class is the main entry point for interacting with the OASM API.
Constructor
Client(*opts: Option)
Creates a new client instance with the provided options.
Options
with_api_url(api_url: str): Sets the base API URLwith_api_key(api_key: str): Sets the API keywith_session(session: Session): Sets a custom requests session
Methods
health() -> bool: Checks the health status of the API
Worker Functions
worker_join(client: Client) -> WorkerJoinResponse: Registers a new workerworker_alive(client: Client, token: str) -> WorkerAliveResponse: Sends a keep-alive signal
Exceptions
APIError: Raised when the API returns an error response
Development
Running Tests
To run the tests, use:
python -m pytest
Dependencies
To install development dependencies:
pip install -r requirements.txt
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 oasm_sdk-0.1.0.tar.gz.
File metadata
- Download URL: oasm_sdk-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e97436c005a0b027df3203b881590c81d67dd5d0f805699ec6ac86223e59e252
|
|
| MD5 |
354d7dc89a08c6d1d781ff9c95a4679d
|
|
| BLAKE2b-256 |
37a50a8da6137cd18f329697796c99ba6ada9486eff1437565d592c7bda770d2
|
File details
Details for the file oasm_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: oasm_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8d64822a14f6512299775f8f2f5579ae9f275fca903f13e3cd36a7ac119865e
|
|
| MD5 |
c56a59589ae2325811c81759a5486933
|
|
| BLAKE2b-256 |
2eb6c36e569f96c356da38ff6f93c4eafc82a8b06a7816d1f13da3ca51a51ea8
|