SDK
Piora provides official SDKs that let you easily integrate the Piora API into your applications without dealing with raw HTTP requests.
Official SDKs
Section titled “Official SDKs”Node.js / TypeScript
Section titled “Node.js / TypeScript”npm install @piora/sdkimport { PioraClient } from '@piora/sdk';
const piora = new PioraClient({ token: process.env.PIORA_API_TOKEN,});
// List all serversconst servers = await piora.servers.list();
// Get application detailsconst app = await piora.applications.get('app_xxxxxxxxxxxx');
// Trigger a deploymentconst deployment = await piora.applications.deploy('app_xxxxxxxxxxxx', { branch: 'main',});Python
Section titled “Python”pip install piora-sdkfrom piora import PioraClient
piora = PioraClient(token=os.environ['PIORA_API_TOKEN'])
# List all serversservers = piora.servers.list()
# Get application detailsapp = piora.applications.get('app_xxxxxxxxxxxx')
# Trigger a deploymentdeployment = piora.applications.deploy('app_xxxxxxxxxxxx', branch='main')SDK Features
Section titled “SDK Features”All official SDKs provide the following features:
| Feature | Description |
|---|---|
| Full API coverage | Supports all Piora API endpoints |
| Type safety | Complete TypeScript type definitions |
| Auto retry | Automatic retry on transient errors |
| Pagination helpers | Automatic handling of paginated queries |
| Error handling | Structured error classes |
Usage Examples
Section titled “Usage Examples”Managing Servers
Section titled “Managing Servers”// List all serversconst servers = await piora.servers.list();for (const server of servers) { console.log(`${server.name}: ${server.status}`);}
// Get server statsconst stats = await piora.servers.stats('srv_xxxxxxxxxxxx');console.log(`CPU: ${stats.cpu}%, Memory: ${stats.memory}%`);Managing Applications
Section titled “Managing Applications”// Create an applicationconst app = await piora.applications.create({ name: 'my-new-app', serverId: 'srv_xxxxxxxxxxxx', source: { type: 'git', repository: 'https://github.com/user/repo', branch: 'main', },});
// Set environment variablesawait piora.applications.setEnv('app_xxxxxxxxxxxx', { NODE_ENV: 'production', DATABASE_URL: 'postgresql://...',});
// Deployconst deployment = await piora.applications.deploy('app_xxxxxxxxxxxx');
// Wait for deployment to completeawait deployment.waitUntilComplete();console.log('Deployment successful!');Managing Databases
Section titled “Managing Databases”// Create a PostgreSQL databaseconst db = await piora.databases.create({ type: 'postgresql', version: '16', name: 'my-database', serverId: 'srv_xxxxxxxxxxxx',});
// Get connection infoconst connectionInfo = await piora.databases.connectionInfo(db.id);console.log(connectionInfo.url);Handling Webhook Events
Section titled “Handling Webhook Events”import { PioraWebhookHandler } from '@piora/sdk';
const handler = new PioraWebhookHandler({ secret: process.env.PIORA_WEBHOOK_SECRET,});
// Express.js integrationapp.post('/webhook', handler.express((event) => { switch (event.type) { case 'deployment.succeeded': console.log(`Deploy succeeded: ${event.data.application.name}`); break; case 'deployment.failed': console.log(`Deploy failed: ${event.data.application.name}`); // Send alert notification break; }}));Error Handling
Section titled “Error Handling”SDKs provide structured error classes:
import { PioraError, AuthenticationError, NotFoundError } from '@piora/sdk';
try { const app = await piora.applications.get('invalid-id');} catch (error) { if (error instanceof AuthenticationError) { console.error('Token is invalid or expired'); } else if (error instanceof NotFoundError) { console.error('Application not found'); } else if (error instanceof PioraError) { console.error(`API error: ${error.code} - ${error.message}`); }}Pagination
Section titled “Pagination”// Manual paginationconst page1 = await piora.applications.list({ page: 1, perPage: 20 });const page2 = await piora.applications.list({ page: 2, perPage: 20 });
// Auto-iterate through all pagesfor await (const app of piora.applications.listAll()) { console.log(app.name);}Community SDKs
Section titled “Community SDKs”In addition to official SDKs, the community maintains SDKs for other languages:
| Language | Package | Maintainer |
|---|---|---|
| Go | piora-go | Community |
| Ruby | piora-ruby | Community |
| PHP | piora/sdk-php | Community |