Skip to main content

Python SDK for Pendra — UK-based, privacy-first LLM inference

Project description

pendra-python

Official Python SDK for Pendra — UK-based, privacy-first LLM inference.

Your data is processed in the UK, never stored, never shared with US cloud providers.

Installation

pip install pendra

Quick Start

import pendra

client = pendra.Pendra(
    api_key="pdr_sk_...",  # or set PENDRA_API_KEY env var
)

response = client.chat.completions.create(
    model="llama3.2",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is the capital of the UK?"},
    ],
)

print(response.choices[0].message.content)
# → London is the capital of the United Kingdom.

Streaming

with client.chat.completions.create(
    model="llama3.2",
    messages=[{"role": "user", "content": "Write me a short poem about London."}],
    stream=True,
) as stream:
    for chunk in stream:
        print(chunk.choices[0].delta.content or "", end="", flush=True)

Async

import asyncio
import pendra

async def main():
    async with pendra.AsyncPendra(api_key="pdr_sk_...") as client:
        # Non-streaming
        response = await client.chat.completions.create(
            model="llama3.2",
            messages=[{"role": "user", "content": "Hello!"}],
        )
        print(response.choices[0].message.content)

        # Streaming
        stream = await client.chat.completions.create(
            model="llama3.2",
            messages=[{"role": "user", "content": "Count to 5"}],
            stream=True,
        )
        async for chunk in stream:
            print(chunk.choices[0].delta.content or "", end="", flush=True)

asyncio.run(main())

List Models

models = client.models.list()
for model in models:
    print(model.id)

Image Generation

Generate images from a text prompt. Returns base64-encoded PNGs by default.

import base64

response = client.images.generations.create(
    model="x/z-image-turbo",
    prompt="A red London double-decker bus at sunset",
    size="1024x1024",
)

with open("bus.png", "wb") as f:
    f.write(base64.b64decode(response.data[0].b64_json))

Async usage mirrors the sync API:

async with pendra.AsyncPendra(api_key="pdr_sk_...") as client:
    response = await client.images.generations.create(
        model="x/z-image-turbo",
        prompt="A red London double-decker bus at sunset",
    )

Image generation is non-streaming — the response is returned as a single JSON payload once the worker finishes.

Environment Variables

Variable Description
PENDRA_API_KEY Your Pendra API key (pdr_sk_...)

OpenAI Compatibility

The Pendra SDK is fully compatible with the OpenAI Python SDK interface. To migrate:

# Before
from openai import OpenAI
client = OpenAI(api_key="sk-...")

# After
from pendra import Pendra
client = Pendra(api_key="pdr_sk_...")

The client.chat.completions.create() interface is identical.

Self-Hosted Workers

Run inference on your own GPUs with a single command. Your prompts and completions never leave your infrastructure.

curl -fsSL https://get.pendra.ai/worker | bash

See the Workers documentation for full setup instructions.

Licence

Apache-2.0

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

pendra-0.3.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

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

pendra-0.3.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pendra-0.3.0.tar.gz.

File metadata

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

File hashes

Hashes for pendra-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b02858db4bdf1a932c73d5d7fc6ddf12ef02880709c16cd5b6554741738172d5
MD5 18bf9d7b57b04fe49befec9acd49b5fd
BLAKE2b-256 818406102fe8c26af7ec984c1b638baee59590862430292a16974ba71af4a35a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pendra-0.3.0.tar.gz:

Publisher: publish-sdk-python.yml on Pendra-Cloud/pendra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pendra-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pendra-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pendra-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e7653f1c08696aec71977bc4a8370a06a7b3fb24857d26f21103b0b0bedda23a
MD5 1f141e80050a657168dad82a625c96d8
BLAKE2b-256 ba47bf27d6c3bb749015a3d6d4daf34f4d533cebfd48786e3312e20c8415f824

See more details on using hashes here.

Provenance

The following attestation bundles were made for pendra-0.3.0-py3-none-any.whl:

Publisher: publish-sdk-python.yml on Pendra-Cloud/pendra

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