Skip to main content

A Python client for the Sigscale OCS API

Project description

Sigscale OCS Python API Wrapper

A Python wrapper for the Sigscale OCS API supporting user signup, data purchases, balance top-ups, and offering management.

Features

  • User Signup - Add subscribers/services for SIM cards (TMF638)
  • Data Purchase - Create product subscriptions (TMF637)
  • Balance Top-Up - Add credits/data to user accounts (TMF654)
  • Offering Management - Admin creates/manages product offerings (TMF620)
  • Type-safe with dataclasses and comprehensive type hints
  • Specific exception classes for better error handling
  • SSL verification control for self-signed certificates
  • Real integration tests against live API
  • Automated PyPI publishing on releases

Installation

pip install sigscale-ocs-api

Configuration

Create a .env file with your OCS credentials:

SIGSCALE_OCS_URL=https://ocs-build.sigscale.org:8096
SIGSCALE_OCS_USERNAME=admin
SIGSCALE_OCS_PASSWORD=admin
SIGSCALE_OCS_VERIFY_SSL=false

Quick Start

Core Operations (Recommended)

For the essential operations, use the focused example:

# Make sure you have the package installed
pip install -e .

# Test the package (no API connection required)
python test_import.py

# Run the core operations example (SIM card creation, data purchase, balance top-up)
python core_example.py

Basic Usage

from sigscale_ocs import OCSClient, BalanceManagement, ProductCatalog, ProductInventory, ServiceInventory

# Initialize client
client = OCSClient()

# Or with explicit credentials
client = OCSClient(
    base_url="https://ocs-build.sigscale.org:8096",
    username="admin",
    password="admin",
    verify_ssl=False
)

User Signup (Service Inventory)

from sigscale_ocs import ServiceInventory

service_inventory = ServiceInventory(client)

# Create a new subscriber (user signup)
service_data = {
    "name": "John Doe",
    "description": "New subscriber",
    "status": "active",
    "serviceCharacteristic": [
        {"name": "IMSI", "value": "123456789012345"}
    ]
}

subscriber = service_inventory.create_service(service_data)
print(f"Created subscriber: {subscriber['id']}")

Data Purchase (Product Inventory)

from sigscale_ocs import ProductInventory

product_inventory = ProductInventory(client)

# Create a product subscription (data purchase)
product_data = {
    "name": "Data Subscription",
    "description": "1GB data plan subscription",
    "productOffering": {"id": "your-offering-id"}
}

subscription = product_inventory.create_product(product_data)
print(f"Created subscription: {subscription['id']}")

Balance Top-Up

from sigscale_ocs import BalanceManagement

balance = BalanceManagement(client)

# Top up balance for a product
result = balance.create_adjustment(
    product_id="1605455656771-64",
    amount=1000,  # $10.00 in cents
    units="cents",
    description="Balance top-up"
)
print(f"Balance adjustment: {result}")

# List buckets for a product
buckets = balance.list_buckets("1605455656771-64")
print(f"Product buckets: {buckets}")

# Format balance amounts for display
for bucket in buckets:
    amount = bucket.get('remaining_amount')
    units = bucket.get('units')
    if amount and units:
        formatted = balance.format_balance_amount(amount, units)
        print(f"Bucket {bucket['id']}: {formatted}")

Offering Management (Admin)

from sigscale_ocs import ProductCatalog

catalog = ProductCatalog(client)

# Create a new offering
offering_data = {
    "name": "Data Plan 1GB",
    "description": "1GB data plan",
    "isBundle": False,
    "productOfferingPrice": [
        {
            "id": "price-1",
            "name": "Monthly Price",
            "price": {
                "unit": "USD",
                "value": 29.99
            }
        }
    ]
}

offering = catalog.create_offering(offering_data)
print(f"Created offering: {offering['id']}")

# List all offerings
offerings = catalog.list_offerings()
print(f"Available offerings: {len(offerings)}")

API Reference

OCSClient

Base client for API interactions.

client = OCSClient(
    base_url="https://ocs-build.sigscale.org:8096",
    username="admin",
    password="admin",
    verify_ssl=False
)

BalanceManagement (TMF654)

Balance adjustments and bucket operations.

  • create_adjustment(product_id, amount, units='cents', description=None)
  • list_buckets(product_id, parse=True) - Get balance buckets (parsed by default)
  • get_bucket(bucket_id, parse=True) - Get bucket details (parsed by default)
  • format_balance_amount(amount, units) - Format amounts for display (e.g., "1000000000b octets" → "953.67 MB")

ProductCatalog (TMF620)

Product offering management.

  • list_offerings(fields=None, description=None, lifecycle_status=None, start_date=None, end_date=None, price=None)
  • create_offering(offering_data) - Create new offerings (may have request format limitations)
  • delete_offering(offering_id) - Delete offerings
  • list_catalogs() - List catalogs
  • list_categories() - List categories
  • list_product_specifications() - List product specifications

ProductInventory (TMF637)

Product subscription management.

  • list_products(fields=None, status=None, product_offering_id=None, start_date=None, end_date=None)
  • get_product(product_id)
  • create_product(product_data)
  • delete_product(product_id)

ServiceInventory (TMF638)

Service/subscriber management.

  • list_services(fields=None, status=None, product_id=None, start_date=None, end_date=None)
  • get_service(service_id)
  • create_service(service_data)
  • delete_service(service_id)

Error Handling

The wrapper provides specific exception classes for different error scenarios:

from sigscale_ocs import OCSClient, AuthenticationError, BadRequestError, NotFoundError, ServerError

try:
    client = OCSClient()
    # API calls...
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except BadRequestError as e:
    print(f"Bad request: {e}")
except NotFoundError as e:
    print(f"Resource not found: {e}")
except ServerError as e:
    print(f"Server error: {e}")

Development

Setup Development Environment

git clone https://github.com/keeganwhite/sigscale-ocs-api.git
cd sigscale-ocs-api
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e .[dev]

Running Tests

# Set up test credentials
export SIGSCALE_OCS_URL="https://ocs-build.sigscale.org:8096"
export SIGSCALE_OCS_USERNAME="admin"
export SIGSCALE_OCS_PASSWORD="admin"
export SIGSCALE_OCS_VERIFY_SSL="false"

# Run tests
pytest tests/

# Run with coverage
pytest tests/ --cov=sigscale_ocs --cov-report=html

Code Quality

# Linting
flake8 src/ tests/

# Type checking
mypy src/

# Formatting
black src/ tests/

Changelog

See CHANGELOG.md for a detailed list of changes and releases.

License

This project is licensed under the GNU GPL 3.0 - 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

sigscale_ocs_api-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

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

sigscale_ocs_api-0.1.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sigscale_ocs_api-0.1.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for sigscale_ocs_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fedd3fca8c9d8d522f0ae7383d8db1799317da505ff62a48ebddee5abca261a4
MD5 acf942e3da7fafc5ab235ca7359192da
BLAKE2b-256 5d891c6942b9bccb548482f2e163ddb08a0adba161df4ef6b266969cf0c2d431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sigscale_ocs_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aceb836be9c436f932c3847c9710f011cf72297bbc435c67c9f2de9e98a66692
MD5 8babd2e4476a52da059e1db1b7902330
BLAKE2b-256 ceda6377e2543fc45ebe44b8b8e4320cc4c899a1e5f65e379adb69f6b9190774

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