Skip to main content

Installation


Quick Start

Configuration

Get your API key from Settings → API Keys in your Metrifox dashboard.

Customer Management

Create a Customer

Type-Safe Dataclasses

For better type safety and IDE support:

Update a Customer

The customer_key cannot be changed after creation.

Get Customer Data

Delete a Customer

Archive / Unarchive a Customer

Bulk CSV Upload


Usage Tracking & Access Control

Check Feature Access

Type-Safe Access Checks

Record Usage Events

Type-Safe Usage Events

List Usage Events

Retrieve usage events with optional filters and pagination:

Compute Quantity Price

Compute the price for a given quantity of a feature for a customer, based on their plan. Useful for previewing upgrade costs or showing customers the cost of additional usage before they commit.
Only available to tenants whose plan includes the finance API feature.

Complete Usage Example


Checkout & Billing

Generate Checkout URL

Type-Safe Checkout

Card Collection URL

Generate a hosted URL for collecting a payment method against an existing subscription or order. Useful for trial-to-paid conversions and re-collecting card details after expiry.

Wallets & Credit Allocations


Error Handling


Framework Integration

Django

Flask

FastAPI


API Reference

Client Methods

Initialization:
  • MetrifoxClient(api_key, base_url, web_app_base_url, meter_service_base_url) - Initialize the client
  • init(config) - Convenience function to initialize the client
Customers Module (client.customers):
  • create(request) - Create a customer
  • update(customer_key, request) - Update a customer
  • get(customer_key) - Get a customer
  • get_details(customer_key) - Get detailed customer information
  • list(params) - List customers with pagination and filters
  • delete(customer_key) - Delete a customer
  • archive(customer_key) - Archive a customer
  • unarchive(customer_key) - Restore an archived customer
  • has_active_subscription(customer_key) - Check for active subscription
  • upload_csv(file_path) - Upload customers via CSV
  • bulk_create(customers) - Create multiple customers in one call
Usages Module (client.usages):
  • check_access(request) - Check feature access
  • record_usage(request) - Record a usage event
  • list_events(customer_key, feature_key, page, per_page) - List recorded usage events
  • quantity_price(customer_key, feature_key, quantity) - Compute the price of a usage quantity (requires finance API feature)
Checkout Module (client.checkout):
  • url(config) - Generate a checkout URL
  • card_collection_url(subscription_id, order_id) - Generate a hosted card-collection URL
Wallets Module (client.wallets):
  • list(customer_key) - List a customer’s credit wallets
  • list_credit_allocations(wallet_id, status) - List credit allocations for a wallet
  • get_credit_allocation(allocation_id) - Get a single allocation with transaction history

Type Definitions

All type definitions are available for import:

Configuration

Environment Variables

  • METRIFOX_API_KEY - Your Metrifox API key
  • METRIFOX_METER_SERVICE_BASE_URL - Optional override for the meter service URL

Custom URLs

Default URLs

  • Production API: https://api.metrifox.com/api/v1/
  • Meter Service: https://api-meter.metrifox.com/
  • Web App: https://app.metrifox.com

Requirements

  • Python 3.8+
  • requests >= 2.31.0

Support

The Python SDK follows Pythonic patterns with type hints, dataclasses, and comprehensive error handling for a great developer experience.