Skip to main content

Pie Client

Project description

Pie Python Client

A Python client for interacting with the Pie server.

Installation

pip install -e .

Quick Start

import asyncio
from pie import PieClient, ParsedPrivateKey

async def main():
    async with PieClient("ws://127.0.0.1:8080") as client:
        # Authentication is always required.
        # If server auth is enabled, provide a valid private key:
        key = ParsedPrivateKey.from_file("~/.ssh/id_ed25519")
        await client.authenticate("username", key)
        
        # If server auth is disabled, any username works without a key:
        # await client.authenticate("any_username")
        
        # Upload and launch a program
        with open("my_program.wasm", "rb") as f:
            await client.upload_program(f.read())
        
        program_hash = "..."  # blake3 hash of the wasm binary
        instance = await client.launch_instance(program_hash)
        
        # Interact with the instance
        await instance.send("hello")
        event, message = await instance.recv()
        print(f"Received: {event.name} - {message}")

asyncio.run(main())

API Reference

PieClient

Method Description
authenticate(username, private_key) Public key authentication (challenge-response)
internal_authenticate(token) Token-based internal authentication
upload_program(bytes) Upload a WASM program
program_exists(hash) Check if program is uploaded
launch_instance(hash, args, detached) Launch a program instance
attach_instance(instance_id) Attach to a detached instance
list_instances() List running instances
terminate_instance(instance_id) Terminate an instance
ping() Check server connectivity
query(subject, record) Generic server query

Instance

Method Description
send(message) Send a string to the instance
upload_blob(bytes) Upload binary data
recv() Receive next event (returns (Event, data))
terminate() Request termination

Event Types

Event Description
Message Text message from instance
Completed Instance finished successfully
Aborted Instance was aborted
Exception Instance raised an exception
ServerError Server-side error
OutOfResources Resource limit reached
Blob Binary data received
Stdout Streaming stdout output
Stderr Streaming stderr output

ParsedPrivateKey

Supports RSA (≥2048 bits), ED25519, and ECDSA (P-256, P-384) keys.

# From file
key = ParsedPrivateKey.from_file("~/.ssh/id_ed25519")

# From string
key = ParsedPrivateKey.parse(key_content)

Example

See main.py for a complete usage example.

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

pie_client-0.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

pie_client-0.2.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pie_client-0.2.0.tar.gz.

File metadata

  • Download URL: pie_client-0.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pie_client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d88d1f992cb8250208236f0a5322cae5d2faebb236166bc2522b539949bee29b
MD5 39ea40065e3501785ab0db15a1ee7afa
BLAKE2b-256 94657b0c93c44004248f2f8cdf14168755961736ca959a1a8f5a1ee35b1c22df

See more details on using hashes here.

File details

Details for the file pie_client-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pie_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for pie_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d52f2b2e5665bbb5550ac6205c87e37bf1f990f99f70bf37dabb4a040932c23
MD5 b4392eb17620b2bf0c5a4dc8a295e082
BLAKE2b-256 78a7f1a2e7ff99bde9645e9a388b9005c6aa6957b9db89d23cc2654c50418087

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