{"id":9940,"library":"metronome-sdk","title":"Metronome SDK","description":"The Metronome SDK is the official Python library for interacting with the Metronome API, designed for integrating metered billing and usage-based pricing into applications. It provides access to endpoints for managing customers, contracts, usage, invoices, and more. The library is currently at version 4.4.0 and follows a rapid release cadence with frequent updates and bug fixes.","status":"active","version":"4.4.0","language":"en","source_language":"en","source_url":"https://github.com/Metronome-Industries/metronome-python","tags":["api-client","billing","metered-billing","saas","pricing"],"install":[{"cmd":"pip install metronome-sdk","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for execution","package":"python","version":">=3.9","optional":false}],"imports":[{"note":"The Metronome client class is within the 'client' submodule, not directly under 'metronome'.","wrong":"import metronome; client = metronome.Metronome()","symbol":"Metronome","correct":"from metronome.client import Metronome"},{"note":"It's best practice to import the 'types' module with an alias or specific types directly, rather than the top-level 'types' that might conflict.","wrong":"from metronome import types","symbol":"types","correct":"import metronome.types as types"}],"quickstart":{"code":"import os\nfrom metronome.client import Metronome\nimport metronome.types as types\n\nMETRONOME_API_KEY = os.environ.get('METRONOME_API_KEY', 'YOUR_API_KEY')\n\nif not METRONOME_API_KEY or METRONOME_API_KEY == 'YOUR_API_KEY':\n    print(\"Warning: METRONOME_API_KEY not set. Using placeholder.\")\n    # Example: run in dry-run mode or with a mocked client for testing\n    # For real API calls, ensure API key is set.\n    exit(1)\n\nclient = Metronome(api_key=METRONOME_API_KEY)\n\ntry:\n    # Example: List customers\n    customers = client.customers.list()\n    print(f\"Found {len(customers.items)} customers:\")\n    for customer in customers.items[:3]: # Print first 3 customers\n        print(f\"  ID: {customer.id}, Name: {customer.name}\")\n\n    # Example: Create a new test customer\n    new_customer = client.customers.create(\n        name=\"My Test Customer from SDK\",\n        billing_config=types.BillingConfig(\n            currency=\"USD\",\n            billing_provider_type=types.BillingProviderType.STRIPE,\n            billing_provider_customer_id=\"cus_test_123\",\n        ),\n        external_id=\"my-test-customer-123\"\n    )\n    print(f\"Created new customer with ID: {new_customer.id}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart initializes the Metronome client using an API key from an environment variable and then demonstrates listing existing customers and creating a new one. Ensure you have a `METRONOME_API_KEY` environment variable set with your actual Metronome API key for successful API calls."},"warnings":[{"fix":"Remove `minimum_config` from any Rate or Override objects in your API requests (e.g., when creating/editing contracts, plans, or prices). Review your contract and pricing configurations.","message":"The `minimum_config` field was removed from Rate and Override schemas.","severity":"breaking","affected_versions":">=4.3.0"},{"fix":"Remove `priority` from any parameters sent when creating or updating contracts, and adjust code that expects `priority` in contract responses.","message":"The `priority` parameter and response field were removed from contract-related API endpoints.","severity":"breaking","affected_versions":">=4.2.0"},{"fix":"Update your API calls and data models to no longer include or expect the `use_list_prices` field on Rate objects, particularly when defining or updating pricing plans.","message":"The `use_list_prices` field was removed from Rate objects.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"When calling the preview events API, ensure you are no longer passing `customer_id` as a request parameter.","message":"The `customer_id` parameter was removed from preview events requests.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If your code assumes a single invoice object from the Preview Events API, update it to iterate over the returned list of invoices, even if it expects only one.","message":"The Preview Events API changed its response structure to return a list of invoices instead of a single invoice object.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update calls to affected list endpoints (e.g., `client.customers.list()`) to correctly handle pagination by checking `response.next_page` and `response.items` for results. Direct access to `.items` will only provide the current page's results.","message":"Pagination support was added to many list endpoints (e.g., Customers, Invoices, Commits, Credits, Usage).","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Remove the `minimum_config` attribute from your `Rate` or `Override` object definitions. Update your code to reflect the schema changes.","cause":"You are attempting to set or access the `minimum_config` field on a `Rate` object, which was removed in version 4.3.0.","error":"AttributeError: 'Rate' object has no attribute 'minimum_config'"},{"fix":"Remove the `priority` keyword argument from your `client.contracts.create()` or `client.contracts.edit()` calls.","cause":"The `priority` field was removed as a parameter for contract creation/update in version 4.2.0.","error":"TypeError: 'priority' is an unexpected keyword argument for 'create_contract'"},{"fix":"Ensure the `METRONOME_API_KEY` environment variable is correctly set, or pass a valid `api_key` directly when initializing `metronome.client.Metronome()`.","cause":"The API key provided is missing, invalid, or has insufficient permissions.","error":"metronome.ApiException: 401 Unauthorized"},{"fix":"Review the Metronome API documentation for the specific endpoint you are using and provide all mandatory fields, such as `billing_config` when creating a customer.","cause":"You are trying to create a resource (e.g., a customer) without providing a required configuration object.","error":"TypeError: Missing required argument 'billing_config'"}]}