Skip to main content

Python SDK for Subspace Computing Engine API (by Beausoft)

Project description

Subspace Computing Engine - Python SDK

Python SDK for the Subspace Computing Engine API (by Beausoft).

Installation

pip install subspacecomputing

Usage

Initialization

from subspacecomputing import BSCE

# Initialize the client (defaults to production URL)
bsce = BSCE(api_key='your-api-key-here')

# For local testing or custom environments (optional)
# bsce = BSCE(api_key='your-api-key-here', base_url='http://localhost:8000')

Simple Projection (1 scenario)

# Create a simple SP Model
spec = {
    'scenarios': 1,  # Must be 1 for /project
    'steps': 12,
    'variables': [
        {
            'name': 'capital',
            'init': 1000.0,
            'formula': 'capital[t-1] * 1.05'  # 5% growth per period
        }
    ]
}

# Run the projection
result = bsce.project(spec)

# Display results
print(f"Final capital: {result['final_values']['capital']}")
print(f"Trajectory: {result['trajectory']['capital']}")

Monte Carlo Simulation (Multiple scenarios)

# SP Model with random variables
spec = {
    'scenarios': 1000,  # 1000 Monte Carlo scenarios
    'steps': 12,
    'variables': [
        {
            'name': 'taux',
            'dist': 'uniform',
            'params': {'min': 0.03, 'max': 0.07},
            'per': 'scenario'
        },
        {
            'name': 'capital',
            'init': 1000.0,
            'formula': 'capital[t-1] * (1 + taux)'
        }
    ]
}

# Run the simulation
result = bsce.simulate(spec)

# Analyze results
print(f"Mean final capital: {result['last_mean']['capital']}")
print(f"Median: {result['statistics']['capital']['median']}")
print(f"P5: {result['statistics']['capital']['percentiles']['5']}")
print(f"P95: {result['statistics']['capital']['percentiles']['95']}")

Batch Mode (Multiple Entities)

# SP Model template
template = {
    'scenarios': 1,
    'steps': '65 - batch_params.age',  # Dynamic steps
    'variables': [
        {
            'name': 'age_actuel',
            'init': 'batch_params.age'
        },
        {
            'name': 'salaire',
            'init': 'batch_params.salary',
            'formula': 'salaire[t-1] * 1.03'  # 3% annual increase
        },
        {
            'name': 'capital_retraite',
            'init': 0.0,
            'formula': 'capital_retraite[t-1] * 1.05 + salaire[t] * 0.10'
        }
    ]
}

# Entity data
batch_params = [
    {'entity_id': 'emp_001', 'age': 45, 'salary': 60000},
    {'entity_id': 'emp_002', 'age': 50, 'salary': 80000},
    {'entity_id': 'emp_003', 'age': 35, 'salary': 50000}
]

# Global aggregations (optional)
aggregations = [
    {
        'name': 'capital_total',
        'formula': 'sum(capital_retraite[t_final])'
    },
    {
        'name': 'moyenne_capital',
        'formula': 'mean(capital_retraite[t_final])'
    }
]

# Run batch
result = bsce.project_batch(
    template=template,
    batch_params=batch_params,
    aggregations=aggregations
)

# Analyze results
for entity in result['entities']:
    print(f"{entity['_entity_id']}: Capital = {entity['final_values']['capital_retraite']}")

print(f"Total capital: {result['aggregations']['capital_total']}")
print(f"Average: {result['aggregations']['moyenne_capital']}")

Validation

# Validate an SP Model before execution
validation = bsce.validate(spec)

if validation['is_valid']:
    print("✅ SP Model is valid")
    if validation.get('warnings'):
        print(f"⚠️  Warnings: {validation['warnings']}")
else:
    print(f"❌ Errors: {validation['errors']}")

Utilities

# Get examples
examples = bsce.get_examples()
print(f"Available examples: {len(examples['examples'])}")

# Check usage
usage = bsce.get_usage()
print(f"Simulations used: {usage['usage']['simulations_used']}/{usage['usage']['simulations_limit']}")

# Get plans
plans = bsce.get_plans()
for plan in plans['plans']:
    print(f"{plan['name']}: ${plan['price_monthly']}/month")

Error Handling

from subspacecomputing import (
    BSCE,
    QuotaExceededError,
    RateLimitError,
    AuthenticationError,
    ValidationError,
    BSCEError
)

try:
    result = bsce.simulate(spec)
except QuotaExceededError as e:
    print(f"Monthly quota exceeded: {e}")
except RateLimitError as e:
    print(f"Rate limit exceeded: {e}")
    print(f"Retry after: {e.response.headers.get('Retry-After')} seconds")
except AuthenticationError as e:
    print(f"Invalid API key: {e}")
except ValidationError as e:
    print(f"Validation error: {e.detail}")
except BSCEError as e:
    print(f"API error: {e}")

Rate Limit and Quota Information

After making a request, you can check your rate limit and quota status:

# Make a request
result = bsce.project(spec)

# Check rate limit info
rate_limit = bsce.get_rate_limit_info()
if rate_limit:
    print(f"Rate limit: {rate_limit['remaining']}/{rate_limit['limit']} remaining")

# Check quota info
quota = bsce.get_quota_info()
if quota:
    print(f"Quota: {quota['used']}/{quota['limit']} used, {quota['remaining']} remaining")

Documentation

Check out the full documentation at https://www.subspacecomputing.com/developer

API reference is available at https://api.subspacecomputing.com/docs

For support, reach out to contact@beausoft.ca

License

MIT License. Check the LICENSE file for details.

Copyright

© 2025 Beausoft Inc. All Rights Reserved

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

subspacecomputing-0.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

subspacecomputing-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for subspacecomputing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8262a39f8b0da13a2921cbb784b2dcbf7e7b3ea65a56eb0e36cf51642adda0d7
MD5 4e2a8039015fa6dbbd2b42350fbc184b
BLAKE2b-256 c4bda3b7e7587a9bee173ecaf5696776eb0540b1444e8a7bc181ffb8a7e763f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subspacecomputing-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2483725fc6aa9dbdab1b334026382c50b3cdaa882337536c6f92cbc2f4debc8d
MD5 f470e9895d6955fac751267c169a4422
BLAKE2b-256 3e7b54d638c47cd308288ab4f7a0b89288731458650a9c339ee52042edb815bf

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