> ## Documentation Index
> Fetch the complete documentation index at: https://blackswan-23965643.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# BlackSwan Python SDK Integration Examples

> Practical BlackSwan Python SDK examples for FastAPI and Flask — fetch credit dashboards, trust ratios, and APR data in your own backend.

The examples below show how to integrate the BlackSwan Python SDK into common Python web frameworks, as well as a standalone script for quick testing.

## FastAPI Integration

```python theme={null}
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

```python theme={null}
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

```python theme={null}
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")
```
