Files
aitbc/docs/development/4_examples.md
aitbc 19d415a235
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 3s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 2s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 2s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Deploy to Testnet / deploy-testnet (push) Successful in 1m12s
Documentation Validation / validate-docs (push) Failing after 8s
Documentation Validation / validate-policies-strict (push) Successful in 3s
Integration Tests / test-service-integration (push) Successful in 2m6s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 4s
P2P Network Verification / p2p-verification (push) Successful in 4s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 32s
Package Tests / Python package - aitbc-core (push) Successful in 14s
Package Tests / Python package - aitbc-crypto (push) Successful in 12s
Package Tests / Python package - aitbc-sdk (push) Successful in 9s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 17s
Python Tests / test-python (push) Successful in 15s
Security Scanning / security-scan (push) Successful in 27s
Node Failover Simulation / failover-test (push) Successful in 7s
Multi-Node Stress Testing / stress-test (push) Successful in 6s
Cross-Node Transaction Testing / transaction-test (push) Successful in 4s
feat: add SQLCipher database encryption support and consolidate agent documentation
- Add SQLCipher encryption for ait-mainnet database with configurable flag
- Add db_encryption_enabled and db_encryption_key_path config settings
- Implement encryption key loading and PRAGMA key setup via connection events
- Add shutdown_db function for proper database cleanup
- Export middleware classes in aitbc/__init__.py
- Fix import path in sync.py for settings
- Remove duplicate agent documentation from docs
2026-05-03 12:00:38 +02:00

2.9 KiB

title, description
title description
Code Examples Practical examples for building on AITBC

Code Examples

This section provides practical examples for common tasks on the AITBC platform.

Python Examples

Basic Job Submission

from aitbc import AITBCClient

client = AITBCClient(api_key="your_key")

job = client.jobs.create({
    "name": "image-classification",
    "type": "ai-inference",
    "model": {
        "type": "python",
        "entrypoint": "model.py",
        "requirements": ["torch", "pillow"]
    }
})

result = client.jobs.wait_for_completion(job["job_id"])

Batch Job Processing

import asyncio
from aitbc import AsyncAITBCClient

async def process_images(image_paths):
    client = AsyncAITBCClient(api_key="your_key")
    
    tasks = []
    for path in image_paths:
        job = await client.jobs.create({
            "name": f"process-{path}",
            "type": "image-analysis"
        })
        tasks.append(client.jobs.wait_for_completion(job["job_id"]))
    
    results = await asyncio.gather(*tasks)
    return results

JavaScript Examples

React Component

import React, { useState, useEffect } from 'react';
import { AITBCClient } from '@aitbc/client';

function JobList() {
    const [jobs, setJobs] = useState([]);
    const client = new AITBCClient({ apiKey: 'your_key' });
    
    useEffect(() => {
        async function fetchJobs() {
            const jobList = await client.jobs.list();
            setJobs(jobList);
        }
        fetchJobs();
    }, []);
    
    return (
        <div>
            {jobs.map(job => (
                <div key={job.jobId}>
                    <h3>{job.name}</h3>
                    <p>Status: {job.status}</p>
                </div>
            ))}
        </div>
    );
}

WebSocket Integration

const client = new AITBCClient({ apiKey: 'your_key' });
const ws = client.websocket.connect();

ws.on('jobUpdate', (data) => {
    console.log(`Job ${data.jobId} updated to ${data.status}`);
});

ws.subscribe('jobs');
ws.start();

CLI Examples

Job Management

# Create job from file
aitbc job create job.yaml

# List all jobs
aitbc job list --status running

# Monitor job progress
aitbc job watch <job_id>

# Download results
aitbc job download <job_id> --output ./results/

Marketplace Operations

# List available offers
aitbc marketplace list --type image-classification

# Create offer as miner
aitbc marketplace create-offer offer.yaml

# Accept offer
aitbc marketplace accept <offer_id> --job-id <job_id>

Complete Examples

Find full working examples in our GitHub repositories: