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
- Complete Documentation - Full documentation with API reference, examples, and guides
- GitHub Repository - Source code and issue tracking
- Contributing Guide - How to contribute to the project
📚 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 datasetsPipelineService: Create and manage recommendation pipelinesRoleService: Manage user roles and permissionsRecommendationService: Get recommendations and query results
3. Models
Type-safe data models using Pydantic:
Dataset: Dataset information and metadataPipeline: Pipeline configuration and statusRole: User roles and permissionsQuery: 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 callquick_batch_upload(): Upload large amounts of data efficientlyquick_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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- 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 the Contributing Guide.
📊 Status
📞 Support
For support and questions:
- Create an issue on GitHub
- Contact: luli245683@gmail.com
Project details
Release history Release notifications | RSS feed
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 rose_python_sdk-1.2.0.tar.gz.
File metadata
- Download URL: rose_python_sdk-1.2.0.tar.gz
- Upload date:
- Size: 91.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db31424b27d9ecd585063546c56d31034471b0a553334e053c57e8c0b8f0666f
|
|
| MD5 |
669c03baf4133c38c13303cbd797f402
|
|
| BLAKE2b-256 |
1bf4bbd1bdc0f97a5c93ebc28badb49bbf0269977b46e1690d9e22a9c6342758
|
Provenance
The following attestation bundles were made for rose_python_sdk-1.2.0.tar.gz:
Publisher:
publish.yml on luli0034/rose-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rose_python_sdk-1.2.0.tar.gz -
Subject digest:
db31424b27d9ecd585063546c56d31034471b0a553334e053c57e8c0b8f0666f - Sigstore transparency entry: 643890662
- Sigstore integration time:
-
Permalink:
luli0034/rose-python-sdk@178c2a6425b5412ea20c979df675c2ae89211014 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/luli0034
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@178c2a6425b5412ea20c979df675c2ae89211014 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rose_python_sdk-1.2.0-py3-none-any.whl.
File metadata
- Download URL: rose_python_sdk-1.2.0-py3-none-any.whl
- Upload date:
- Size: 40.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f433a09a5d8ef734cea6d847628236a6237fc44db2481a0d7cb3a5c715a40e4
|
|
| MD5 |
826eab0b0dd1889505314c2dae33e254
|
|
| BLAKE2b-256 |
95ec3962be34114d86b3b36688242f6339fc33da67fb68c6f8058d4a54f42951
|
Provenance
The following attestation bundles were made for rose_python_sdk-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on luli0034/rose-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rose_python_sdk-1.2.0-py3-none-any.whl -
Subject digest:
7f433a09a5d8ef734cea6d847628236a6237fc44db2481a0d7cb3a5c715a40e4 - Sigstore transparency entry: 643890683
- Sigstore integration time:
-
Permalink:
luli0034/rose-python-sdk@178c2a6425b5412ea20c979df675c2ae89211014 -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/luli0034
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@178c2a6425b5412ea20c979df675c2ae89211014 -
Trigger Event:
push
-
Statement type: