Skip to main content

Overview

The Devdraft Python SDK provides a complete client library for integrating payment processing, customer management, and webhook functionality into your Python applications.

Pythonic API

Follows Python conventions with snake_case naming and type hints

Context Manager Support

Clean resource management with Python’s with statement

Comprehensive

Access to all Devdraft API endpoints and features

Easy Integration

Simple configuration and intuitive method names

Installation

pip install devdraft

Requirements

  • Python 3.9 or higher

Quick Start

import devdraft
import os

# Configure the SDK
configuration = devdraft.Configuration(
    host="https://api.devdraft.ai"
)

configuration.api_key['x-client-key'] = os.environ.get('DEVDRAFT_CLIENT_KEY')
configuration.api_key['x-client-secret'] = os.environ.get('DEVDRAFT_CLIENT_SECRET')

# Use context manager for automatic resource cleanup
with devdraft.ApiClient(configuration) as api_client:
    # Initialize API instances
    transfers_api = devdraft.TransfersApi(api_client)
    webhooks_api = devdraft.WebhooksApi(api_client)
    
    # Use the APIs
    transfer = transfers_api.transfer_controller_create_direct_wallet_transfer(
        devdraft.CreateDirectWalletTransferDto(
            wallet_id='your-wallet-id',
            network='solana',
            stable_coin_currency='usdc',
            amount=100.00
        )
    )

API Classes

The SDK is organized into API classes, each handling a specific domain:
API ClassDescription
APIHealthApiService health checks and status monitoring
AppBalancesApiQuery application balances across stablecoins
CustomersApiCustomer management and KYC operations
ExchangeRatesApiReal-time currency exchange rates
InvoicesApiInvoice creation and management
LiquidationAddressesApiCryptocurrency liquidation addresses
PaymentIntentsApiPayment intent creation for bank and stablecoin
PaymentLinksApiGenerate and manage payment links
ProductsApiProduct catalog management
TaxesApiTax configuration and management
TestPaymentsApiTest payment processing in sandbox
TransfersApiInitiate and manage fund transfers
WalletsApiWallet management and balances
WebhooksApiWebhook configuration and management

API Health

Monitor service health and availability.

Methods

health_controller_check_v0()

Authenticated health check endpoint requiring API credentials.
import devdraft

with devdraft.ApiClient(configuration) as api_client:
    health_api = devdraft.APIHealthApi(api_client)
    
    try:
        health_api.health_controller_check_v0()
        print('Service is healthy and authenticated')
    except devdraft.ApiException as e:
        print(f'Health check failed: {e}')
Returns: None

health_controller_public_health_check_v0()

Public health check endpoint (no authentication required).
status = health_api.health_controller_public_health_check_v0()
print(f'Service status: {status}')
Returns: PublicHealthResponseDto

App Balances

Query your application’s stablecoin balances.

Methods

balance_controller_get_all_balances()

Get all stablecoin balances for your application.
import devdraft

with devdraft.ApiClient(configuration) as api_client:
    balances_api = devdraft.AppBalancesApi(api_client)
    
    balances = balances_api.balance_controller_get_all_balances()
    print(f'USDC Balance: {balances.usdc}')
    print(f'EURC Balance: {balances.eurc}')
Returns: AllBalancesResponse

balance_controller_get_usdc_balance()

Get USDC balance only.
usdc_balance = balances_api.balance_controller_get_usdc_balance()
print(f'USDC: {usdc_balance.amount}')
Returns: AggregatedBalanceResponse

balance_controller_get_eurc_balance()

Get EURC balance only.
eurc_balance = balances_api.balance_controller_get_eurc_balance()
print(f'EURC: {eurc_balance.amount}')
Returns: AggregatedBalanceResponse

Customers

Manage customer records and KYC information.

Methods

customer_controller_create(create_customer_dto)

Create a new customer.
import devdraft
from devdraft.model.create_customer_dto import CreateCustomerDto

with devdraft.ApiClient(configuration) as api_client:
    customers_api = devdraft.CustomersApi(api_client)
    
    new_customer = customers_api.customer_controller_create(
        CreateCustomerDto(
            first_name='John',
            last_name='Doe',
            email='john.doe@example.com',
            type='INDIVIDUAL',
            country='US'
        )
    )
    
    print(f'Customer created: {new_customer.id}')
Parameters:
  • create_customer_dto: CreateCustomerDto - Customer details
Returns: Customer

customer_controller_find_all(**kwargs)

Get all customers with optional filters.
customers = customers_api.customer_controller_find_all(
    page=1,
    limit=20,
    status='ACTIVE'
)

for customer in customers:
    print(f'{customer.first_name} {customer.last_name} - {customer.email}')
Parameters:
  • page: int - Page number (optional, default: 1)
  • limit: int - Items per page (optional, default: 20)
  • status: str - Filter by status (optional)
Returns: List[Customer]

customer_controller_find_one(id)

Get a customer by ID.
customer = customers_api.customer_controller_find_one(id='customer-id-here')
print(f'Customer: {customer.first_name} {customer.last_name}')
Parameters:
  • id: str - Customer ID
Returns: Customer

customer_controller_update(id, update_customer_dto)

Update a customer’s information.
from devdraft.model.update_customer_dto import UpdateCustomerDto

updated = customers_api.customer_controller_update(
    id='customer-id-here',
    update_customer_dto=UpdateCustomerDto(
        phone='+1234567890',
        address='123 Main St'
    )
)

print(f'Customer updated: {updated.id}')
Parameters:
  • id: str - Customer ID
  • update_customer_dto: UpdateCustomerDto - Fields to update
Returns: Customer

Exchange Rates

Get real-time currency exchange rates.

Methods

exchange_rate_controller_get_exchange_rate(**kwargs)

Get exchange rate between any two supported currencies.
import devdraft

with devdraft.ApiClient(configuration) as api_client:
    rates_api = devdraft.ExchangeRatesApi(api_client)
    
    rate = rates_api.exchange_rate_controller_get_exchange_rate(
        var_from='USD',
        to='EUR'
    )
    
    print(f'1 USD = {rate.rate} EUR')
    print(f'Rate expires at: {rate.expires_at}')
Parameters:
  • var_from: str - Source currency code
  • to: str - Target currency code
Returns: ExchangeRateResponseDto

exchange_rate_controller_get_usdto_eur_rate()

Get USD to EUR exchange rate.
usd_to_eur = rates_api.exchange_rate_controller_get_usdto_eur_rate()
print(f'USD to EUR: {usd_to_eur.rate}')
Returns: ExchangeRateResponseDto

exchange_rate_controller_get_eurto_usd_rate()

Get EUR to USD exchange rate.
eur_to_usd = rates_api.exchange_rate_controller_get_eurto_usd_rate()
print(f'EUR to USD: {eur_to_usd.rate}')
Returns: ExchangeRateResponseDto

Invoices

Create and manage invoices for your customers.

Methods

invoice_controller_create(create_invoice_dto)

Create a new invoice.
import devdraft
from devdraft.model.create_invoice_dto import CreateInvoiceDto

with devdraft.ApiClient(configuration) as api_client:
    invoices_api = devdraft.InvoicesApi(api_client)
    
    invoice = invoices_api.invoice_controller_create(
        CreateInvoiceDto(
            customer_id='customer-id',
            items=[
                {
                    'description': 'Premium Subscription',
                    'quantity': 1,
                    'price': 99.99,
                    'currency': 'USD'
                }
            ],
            due_date='2024-12-31'
        )
    )
    
    print(f'Invoice created: {invoice.id}')
    print(f'Total: {invoice.total}')
Parameters:
  • create_invoice_dto: CreateInvoiceDto - Invoice details
Returns: Invoice

invoice_controller_find_all(**kwargs)

Get all invoices.
invoices = invoices_api.invoice_controller_find_all(
    page=1,
    limit=50,
    status='UNPAID'
)
Parameters:
  • page: int - Page number (optional)
  • limit: int - Items per page (optional)
  • status: str - Filter by status (optional)
Returns: List[Invoice]

invoice_controller_find_one(id)

Get an invoice by ID.
invoice = invoices_api.invoice_controller_find_one(id='invoice-id')
Parameters:
  • id: str - Invoice ID
Returns: Invoice

invoice_controller_update(id, update_invoice_dto)

Update an invoice.
from datetime import datetime

updated = invoices_api.invoice_controller_update(
    id='invoice-id',
    update_invoice_dto={
        'status': 'PAID',
        'paid_at': datetime.now().isoformat()
    }
)
Parameters:
  • id: str - Invoice ID
  • update_invoice_dto: dict - Fields to update
Returns: Invoice

Liquidation Addresses

Manage cryptocurrency liquidation addresses for customers.

Methods

liquidation_address_controller_create_liquidation_address(customer_id, create_liquidation_address_dto)

Create a new liquidation address for a customer.
import devdraft
from devdraft.model.create_liquidation_address_dto import CreateLiquidationAddressDto

with devdraft.ApiClient(configuration) as api_client:
    liquidation_api = devdraft.LiquidationAddressesApi(api_client)
    
    address = liquidation_api.liquidation_address_controller_create_liquidation_address(
        customer_id='customer-id',
        create_liquidation_address_dto=CreateLiquidationAddressDto(
            network='solana',
            currency='usdc'
        )
    )
    
    print(f'Liquidation address: {address.address}')
    print(f'Network: {address.network}')
Parameters:
  • customer_id: str - Customer ID
  • create_liquidation_address_dto: CreateLiquidationAddressDto - Address details
Returns: LiquidationAddressResponseDto

liquidation_address_controller_get_liquidation_addresses(customer_id)

Get all liquidation addresses for a customer.
addresses = liquidation_api.liquidation_address_controller_get_liquidation_addresses(
    customer_id='customer-id'
)

for addr in addresses:
    print(f'{addr.network}: {addr.address}')
Parameters:
  • customer_id: str - Customer ID
Returns: List[LiquidationAddressResponseDto]

liquidation_address_controller_get_liquidation_address(customer_id, liquidation_address_id)

Get a specific liquidation address.
address = liquidation_api.liquidation_address_controller_get_liquidation_address(
    customer_id='customer-id',
    liquidation_address_id='address-id'
)
Parameters:
  • customer_id: str - Customer ID
  • liquidation_address_id: str - Address ID
Returns: LiquidationAddressResponseDto

Payment Intents

Create payment intents for bank and stablecoin payments.

Methods

payment_intent_controller_create_bank_payment_intent(create_bank_payment_intent_dto)

Create a bank payment intent.
import devdraft
from devdraft.model.create_bank_payment_intent_dto import CreateBankPaymentIntentDto

with devdraft.ApiClient(configuration) as api_client:
    intent_api = devdraft.PaymentIntentsApi(api_client)
    
    intent = intent_api.payment_intent_controller_create_bank_payment_intent(
        CreateBankPaymentIntentDto(
            customer_id='customer-id',
            amount=1000.00,
            currency='USD',
            payment_rail='wire'
        )
    )
    
    print(f'Payment intent: {intent.id}')
    print(f'Status: {intent.status}')
Parameters:
  • create_bank_payment_intent_dto: CreateBankPaymentIntentDto - Intent details
Returns: PaymentIntent

payment_intent_controller_create_stable_payment_intent(create_stable_payment_intent_dto)

Create a stablecoin payment intent.
from devdraft.model.create_stable_payment_intent_dto import CreateStablePaymentIntentDto

stable_intent = intent_api.payment_intent_controller_create_stable_payment_intent(
    CreateStablePaymentIntentDto(
        customer_id='customer-id',
        amount=500.00,
        currency='usdc',
        network='solana'
    )
)
Parameters:
  • create_stable_payment_intent_dto: CreateStablePaymentIntentDto - Intent details
Returns: PaymentIntent
Generate and manage payment links for easy customer payments.

Methods

Create a new payment link.
import devdraft
from devdraft.model.create_payment_link_dto import CreatePaymentLinkDto

with devdraft.ApiClient(configuration) as api_client:
    links_api = devdraft.PaymentLinksApi(api_client)
    
    link = links_api.payment_links_controller_create(
        CreatePaymentLinkDto(
            name='Product Purchase',
            amount=99.99,
            currency='USD',
            products=[
                {
                    'name': 'Premium Plan',
                    'quantity': 1,
                    'price': 99.99
                }
            ]
        )
    )
    
    print(f'Payment link: {link.url}')
    print(f'Share this link with customers: {link.short_url}')
Parameters:
  • create_payment_link_dto: CreatePaymentLinkDto - Link details
Returns: PaymentLink Get all payment links.
links = links_api.payment_links_controller_find_all(
    page=1,
    limit=20,
    active=True
)
Parameters:
  • page: int - Page number (optional)
  • limit: int - Items per page (optional)
  • active: bool - Filter by active status (optional)
Returns: List[PaymentLink] Get a payment link by ID.
link = links_api.payment_links_controller_find_one(id='link-id')
Parameters:
  • id: str - Payment link ID
Returns: PaymentLink Update a payment link.
updated = links_api.payment_links_controller_update(
    id='link-id',
    update_payment_link_dto={
        'active': False,
        'expires_at': '2024-12-31T23:59:59Z'
    }
)
Parameters:
  • id: str - Payment link ID
  • update_payment_link_dto: dict - Fields to update
Returns: PaymentLink

Products

Manage your product catalog.

Methods

product_controller_create(create_product_dto)

Create a new product.
import devdraft

with devdraft.ApiClient(configuration) as api_client:
    products_api = devdraft.ProductsApi(api_client)
    
    product = products_api.product_controller_create(
        {
            'name': 'Premium Subscription',
            'description': 'Access to all premium features',
            'price': 99.99,
            'currency': 'USD',
            'category': 'subscriptions'
        }
    )
    
    print(f'Product created: {product.id}')
Parameters:
  • create_product_dto: dict - Product details
Returns: Product

product_controller_find_all(**kwargs)

Get all products.
products = products_api.product_controller_find_all(
    category='subscriptions',
    active=True
)
Parameters:
  • category: str - Filter by category (optional)
  • active: bool - Filter by active status (optional)
Returns: List[Product]

product_controller_find_one(id)

Get a product by ID.
product = products_api.product_controller_find_one(id='product-id')
Parameters:
  • id: str - Product ID
Returns: Product

product_controller_update(id, update_product_dto)

Update a product.
updated = products_api.product_controller_update(
    id='product-id',
    update_product_dto={
        'price': 89.99,
        'description': 'Updated description'
    }
)
Parameters:
  • id: str - Product ID
  • update_product_dto: dict - Fields to update
Returns: Product

product_controller_remove(id)

Delete a product.
products_api.product_controller_remove(id='product-id')
Parameters:
  • id: str - Product ID
Returns: None

product_controller_upload_image(id, images)

Upload images for a product.
with open('product-image.jpg', 'rb') as image_file:
    products_api.product_controller_upload_image(
        id='product-id',
        images=[image_file]
    )
Parameters:
  • id: str - Product ID
  • images: List[file] - Image files
Returns: Product

Taxes

Configure and manage tax settings.

Methods

tax_controller_create(create_tax_dto)

Create a new tax configuration.
import devdraft
from devdraft.model.create_tax_dto import CreateTaxDto

with devdraft.ApiClient(configuration) as api_client:
    taxes_api = devdraft.TaxesApi(api_client)
    
    tax = taxes_api.tax_controller_create(
        CreateTaxDto(
            name='Sales Tax',
            percentage=8.5,
            country='US',
            state='CA'
        )
    )
    
    print(f'Tax created: {tax.id}')
Parameters:
  • create_tax_dto: CreateTaxDto - Tax details
Returns: Tax

tax_controller_find_all(**kwargs)

Get all tax configurations.
taxes = taxes_api.tax_controller_find_all(country='US')
Parameters:
  • country: str - Filter by country (optional)
Returns: List[Tax]

tax_controller_find_one(id)

Get a tax configuration by ID.
tax = taxes_api.tax_controller_find_one(id='tax-id')
Parameters:
  • id: str - Tax ID
Returns: Tax

tax_controller_update(id, update_tax_dto)

Update a tax configuration.
from devdraft.model.update_tax_dto import UpdateTaxDto

updated = taxes_api.tax_controller_update(
    id='tax-id',
    update_tax_dto=UpdateTaxDto(percentage=9.0)
)
Parameters:
  • id: str - Tax ID
  • update_tax_dto: UpdateTaxDto - Fields to update
Returns: Tax

tax_controller_remove(id)

Delete a tax configuration.
taxes_api.tax_controller_remove(id='tax-id')
Parameters:
  • id: str - Tax ID
Returns: None

Test Payments

Process test payments in sandbox environment.

Methods

test_payment_controller_create_payment_v0(payment_request_dto)

Create a test payment.
import devdraft
from devdraft.model.payment_request_dto import PaymentRequestDto

with devdraft.ApiClient(configuration) as api_client:
    test_api = devdraft.TestPaymentsApi(api_client)
    
    payment = test_api.test_payment_controller_create_payment_v0(
        PaymentRequestDto(
            amount=100.00,
            currency='USD',
            customer_id='test-customer-id',
            idempotency_key='unique-key-123'
        )
    )
    
    print(f'Test payment: {payment.id}')
    print(f'Status: {payment.status}')
Parameters:
  • payment_request_dto: PaymentRequestDto - Payment details
Returns: PaymentResponseDto

test_payment_controller_get_payment_v0(id)

Get test payment details by ID.
payment = test_api.test_payment_controller_get_payment_v0(id='payment-id')
print(f'Payment status: {payment.status}')
Parameters:
  • id: str - Payment ID
Returns: PaymentResponseDto

test_payment_controller_refund_payment_v0(id, **kwargs)

Refund a test payment.
refund = test_api.test_payment_controller_refund_payment_v0(
    id='payment-id',
    refund_amount=50.00
)

print(f'Refund processed: {refund.id}')
Parameters:
  • id: str - Payment ID
  • refund_amount: float - Amount to refund (optional, defaults to full amount)
Returns: RefundResponseDto

Transfers

Initiate and manage fund transfers between different payment rails.

Methods

transfer_controller_create_direct_bank_transfer(create_direct_bank_transfer_dto)

Create a direct bank transfer.
import devdraft
from devdraft.model.create_direct_bank_transfer_dto import CreateDirectBankTransferDto

with devdraft.ApiClient(configuration) as api_client:
    transfers_api = devdraft.TransfersApi(api_client)
    
    transfer = transfers_api.transfer_controller_create_direct_bank_transfer(
        CreateDirectBankTransferDto(
            wallet_id='wallet-id',
            payment_rail='wire',
            source_currency='usd',
            destination_currency='usdc',
            amount=1000.00
        )
    )
    
    print(f'Transfer created: {transfer.id}')
    print(f'Bank instructions: {transfer.source_deposit_instructions}')
Parameters:
  • create_direct_bank_transfer_dto: CreateDirectBankTransferDto - Transfer details
Returns: Transfer See also: Direct Bank Transfer Guide

transfer_controller_create_direct_wallet_transfer(create_direct_wallet_transfer_dto)

Create a direct wallet transfer.
from devdraft.model.create_direct_wallet_transfer_dto import CreateDirectWalletTransferDto

transfer = transfers_api.transfer_controller_create_direct_wallet_transfer(
    CreateDirectWalletTransferDto(
        wallet_id='wallet-id',
        network='solana',
        stable_coin_currency='usdc',
        amount=500.00
    )
)

print(f'Transfer created: {transfer.id}')
print(f'Deposit address: {transfer.source_deposit_instructions.to_address}')
Parameters:
  • create_direct_wallet_transfer_dto: CreateDirectWalletTransferDto - Transfer details
Returns: Transfer See also: Direct Wallet Transfer Guide

transfer_controller_create_external_bank_transfer(create_external_bank_transfer_dto)

Create an external bank transfer (from your wallet to external bank).
from devdraft.model.create_external_bank_transfer_dto import CreateExternalBankTransferDto

transfer = transfers_api.transfer_controller_create_external_bank_transfer(
    CreateExternalBankTransferDto(
        source_wallet_id='wallet-id',
        destination_bank_account_id='bank-account-id',
        amount=1000.00,
        currency='USD'
    )
)
Parameters:
  • create_external_bank_transfer_dto: CreateExternalBankTransferDto - Transfer details
Returns: Transfer

transfer_controller_create_external_stablecoin_transfer(create_external_stablecoin_transfer_dto)

Create an external stablecoin transfer (from your wallet to external wallet).
from devdraft.model.create_external_stablecoin_transfer_dto import CreateExternalStablecoinTransferDto

transfer = transfers_api.transfer_controller_create_external_stablecoin_transfer(
    CreateExternalStablecoinTransferDto(
        source_wallet_id='wallet-id',
        destination_address='0x742d35Cc6Ff82a8C2D8D1Da9da17c7eDfD5bE0a3',
        network='ethereum',
        currency='usdc',
        amount=250.00
    )
)
Parameters:
  • create_external_stablecoin_transfer_dto: CreateExternalStablecoinTransferDto - Transfer details
Returns: Transfer

transfer_controller_create_stablecoin_conversion(create_stablecoin_conversion_dto)

Convert between different stablecoins or networks.
from devdraft.model.create_stablecoin_conversion_dto import CreateStablecoinConversionDto

conversion = transfers_api.transfer_controller_create_stablecoin_conversion(
    CreateStablecoinConversionDto(
        source_wallet_id='wallet-id',
        destination_wallet_id='wallet-id',
        source_network='ethereum',
        destination_network='solana',
        source_currency='usdc',
        destination_currency='usdc',
        amount=1000.00
    )
)

print(f'Conversion ID: {conversion.id}')
print(f'Exchange rate: {conversion.exchange_rate.rate}')
print(f'Estimated completion: {conversion.estimated_completion}')
Parameters:
  • create_stablecoin_conversion_dto: CreateStablecoinConversionDto - Conversion details
Returns: Conversion See also: Stablecoin Conversion Guide

Wallets

Manage wallets and query balances.

Methods

wallet_controller_get_wallets()

Get all wallets for your application.
import devdraft

with devdraft.ApiClient(configuration) as api_client:
    wallets_api = devdraft.WalletsApi(api_client)
    
    wallets_api.wallet_controller_get_wallets()
    # Returns wallet information for your application
Returns: None
The response contains wallet IDs that you can use for transfers and other operations. In a future SDK version, this will return typed wallet objects.

Webhooks

Configure webhooks to receive real-time event notifications.

Methods

webhook_controller_create(create_webhook_dto)

Create a new webhook.
import devdraft
from devdraft.model.create_webhook_dto import CreateWebhookDto

with devdraft.ApiClient(configuration) as api_client:
    webhooks_api = devdraft.WebhooksApi(api_client)
    
    webhook = webhooks_api.webhook_controller_create(
        CreateWebhookDto(
            url='https://your-app.com/webhooks/devdraft',
            name='Production Webhook',
            is_active=True,
            encrypted=False
        )
    )
    
    print(f'Webhook ID: {webhook.id}')
    print(f'Signing secret: {webhook.signing_secret}')
Parameters:
  • create_webhook_dto: CreateWebhookDto - Webhook configuration
Returns: WebhookResponseDto See also: Webhooks Overview

webhook_controller_find_all(**kwargs)

Get all webhooks.
webhooks = webhooks_api.webhook_controller_find_all(
    page=1,
    limit=20,
    active=True
)

for webhook in webhooks:
    print(f'{webhook.name}: {webhook.url}')
    print(f'Active: {webhook.is_active}')
Parameters:
  • page: int - Page number (optional)
  • limit: int - Items per page (optional)
  • active: bool - Filter by active status (optional)
Returns: List[WebhookResponseDto]

webhook_controller_find_one(id)

Get a webhook by ID.
webhook = webhooks_api.webhook_controller_find_one(id='webhook-id')

print(f'Webhook: {webhook.name}')
print(f'URL: {webhook.url}')
print(f'Delivery stats: {webhook.delivery_stats}')
Parameters:
  • id: str - Webhook ID
Returns: WebhookResponseDto

webhook_controller_update(id, update_webhook_dto)

Update a webhook.
from devdraft.model.update_webhook_dto import UpdateWebhookDto

updated = webhooks_api.webhook_controller_update(
    id='webhook-id',
    update_webhook_dto=UpdateWebhookDto(
        url='https://your-app.com/webhooks/new-endpoint',
        is_active=True
    )
)
Parameters:
  • id: str - Webhook ID
  • update_webhook_dto: UpdateWebhookDto - Fields to update
Returns: WebhookResponseDto

webhook_controller_remove(id)

Delete a webhook.
webhooks_api.webhook_controller_remove(id='webhook-id')
print('Webhook deleted')
Parameters:
  • id: str - Webhook ID
Returns: None

Error Handling

All SDK methods may throw ApiException. Handle them appropriately:
from devdraft.rest import ApiException

try:
    transfer = transfers_api.transfer_controller_create_direct_wallet_transfer(transfer_data)
except ApiException as e:
    status_code = e.status
    response_body = e.body
    
    if status_code == 400:
        print(f'Invalid request: {response_body}')
    elif status_code == 401:
        print('Authentication failed - check your API credentials')
    elif status_code == 404:
        print(f'Resource not found: {response_body}')
    elif status_code == 422:
        print(f'Validation error: {response_body}')
    elif status_code == 429:
        retry_after = e.headers.get('Retry-After')
        print(f'Rate limited - retry after: {retry_after}')
    else:
        print(f'API error: {status_code} - {response_body}')

Type Hints

The SDK includes type hints for better IDE support and type checking:
from devdraft.model.create_direct_wallet_transfer_dto import CreateDirectWalletTransferDto
from devdraft.model.webhook_response_dto import WebhookResponseDto
from devdraft.model.payment_response_dto import PaymentResponseDto

# Type hints help with IDE autocomplete and type checking
def create_transfer(wallet_id: str, amount: float) -> None:
    transfer_dto = CreateDirectWalletTransferDto(
        wallet_id=wallet_id,
        network='solana',
        stable_coin_currency='usdc',
        amount=amount
    )
    
    transfer = transfers_api.transfer_controller_create_direct_wallet_transfer(transfer_dto)

Best Practices

1

Use Context Managers

Always use with statements to ensure proper resource cleanup.
with devdraft.ApiClient(configuration) as api_client:
    transfers_api = devdraft.TransfersApi(api_client)
    # API calls here
# Resources automatically cleaned up
2

Environment Variables for Credentials

Store API credentials in environment variables, never in source code.
import os

configuration.api_key['x-client-key'] = os.environ['DEVDRAFT_CLIENT_KEY']
configuration.api_key['x-client-secret'] = os.environ['DEVDRAFT_CLIENT_SECRET']
3

Proper Exception Handling

Always wrap API calls in try-except blocks.
from devdraft.rest import ApiException

try:
    result = api.some_method()
except ApiException as e:
    print(f'API error: {e.status} - {e.body}')
except Exception as e:
    print(f'Unexpected error: {e}')
4

Use Type Hints

Leverage Python’s type hints for better code quality.
from typing import Optional
from devdraft.model.customer import Customer

def get_customer_by_email(email: str) -> Optional[Customer]:
    customers = customers_api.customer_controller_find_all()
    return next((c for c in customers if c.email == email), None)
5

Reuse ApiClient

Create a single configuration and ApiClient instance and reuse it.
# Bad: Creating new client for each API
with devdraft.ApiClient(config) as client1:
    transfers_api = devdraft.TransfersApi(client1)

with devdraft.ApiClient(config) as client2:
    webhooks_api = devdraft.WebhooksApi(client2)

# Good: Reuse the same client
with devdraft.ApiClient(config) as api_client:
    transfers_api = devdraft.TransfersApi(api_client)
    webhooks_api = devdraft.WebhooksApi(api_client)
6

Use Logging for Debugging

Enable logging for debugging API calls.
import logging

# Enable debug logging
logging.basicConfig(level=logging.DEBUG)

configuration.debug = True  # Enable SDK debug mode

Testing with Pytest

Example pytest test for SDK integration:
import pytest
import devdraft
from devdraft.rest import ApiException

@pytest.fixture
def api_client():
    configuration = devdraft.Configuration(
        host="https://api.devdraft.ai"
    )
    configuration.api_key['x-client-key'] = 'test-key'
    configuration.api_key['x-client-secret'] = 'test-secret'
    
    with devdraft.ApiClient(configuration) as client:
        yield client

def test_create_webhook(api_client):
    webhooks_api = devdraft.WebhooksApi(api_client)
    
    webhook = webhooks_api.webhook_controller_create(
        devdraft.CreateWebhookDto(
            url='https://test.example.com/webhook',
            name='Test Webhook',
            is_active=True
        )
    )
    
    assert webhook.id is not None
    assert webhook.name == 'Test Webhook'

def test_api_error_handling(api_client):
    transfers_api = devdraft.TransfersApi(api_client)
    
    with pytest.raises(ApiException) as exc_info:
        transfers_api.transfer_controller_create_direct_wallet_transfer(
            devdraft.CreateDirectWalletTransferDto(
                wallet_id='invalid-id',
                network='invalid-network',
                stable_coin_currency='invalid',
                amount=-100  # Invalid amount
            )
        )
    
    assert exc_info.value.status in [400, 422]

Async Support

For async/await support, you can use aiohttp with the SDK:
import asyncio
import devdraft

async def async_example():
    configuration = devdraft.Configuration(
        host="https://api.devdraft.ai"
    )
    configuration.api_key['x-client-key'] = 'your-key'
    configuration.api_key['x-client-secret'] = 'your-secret'
    
    async with devdraft.ApiClient(configuration) as api_client:
        health_api = devdraft.APIHealthApi(api_client)
        
        # Use async methods
        response = await health_api.health_controller_public_health_check_v0()
        print(f'Status: {response.status}')

# Run async function
asyncio.run(async_example())

Next Steps

SDK Quickstart

Complete integration guide with examples

Transfers

Learn about initiating transfers

Webhooks

Set up webhook notifications

API Reference

Complete REST API documentation