from flexprice import Flexpriceimport os# Basic initializationwith Flexprice( server_url="https://us.api.flexprice.io/v1", api_key_auth=os.getenv("FLEXPRICE_API_KEY"),) as flexprice: # Your code here pass
Always use the context manager (with statement) to ensure proper resource cleanup.
The server URL must include /v1 and have no trailing slash: https://us.api.flexprice.io/v1
from flexprice import Flexpricetry: with Flexprice( server_url="https://us.api.flexprice.io/v1", api_key_auth=os.getenv("FLEXPRICE_API_KEY"), ) as flexprice: result = flexprice.events.ingest_event( request={ "event_name": "test_event", "external_customer_id": "customer-123", } )except Exception as e: print(f"Error: {e}") # Inspect status code and response body if available if hasattr(e, 'status_code'): print(f"Status code: {e.status_code}")
with Flexprice( server_url="https://us.api.flexprice.io/v1", api_key_auth=os.getenv("FLEXPRICE_API_KEY"),) as flexprice: customers = flexprice.customers.list_customers( page_size=50, page=1, ) for customer in customers.customers: print(f"Customer: {customer.name} ({customer.external_id})")
The Python SDK uses Pydantic models for type-safe request and response handling:
from flexprice import Flexpricefrom typing import Dict, Any# Type hints work automaticallywith Flexprice( server_url="https://us.api.flexprice.io/v1", api_key_auth=os.getenv("FLEXPRICE_API_KEY"),) as flexprice: # Request is type-checked event_data: Dict[str, Any] = { "event_name": "api_request", "external_customer_id": "customer-123", "properties": {"key": "value"}, } result = flexprice.events.ingest_event(request=event_data) # Response is a Pydantic model with autocomplete