Xenfra Python SDK
The official, open-source Python SDK for interacting with the Xenfra API.
This SDK provides a simple and Pythonic interface for developers and AI Agents to programmatically manage infrastructure, deployments, and other platform resources.
Installation
pip install xenfra-sdk
Basic Usage
Initialize the client with your API token (or ensure the XENFRA_TOKEN environment variable is set).
import os
from xenfra_sdk import XenfraClient
from xenfra_sdk.exceptions import XenfraAPIError
client = XenfraClient(token=os.getenv("XENFRA_TOKEN"))
try:
projects = client.projects.list()
for p in projects:
print(f"Found project: {p.name} (Status: {p.status})")
except XenfraAPIError as e:
print(f"API Error: {e.detail}")
Usage for Agentic Workflows
The Xenfra SDK is designed to be used as a "tool" by AI Agents (e.g., OpenAI Assistants). The Pydantic models are compatible with function-calling schemas, allowing an agent to easily call these methods.
Here is a conceptual example of how an agent might use the SDK to fulfill a user's request.
# This is a conceptual representation of an agent's internal logic.
# The agent would be configured with functions that call these SDK methods.
def list_all_projects():
"""Lists all available projects in the Xenfra account."""
return client.projects.list()
def create_new_deployment(project_name: str, git_repo: str, branch: str = "main"):
"""
Creates a new deployment for a project.
Args:
project_name: The name for the new deployment.
git_repo: The URL of the git repository to deploy.
branch: The branch to deploy (defaults to 'main').
"""
return client.deployments.create(
project_name=project_name,
git_repo=git_repo,
branch=branch,
framework="fastapi" # Framework detection would be part of a more complex agent
)
# --- Agent Execution Flow ---
# User prompt: "Deploy my new app from github.com/user/my-app"
# 1. Agent decides which tool to use: `create_new_deployment`
# 2. Agent extracts parameters:
# - project_name = "my-app" (inferred)
# - git_repo = "https://github.com/user/my-app"
# 3. Agent calls the tool:
# create_new_deployment(
# project_name="my-app",
# git_repo="https://github.com/user/my-app"
# )
Error Handling
The SDK uses custom exceptions for clear error handling. All API-related errors will raise a XenfraAPIError, which contains the status_code and a detail message from the API response.
from xenfra_sdk.exceptions import XenfraAPIError, AuthenticationError
try:
# Make an API call
...
except AuthenticationError as e:
print("Authentication failed. Please check your token.")
except XenfraAPIError as e:
print(f"An API error occurred with status {e.status_code}: {e.detail}")
Metadata
Release files for xenfra-sdk 0.2.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| xenfra_sdk-0.2.9.tar.gz | 94.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| xenfra_sdk-0.2.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 209.0 kB
Release files / xenfra_sdk-0.2.9.tar.gz
| Download URL | xenfra_sdk-0.2.9.tar.gz |
|---|---|
| Size | 94.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca7f41373d391f0ad5603f7eb96a09da387cc3f1ab1509af3e793434c2e49ac4
|
|
BLAKE2b-256 checksum How to use checksums |
295132fdf2fb8d6a8d0ef0b04a551a3f37ae9b3956819967c16047d4c82dd1ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / xenfra_sdk-0.2.9-py3-none-any.whl
| Download URL | xenfra_sdk-0.2.9-py3-none-any.whl |
|---|---|
| Size | 114.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3ae07b943dadb60b31e6243970294952d68baa6d01757089286bd1784ace5644
|
|
BLAKE2b-256 checksum How to use checksums |
f4279ea02fdece7b2fde90007d2b4eb72c6f463f0ce4818a8acf212d1711f858
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|