FastAPI Integration
from fastapi import FastAPI
from blackswan import BlackSwanClient
client = BlackSwanClient(
network="amoy",
rpc_url="https://polygon-amoy.g.alchemy.com/v2/your-api-key"
)
app = FastAPI()
@app.get("/credit/{wallet}")
async def get_credit(wallet: str):
dashboard = client.get_credit_dashboard(wallet)
return {
"trust_ratio": dashboard.trust_ratio,
"tier": dashboard.trust_tier,
"apr": dashboard.current_apr / 1000
}
Flask Integration
from flask import Flask, jsonify
from blackswan import BlackSwanClient
client = BlackSwanClient(
network="amoy",
rpc_url="https://polygon-amoy.g.alchemy.com/v2/your-api-key"
)
app = Flask(__name__)
@app.route("/credit/<wallet>")
def get_credit(wallet):
dashboard = client.get_credit_dashboard(wallet)
return jsonify({
"trust_ratio": dashboard.trust_ratio,
"tier": dashboard.trust_tier,
"apr": dashboard.current_apr / 1000
})
Script Usage
from blackswan import BlackSwanClient
client = BlackSwanClient(
network="amoy",
rpc_url="https://polygon-amoy.g.alchemy.com/v2/your-api-key"
)
wallet = "0x..."
dashboard = client.get_credit_dashboard(wallet)
print(f"Trust: {dashboard.trust_ratio} ({dashboard.trust_tier})")
print(f"APR: {dashboard.current_apr / 1000}%")
print(f"Loans: {dashboard.successful_loans} successful, {dashboard.defaults} defaults")