Skip to main content

Python client library for Workmate APIs

Project description

Workmate Library

A Python client library for interacting with Workmate APIs.

Installation

pip install -e .

Modules

  • risk_assessment - Model management functions
  • sbcc - SBCC message feedback management functions

Risk Assessment Module

The risk_assessment module provides functions for managing risk assessment models.

Setup

First, configure the API connection:

from rtv_workmate.risk_assessment import set_config

set_config(
    base_url="http://localhost:8000",
    api_key="wm_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)

# Or use JWT token
set_config(
    base_url="http://localhost:8000",
    jwt_token="your_jwt_token_here"
)

Usage Examples

List all models

from rtv_workmate.risk_assessment import list_models, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
models = list_models()
for model in models:
    print(f"{model['name']} - {model['category']} v{model['version']}")

Get a specific model

from rtv_workmate.risk_assessment import get_model, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
model = get_model({
    'name': 'UG_North_1_C',
    'category': 'classification',
    'version': '2025.0.1'
})
print(model['metrics'])

Create a model

from rtv_workmate.risk_assessment import create_model, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
create_model({
    'name': 'UG_North_1_C',
    'category': 'classification',
    'version': '2025.0.1',
    'description': 'Latest model for North region',
    'metrics': {'accuracy': 0.76, 'precision': 0.72, 'recall': 0.80},
    'model_file_path': '/path/to/model.pkl'
})

Update a model

from rtv_workmate.risk_assessment import update_model, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
updated_model = update_model(
    model_identifier={
        'name': 'UG_North_1_C',
        'category': 'classification',
        'version': '2025.0.1'
    },
    model_data={
        'description': 'Updated description',
        'metrics': {'accuracy': 0.78}
    }
)

Delete a model

from rtv_workmate.risk_assessment import delete_model, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
delete_model({
    'name': 'UG_North_1_C',
    'category': 'classification',
    'version': '2025.0.1'
})

Error Handling

from rtv_workmate.risk_assessment import get_model, APIError, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")

try:
    model = get_model({'name': 'test', 'category': 'test', 'version': '1.0'})
except APIError as e:
    print(f"API Error: {e.message} (Status: {e.status_code})")

API Reference

Configuration

  • set_config(base_url, api_key=None, jwt_token=None) - Set global API configuration

Model Functions

  • list_models() - Get all models
  • get_model(model_identifier) - Get a specific model. model_identifier dict requires: name, category, version
  • create_model(model_data) - Create a new model. model_data dict requires: name, category, version. Optional: description, metrics, other_training_results, model_file, model_file_path
  • update_model(model_identifier, model_data) - Update an existing model. model_identifier dict requires: name, category, version. model_data dict can contain any fields to update
  • delete_model(model_identifier) - Delete a model. model_identifier dict requires: name, category, version

Exceptions

  • APIError - Exception raised for API errors. Contains message and status_code attributes.

SBCC Module

The sbcc module provides functions for managing SBCC message feedback.

Setup

First, configure the API connection:

from rtv_workmate.sbcc import set_config

set_config(
    base_url="http://localhost:8000",
    api_key="wm_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)

# Or use JWT token
set_config(
    base_url="http://localhost:8000",
    jwt_token="your_jwt_token_here"
)

Usage Examples

List all message feedbacks

from rtv_workmate.sbcc import list_message_feedbacks, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
feedbacks = list_message_feedbacks()
for feedback in feedbacks:
    print(f"{feedback['practice']} - {feedback['barrier']}")

List with filters

from rtv_workmate.sbcc import list_message_feedbacks, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
# Filter by liked status and practice
feedbacks = list_message_feedbacks(filters={
    'is_liked': True,
    'practice': 'Handwashing'
})

Get a specific feedback

from rtv_workmate.sbcc import get_message_feedback, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
feedback = get_message_feedback(pk=1)
print(feedback['generated_message'])

Create a feedback

from rtv_workmate.sbcc import create_message_feedback, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
feedback = create_message_feedback({
    'form_guid': 'form-123',
    'user_guid': 'user-456',
    'practice': 'Handwashing',
    'barrier': 'Lack of soap',
    'generated_message': 'Remember to wash your hands with soap.',
    'is_liked': True,
    'preferred_message': 'Please wash hands before meals.',
    'test_mode': False  # Set to True to test without persisting
})

Update a feedback (full update)

from rtv_workmate.sbcc import update_message_feedback, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
updated = update_message_feedback(
    pk=1,
    feedback_data={
        'form_guid': 'form-123',
        'user_guid': 'user-456',
        'practice': 'Handwashing',
        'barrier': 'Lack of soap',
        'generated_message': 'Updated message.',
        'is_liked': False,
        'preferred_message': 'Updated preferred message.'
    }
)

Partial update

from rtv_workmate.sbcc import partial_update_message_feedback, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
updated = partial_update_message_feedback(
    pk=1,
    feedback_data={
        'is_liked': True,
        'preferred_message': 'New preferred message'
    }
)

Delete a feedback

from rtv_workmate.sbcc import delete_message_feedback, set_config

set_config(base_url="http://localhost:8000", api_key="your_api_key")
delete_message_feedback(pk=1, test_mode=False)

Test Mode

All create/update/delete operations support test mode, which allows you to test requests without persisting data:

# Test mode - data won't be persisted
create_message_feedback({
    'form_guid': 'form-123',
    'user_guid': 'user-456',
    'practice': 'Handwashing',
    'barrier': 'Lack of soap',
    'generated_message': 'Test message',
    'test_mode': True
})

API Reference

Configuration

  • set_config(base_url, api_key=None, jwt_token=None) - Set global API configuration

Message Feedback Functions

  • list_message_feedbacks(filters=None) - List all feedbacks. filters dict can contain: form_guid, user_guid, practice, barrier, is_liked
  • get_message_feedback(pk) - Get a specific feedback by ID
  • create_message_feedback(feedback_data) - Create a new feedback. feedback_data dict requires: form_guid, user_guid, practice, barrier, generated_message. Optional: is_liked, preferred_message, test_mode
  • update_message_feedback(pk, feedback_data) - Update all fields of a feedback (PUT). feedback_data dict requires: form_guid, user_guid, practice, barrier, generated_message, is_liked. Optional: preferred_message, test_mode
  • partial_update_message_feedback(pk, feedback_data) - Partially update a feedback (PATCH). feedback_data dict can contain any fields to update. Optional: test_mode
  • delete_message_feedback(pk, test_mode=False) - Delete a feedback

Exceptions

  • APIError - Exception raised for API errors. Contains message and status_code attributes.

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

rtv_workmate-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

rtv_workmate-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file rtv_workmate-0.1.0.tar.gz.

File metadata

  • Download URL: rtv_workmate-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.3 Darwin/25.2.0

File hashes

Hashes for rtv_workmate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 34fda2a8127b257672f026ab7aa58b26ee993502bce6f61a7dbc7ecab33e9184
MD5 b2bd77ad0964f48bc913d697f9471342
BLAKE2b-256 bfe794e3ad7bc5030c4ea1b502097b2f32df2b3a65e8ffe4e0cd4501d161cfd7

See more details on using hashes here.

File details

Details for the file rtv_workmate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rtv_workmate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.14.3 Darwin/25.2.0

File hashes

Hashes for rtv_workmate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e2fd679137b89c9981e66841a6c3ebd854ea08858390b4ffed2b0fbf3394269
MD5 770932411b1862568f29a1f8c6667152
BLAKE2b-256 1a039f0fcef990d2f193423aa8ba5d2fe7fd6dea61d1b7f9d3d8e401a9c1e277

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