Skip to main content

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 URL
  • with_api_key(api_key: str): Sets the API key
  • with_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 worker
  • worker_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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

oasm_sdk-0.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oasm_sdk-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file oasm_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: oasm_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for oasm_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a7e98e760c8a3982c423b835f737c68836dc87d1218d747b2b1222f0995a9c57
MD5 32fcdcc4c1cdfc046c29069cb0b32bdc
BLAKE2b-256 218ceb8d610e232871c94034834452e3d228e7a92634f2f451db42025562fffa

See more details on using hashes here.

File details

Details for the file oasm_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: oasm_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for oasm_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f9989a0d3d5553e040005ceeaa71f7ffe6ddc0ef56b428430f021fd539d8cff
MD5 399affa98f38f2419d6aad1e2935f88e
BLAKE2b-256 9feebe1a1cbfc5a249d644af6a9251177c27c8990c9615190bda3d36d82ec1b9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page