Skip to main content

Python SDK for Rose Recommendation Service API

Project description

Rose Python SDK

A comprehensive Python SDK for interacting with the Rose Recommendation Service API. This SDK provides a clean, type-safe interface for managing datasets, pipelines, roles, and recommendations.

🚀 Features

  • Complete API Coverage: Full support for all Rose Recommendation Service endpoints
  • Type Safety: Built with Pydantic for robust data validation and type hints
  • Comprehensive Error Handling: Detailed exception classes for different error scenarios
  • Batch Operations: Efficient batch data processing and upload capabilities
  • Schema Management: Automatic schema inference and validation
  • Pipeline Management: Intuitive pipeline creation and management tools
  • Role-Based Access Control: Complete permission and role management system
  • Helper Functions: High-level utilities for common operations

📦 Installation

pip install rose-python-sdk

🏃‍♂️ Quick Start

Basic Setup

from rose_sdk import RoseClient

# Initialize the client
client = RoseClient(
    base_url="https://admin.rose.blendvision.com",
    access_token="your_access_token"
)

Create a Dataset with Data

from rose_sdk import quick_create_dataset_with_data

# Create dataset with sample data
dataset_id = quick_create_dataset_with_data(
    client=client,
    name="user_interactions",
    records=[
        {"user_id": "user1", "item_id": "item1", "rating": 4.5},
        {"user_id": "user1", "item_id": "item2", "rating": 3.0},
        {"user_id": "user2", "item_id": "item1", "rating": 5.0}
    ],
    identifier_fields=["user_id", "item_id"],
    required_fields=["rating"]
)

Create a Recommendation Pipeline

from rose_sdk.utils import create_pipeline

# Create a pipeline with dataset mapping
pipeline_response = create_pipeline(
    client=client,
    account_id="your_account",
    pipeline_name="recommendation_pipeline",
    scenario="realtime_leaderboard",
    dataset_mapping={
        "interaction": dataset_id,  # Map pipeline key to your dataset
        "metadata": "your_metadata_dataset_id"
    }
)

Get Recommendations

# Get recommendations for a user
recommendations = client.recommendations.get(
    query_id="your_query_id",
    parameters={"user_id": "user1"}
)

print(f"Recommendations: {recommendations.data}")

📚 Documentation

📚 Core Modules

1. Client (RoseClient)

The main client class that provides access to all Rose services:

client = RoseClient(base_url="...", access_token="...")

# Access different services
client.datasets.create(...)      # Dataset management
client.pipelines.create(...)     # Pipeline management  
client.roles.create(...)         # Role management
client.recommendations.get(...)  # Get recommendations

2. Services

Organized service classes for different API endpoints:

  • DatasetService: Create, manage, and query datasets
  • PipelineService: Create and manage recommendation pipelines
  • RoleService: Manage user roles and permissions
  • RecommendationService: Get recommendations and query results

3. Models

Type-safe data models using Pydantic:

  • Dataset: Dataset information and metadata
  • Pipeline: Pipeline configuration and status
  • Role: User roles and permissions
  • Query: Query definitions and results

4. Utils

Utility functions for common operations:

  • Record Conversion: Convert between Python and Rose data formats
  • Schema Management: Build and validate dataset schemas
  • Batch Processing: Handle large data uploads efficiently
  • Pipeline Building: Create pipelines with minimal configuration

5. Helpers

High-level helper functions for quick operations:

  • quick_create_dataset_with_data(): Create dataset and add data in one call
  • quick_batch_upload(): Upload large amounts of data efficiently
  • quick_setup_recommendation_system(): Complete end-to-end setup

📖 Examples

The SDK includes comprehensive examples in the examples/ directory:

Role Management

python examples/01_role_management/01_basic_permissions.py
python examples/01_role_management/02_api_usage.py

Dataset Management

python examples/02_dataset_management/01_basic_datasets.py
python examples/02_dataset_management/02_api_usage.py

Records Management

python examples/03_records_management/01_basic_ingestion.py
python examples/03_records_management/02_records_management.py

Batch Data Management

python examples/04_batch_data_management/01_batch_append.py
python examples/04_batch_data_management/02_batch_overwrite.py

Pipeline Management

python examples/05_pipeline_management/01_create_pipeline.py
python examples/05_pipeline_management/02_update_pipeline.py
python examples/05_pipeline_management/04_delete_pipeline.py
python examples/05_pipeline_management/05_list_queries.py

🔧 Advanced Usage

Schema Validation

from rose_sdk.utils import validate_and_align_records

# Validate records against dataset schema
validated_records = validate_and_align_records(
    dataset_id=dataset_id,
    records=your_records,
    client=client
)

Batch Operations

from rose_sdk.utils import prepare_batch_data, get_batch_headers

# Prepare large dataset for batch upload
batch_data = prepare_batch_data(records)
headers = get_batch_headers()

# Upload in batches
client.datasets.batch.upload_batch(dataset_id, batch_id, batch_data)

Pipeline Building

from rose_sdk.utils import PipelineBuilder

# Build complex pipeline configurations
pipeline_config = (PipelineBuilder("account", "pipeline_name", "scenario")
    .add_dataset("interaction", dataset_id)
    .add_dataset("metadata", metadata_dataset_id)
    .set_custom_property("custom_setting", "value")
    .build())

🛠️ Error Handling

The SDK provides detailed exception classes for different error scenarios:

from rose_sdk import (
    RoseAPIError,
    RoseAuthenticationError,
    RosePermissionError,
    RoseNotFoundError,
    RoseValidationError,
    RoseConflictError,
    RoseServerError,
    RoseTimeoutError
)

try:
    dataset = client.datasets.get("invalid_id")
except RoseNotFoundError:
    print("Dataset not found")
except RoseAPIError as e:
    print(f"API error: {e}")

🔐 Authentication

The SDK supports multiple authentication methods:

# Access token authentication
client = RoseClient(
    base_url="https://admin.rose.blendvision.com",
    access_token="your_token"
)

# Environment variables
import os
client = RoseClient(
    base_url=os.getenv('ROSE_BASE_URL'),
    access_token=os.getenv('ROSE_ACCESS_TOKEN')
)

📋 Requirements

  • Python 3.11+
  • requests
  • pydantic
  • typing-extensions

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🔗 Links

🚀 CI/CD

This project uses GitHub Actions for automated testing and publishing:

  • Tests: Automatically run on every push and pull request
  • Publishing: Automatically publish to PyPI when version tags are pushed
  • Releases: Automatically create GitHub releases

For setup instructions, see GitHub Actions Setup Guide.

📊 Status

Tests PyPI Python License

📞 Support

For support and questions:

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

rose_python_sdk-1.1.0.tar.gz (68.8 kB view details)

Uploaded Source

Built Distribution

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

rose_python_sdk-1.1.0-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file rose_python_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: rose_python_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rose_python_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 64460c92b9b3eb827c0af0871d0c48cb4bd0a6627b6efdedae07bd3dddb3460a
MD5 ef4e7a56817433a88bb82a75940be373
BLAKE2b-256 1502ff8cc8ed29e117987f53f6325bdab772704c75c01dc4b9ed099a8e44bfce

See more details on using hashes here.

Provenance

The following attestation bundles were made for rose_python_sdk-1.1.0.tar.gz:

Publisher: publish.yml on luli0034/rose-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rose_python_sdk-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rose_python_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba62a1cb2d9601d3e8da8eb9c07d3b29f49e8f69c4479588a5c04258c942dc53
MD5 5dfe1f5cb31685a0cf5839043f4129b7
BLAKE2b-256 242ee3a88d310f5b435b3c6c1e3d68cb7cb8b192deae11b9db4f5c82c836f9d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for rose_python_sdk-1.1.0-py3-none-any.whl:

Publisher: publish.yml on luli0034/rose-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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