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.3.tar.gz (89.5 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.3-py3-none-any.whl (116.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ogpu-0.2.3.tar.gz
  • Upload date:
  • Size: 89.5 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.3.tar.gz
Algorithm Hash digest
SHA256 5b94361871e2ddb70670d7a0fc0b9405022be073aab84b44b9a4f1d8ee46b4bf
MD5 08779b97ce6f5f772caaad8742b175eb
BLAKE2b-256 22f09930c1a642bb41dec0adaf1c6f3ee89d36ee58eddc2006dd67526d44c828

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ogpu-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 116.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c7f80e5b05c8fda06c285a782b18f8a6865bca129f0b9a9204f7a3a86fe3f46d
MD5 5434db1fb4b2efce49a689a20f44c9a0
BLAKE2b-256 7fb8d8e4020413f955478e9c9bdafdd14c07efa65fe1a338d6b5e277f672ccc0

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