Skip to main content

Python SDK for the SGL Network confidential compute grid (end-to-end encrypted + streaming)

Project description

singularity-grid

Python SDK for the SGL Network confidential compute grid. Submit inference jobs to TEE-verified nodes, check grid capacity, and use the OpenAI-compatible chat completions endpoint -- all from a single package.

Installation

pip install singularity-grid

To use the OpenAI compatibility helper:

pip install singularity-grid[openai]

Quick start

1. OpenAI-compatible usage (simplest)

The SGL Network orchestrator exposes an OpenAI-compatible /v1/chat/completions endpoint. You can use the standard openai package with no wrapper:

from openai import OpenAI

client = OpenAI(
    base_url="https://grid.x402compute.cc/v1",
    api_key="scg_your_api_key",
)

response = client.chat.completions.create(
    model="gemma-4-26b",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

2. Helper function

If you prefer not to copy the URL, use the built-in helper:

from singularity_grid import create_openai_client

client = create_openai_client(api_key="scg_your_api_key")

response = client.chat.completions.create(
    model="gemma-4-26b",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

3. GridClient (full grid features)

For grid-specific features like job submission, TEE attestation, capacity checks, and pricing:

from singularity_grid import GridClient

# Public endpoints -- no auth required
grid = GridClient()
capacity = grid.capacity()
models = grid.models()
pricing = grid.pricing()

print(f"Active nodes: {capacity.active_nodes}/{capacity.total_nodes}")
for m in models:
    print(f"  {m.id} -- {m.sgl_node_count} nodes")

# Authenticated endpoints
grid = GridClient(api_key="scg_your_api_key")

job = grid.submit_job(
    model="gemma-4-26b",
    input_payload={
        "messages": [{"role": "user", "content": "Analyze this data"}]
    },
    submitter_wallet="0xYourWallet",
    submitter_chain="base",
)

print(f"Job {job.job_id}: {job.status}")

# Retrieve result and attestation
result = grid.get_job(job.job_id)
attestation = grid.get_attestation(job.job_id)
print(f"TEE verified: {attestation.verified}")

API reference

GridClient

Method Auth Description
capacity() No Grid-wide capacity summary
models() No Available models with pricing and TEE info
pricing() No Pricing table for all models
submit_job(model, input_payload, ...) Yes Submit a compute job
get_job(job_id) Yes Get job status and result
get_attestation(job_id) Yes Get TEE attestation proof

Exceptions

Exception When
SGLError Base class for all SDK errors
SGLAPIError Non-2xx response from the API
SGLAuthError 401 or 403 response
SGLNotFoundError 404 response
SGLConnectionError Orchestrator unreachable or timeout

Configuration

Parameter Default Description
api_key None Bearer token for authenticated endpoints
base_url orchestrator URL Override the orchestrator URL
timeout 60.0 Request timeout in seconds

License

MIT

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

singularity_grid-0.4.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

singularity_grid-0.4.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file singularity_grid-0.4.0.tar.gz.

File metadata

  • Download URL: singularity_grid-0.4.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for singularity_grid-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c8677823f83c5d6e8f95fc3976f00306004bccab7fac0f980ab2ca7a726f7fa5
MD5 11403838a55a095999f216f5dab839d1
BLAKE2b-256 0eeb51cbe2ec9d8c72172c2c78d4b57f011d9cac67fb88bedb0796ae8d79e78d

See more details on using hashes here.

Provenance

The following attestation bundles were made for singularity_grid-0.4.0.tar.gz:

Publisher: publish.yml on Singularity-Layer/sgl-network-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 singularity_grid-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for singularity_grid-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 337e8255b3cad7507cb4f31eb54b61bd1b32dcb85abf92318d0db0a601bc15b7
MD5 f848a7e4020f38d284a53a3e14265258
BLAKE2b-256 9734df759971fd0da00478cb9de9856ff391295d807d3fb90211787c2ea60935

See more details on using hashes here.

Provenance

The following attestation bundles were made for singularity_grid-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Singularity-Layer/sgl-network-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