Skip to main content

OpenGPU SDK for distributed AI task deployment

Project description

OpenGPU Python SDK

Python SDK for the OpenGPU Network distributed AI compute marketplace.

pip install ogpu

Overview

The SDK has two sides:

  • ogpu.chainChainConfig, ChainId, nonce utilities, ABI loader (re-exported at top level: from ogpu import ChainConfig)
  • ogpu.client / ogpu.protocol — interact with the blockchain: publish sources and tasks, manage vault staking, monitor events
  • ogpu.service — framework for source developers to expose task handlers inside Docker containers

Quick Start

Publish a Task

import time
from web3 import Web3
from ogpu import ChainConfig, ChainId
from ogpu.client import TaskInfo, TaskInput, publish_task

ChainConfig.set_chain(ChainId.OGPU_TESTNET)

task = publish_task(TaskInfo(
    source="0xYOUR_SOURCE_ADDRESS",
    config=TaskInput(function_name="predict", data={"prompt": "hello"}),
    expiryTime=int(time.time()) + 3600,
    payment=Web3.to_wei(0.01, "ether"),
))

print(task.address)             # contract address
print(task.get_status())        # TaskStatus.NEW
print(task.get_source().address)  # navigate to the source

Instance Classes

Every on-chain entity has a live proxy class. Methods hit the chain on every call — no stale cache.

from ogpu.protocol import Source, Task, Response, Provider, Master

task = Task.load("0xTASK_ADDRESS")   # validates existence on-chain
task.get_status()                     # TaskStatus
task.get_attempters()                 # list[str]
task.get_confirmed_response()         # Response | None (chain-only)
task.cancel(signer=my_key)            # Receipt

snap = task.snapshot()                # frozen capture of all fields
print(snap.status, snap.payment, snap.attempt_count)

Vault Operations

from ogpu.protocol import vault

vault.deposit("0xBENEFICIARY", amount=10**18, signer=my_key)
vault.lock(amount=5 * 10**17, signer=my_key)
vault.get_balance_of("0xADDRESS")    # int (wei)
vault.is_eligible("0xADDRESS")       # bool

Event Watching (Async)

import asyncio
from ogpu.events import watch_attempted

async def monitor(task_addr: str):
    async for event in watch_attempted(task_addr):
        print(f"Attempt from {event.provider} @ block {event.block_number}")

asyncio.run(monitor("0xTASK_ADDRESS"))

Custom RPC

from ogpu import ChainConfig

ChainConfig.set_rpc("https://my-private-node.example")
ChainConfig.get_rpc()     # current URL
ChainConfig.reset_rpc()   # restore default

Architecture

ogpu/
  chain/        # ChainConfig, ChainId, Web3Manager, nonce, ABI files
  types/        # enums, errors, Receipt, metadata
  protocol/     # low-level 1:1 contract wrappers
    nexus, controller, terminal, vault
    Source, Task, Response, Provider, Master
  client/       # high-level client workflows
  events/       # async event watchers (the one async island)
  service/      # source developer framework (separate concern)

Protocol layer — every Solidity view has a Python accessor, every state-changing function has a writer. Signer management via per-call signer= parameter with role-based env-var fallback (CLIENT_PRIVATE_KEY, PROVIDER_PRIVATE_KEY, MASTER_PRIVATE_KEY).

Instance classesSource(addr), Task(addr), Response(addr), Provider(addr), Master(addr). Stateless — only self.address is stored. Task.load(addr) validates existence eagerly.

Events — async generators in ogpu.events. HTTP filter polling, not WebSocket. Rest of SDK is sync.

Requirements

  • Python >= 3.10
  • web3 >= 7.0

Documentation

Full docs: https://opengpu-network.github.io/sdk-ogpu-py/

Writing a Task Handler (ogpu.service)

import ogpu.service
from pydantic import BaseModel

class MultiplyInput(BaseModel):
    a: int
    b: int

class MultiplyOutput(BaseModel):
    result: int

@ogpu.service.expose()
def multiply(data: MultiplyInput) -> MultiplyOutput:
    return MultiplyOutput(result=data.a * data.b)

ogpu.service.start()

License

License: MIT

Released under the MIT License — Copyright © 2026 OpenGPU Network.

You're free to use, modify, distribute, and embed ogpu-py in commercial or open-source projects. The only requirement is that the copyright notice and license text travel with the source.

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

ogpu-0.2.2.tar.gz (86.3 kB view details)

Uploaded Source

Built Distribution

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

ogpu-0.2.2-py3-none-any.whl (113.4 kB view details)

Uploaded Python 3

File details

Details for the file ogpu-0.2.2.tar.gz.

File metadata

  • Download URL: ogpu-0.2.2.tar.gz
  • Upload date:
  • Size: 86.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ogpu-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d246e98549a42971dd6797a34a3ad37ac5effbd888b2ca0e58ca16327a296303
MD5 b65254ac95fc2e2a646d5ca69045de34
BLAKE2b-256 44714186e1ae79413764cefe165e34d890185a6b0e3c16004627f8f046a17933

See more details on using hashes here.

File details

Details for the file ogpu-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ogpu-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 113.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for ogpu-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 666df6189837c8568afe6cc5536acaf589d606e2e7955ac4f5192f30ce434b52
MD5 0bb448066c7e9d4bbbfb555fa1b6b93b
BLAKE2b-256 eb39ffa9649da563e335b8d98d093f1089b5c4f895f4372b47d527cca473d6db

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