Skip to main content
Integrate px0 into your Python application. This guide shows how to fetch and render a prompt template programmatically.

Prerequisites

Before running the SDK, ensure you have completed the following steps:

Configuration

The Python SDK requires connection details and authentication to communicate with your px0 instance. Configure these details using environment variables.
  • PX0_HOST: The URL of your px0 API instance.
  • PX0_ACCESS_TOKEN: Your API access key.
Set these variables in your shell before running the applications:
export PX0_HOST="http://localhost:8000"
export PX0_ACCESS_TOKEN="your_access_key_here"

Installation

Install the required client library for Python.
pip install px0

Hello World Example

The following example demonstrates how to load the client, authenticate, and render a live prompt template named hello_world with a dynamic name variable.
import os
import px0

host = os.getenv("PX0_HOST")
access_token = os.getenv("PX0_ACCESS_TOKEN")

config = px0.Configuration(
    host=host,
    access_token=access_token
)
api_client = px0.ApiClient(config)
renders_api = px0.PromptRendersApi(api_client)
response = renders_api.render_live(
    slug="hello_world",
    render_request=px0.RenderRequest(variables={"name": "World"})
)
print(response.rendered)

Execution

Execute the Python script:
python main.py