Skip to Content
Client Basics

Last Updated: 4/8/2026


Client Basics

Learn how to use Pie client libraries to interact with the server.

Installation

Python

pip install pie-client

JavaScript

npm install @pie-project/client

Rust

cargo add pie-client

Basic Usage

Python Example

from pie_client import PieClient # Connect to server client = PieClient("http://localhost:8080") # Run an inferlet result = client.run( inferlet="std/text-completion", args={ "prompt": "Explain quantum computing:", "max_tokens": 100 } ) print(result.output)

JavaScript Example

import { PieClient } from '@pie-project/client'; const client = new PieClient('http://localhost:8080'); const result = await client.run({ inferlet: 'std/text-completion', args: { prompt: 'Explain quantum computing:', max_tokens: 100 } }); console.log(result.output);

Async Execution

Submit and Poll

# Submit job job_id = client.submit( inferlet="std/text-completion", args={"prompt": "Long task..."} ) # Poll for completion import time while True: result = client.get_result(job_id) if result.is_complete: print(result.output) break time.sleep(1)

Streaming Results

Python Streaming

for chunk in client.stream( inferlet="std/text-completion", args={"prompt": "Tell me a story"} ): print(chunk, end="", flush=True)

JavaScript Streaming

const stream = await client.stream({ inferlet: 'std/text-completion', args: { prompt: 'Tell me a story' } }); for await (const chunk of stream) { process.stdout.write(chunk); }

Custom Inferlets

Upload Inferlet

# Upload your custom inferlet client.upload_inferlet( name="my-inferlet", wasm_path="./my_inferlet.wasm" ) # Use it result = client.run( inferlet="my-inferlet", args={"input": "test"} )

Error Handling

Python

from pie_client import PieError try: result = client.run( inferlet="my-inferlet", args={"prompt": "test"} ) except PieError as e: print(f"Error: {e.message}") print(f"Code: {e.code}")

JavaScript

try { const result = await client.run({ inferlet: 'my-inferlet', args: { prompt: 'test' } }); } catch (error) { if (error instanceof PieError) { console.error('Error:', error.message); } }

Configuration

Timeouts

client = PieClient( "http://localhost:8080", timeout=60 # seconds )

Retries

client = PieClient( "http://localhost:8080", max_retries=3, retry_delay=1.0 )

Authentication

client = PieClient( "http://localhost:8080", api_key="your-api-key" )

Best Practices

  1. Reuse client instances - Create once, use many times
  2. Handle errors gracefully - Always wrap calls in try/catch
  3. Use streaming for long outputs - Better UX and memory usage
  4. Set appropriate timeouts - Match your use case
  5. Monitor job status - For long-running tasks

Next Steps