Developer-friendly & type-safe Python SDK specifically catered to leverage flexprice-sdk-test API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
FlexPrice API: FlexPrice API Service
Tip
To finish publishing your SDK to PyPI you must run your first generation action.
Note
Python version upgrade policy
Once a Python version reaches its official end of life date, a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
The SDK can be installed with uv, pip, or poetry package managers.
uv is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
uv add git+<UNSET>.gitPIP is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
pip install git+<UNSET>.gitPoetry is a modern tool that simplifies dependency management and package publishing by using a single pyproject.toml file to handle project metadata and dependencies.
poetry add git+<UNSET>.gitYou can use this SDK in a Python shell with uv and the uvx command that comes with it like so:
uvx --from flexprice-sdk-test pythonIt's also possible to write a standalone Python script without needing to set up a whole project like so:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "flexprice-sdk-test",
# ]
# ///
from flexprice_sdk_test import FlexPrice
sdk = FlexPrice(
# SDK arguments
)
# Rest of script here...Once that is saved to a file, you can run it with uv run script.py where
script.py can be replaced with the actual file name.
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
# Synchronous Example
from flexprice_sdk_test import FlexPrice
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = flex_price.addons.get_addons()
# Handle response
print(res)The same SDK client can also be used to make asynchronous requests by importing asyncio.
# Asynchronous Example
import asyncio
from flexprice_sdk_test import FlexPrice
async def main():
async with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = await flex_price.addons.get_addons_async()
# Handle response
print(res)
asyncio.run(main())This SDK supports the following security scheme globally:
| Name | Type | Scheme |
|---|---|---|
api_key_auth |
apiKey | API key |
To authenticate with the API the api_key_auth parameter must be set when initializing the SDK client instance. For example:
from flexprice_sdk_test import FlexPrice
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = flex_price.addons.get_addons()
# Handle response
print(res)Available methods
- get_addons - List addons
- post_addons - Create addon
- get_addons_lookup_lookup_key_ - Get addon by lookup key
- post_addons_search - List addons by filter
- get_addons_id_ - Get addon
- put_addons_id_ - Update addon
- delete_addons_id_ - Delete addon
- post_alert_search - List alert logs by filter
- post_auth_login - Login
- post_auth_signup - Sign up
- get_connections - Get connections
- post_connections_search - List connections by filter
- get_connections_id_ - Get a connection
- put_connections_id_ - Update a connection
- delete_connections_id_ - Delete a connection
- post_costs - Create a new costsheet
- get_costs_active - Get active costsheet for tenant
- post_costs_analytics - Get combined revenue and cost analytics
- post_costs_analytics_v2 - Get combined revenue and cost analytics
- post_costs_search - List costsheets by filter
- get_costs_id_ - Get a costsheet by ID
- put_costs_id_ - Update a costsheet
- delete_costs_id_ - Delete a costsheet
- get_coupons - List coupons with filtering
- post_coupons - Create a new coupon
- get_coupons_id_ - Get a coupon by ID
- put_coupons_id_ - Update a coupon
- delete_coupons_id_ - Delete a coupon
- get_creditnotes - List credit notes with filtering
- post_creditnotes - Create a new credit note
- get_creditnotes_id_ - Get a credit note by ID
- post_creditnotes_id_finalize - Process a draft credit note
- post_creditnotes_id_void - Void a credit note
- get_creditgrants - Get credit grants
- post_creditgrants - Create a new credit grant
- get_creditgrants_id_ - Get a credit grant by ID
- put_creditgrants_id_ - Update a credit grant
- delete_creditgrants_id_ - Delete a credit grant
- get_plans_id_creditgrants - Get plan credit grants
- get_portal_external_id_ - Create a customer portal session
- get_customers - Get customers
- post_customers - Create a customer
- get_customers_external_external_id_ - Get a customer by external id
- post_customers_search - List customers by filter
- get_customers_usage - Get customer usage summary
- get_customers_id_ - Get a customer
- put_customers_id_ - Update a customer
- delete_customers_id_ - Delete a customer
- get_customers_id_entitlements - Get customer entitlements
- get_customers_id_grants_upcoming - Get upcoming credit grant applications
- get_addons_id_entitlements - Get addon entitlements
- get_entitlements - Get entitlements
- post_entitlements - Create a new entitlement
- post_entitlements_bulk - Create multiple entitlements in bulk
- post_entitlements_search - List entitlements by filter
- get_entitlements_id_ - Get an entitlement by ID
- put_entitlements_id_ - Update an entitlement
- delete_entitlements_id_ - Delete an entitlement
- get_plans_id_entitlements - Get plan entitlements
- get_entity_integration_mappings - List entity integration mappings
- post_entity_integration_mappings - Create entity integration mapping
- get_entity_integration_mappings_id_ - Get entity integration mapping
- delete_entity_integration_mappings_id_ - Delete entity integration mapping
- get_environments - Get environments
- post_environments - Create an environment
- get_environments_id_ - Get an environment
- put_environments_id_ - Update an environment
- post_events - Ingest event
- post_events_analytics - Get usage analytics
- post_events_bulk - Bulk Ingest events
- post_events_huggingface_inference - Get hugging face inference data
- get_events_monitoring - Get monitoring data
- post_events_query - List raw events
- post_events_usage - Get usage statistics
- post_events_usage_meter - Get usage by meter
- get_features - List features
- post_features - Create a new feature
- post_features_search - List features by filter
- get_features_id_ - Get a feature by ID
- put_features_id_ - Update a feature
- delete_features_id_ - Delete a feature
- post_groups - Create a group
- post_groups_search - Get groups
- get_groups_id_ - Get a group
- delete_groups_id_ - Delete a group
- get_secrets_integrations_by_provider_provider_ - Get integration details
- post_secrets_integrations_create_provider_ - Create or update an integration
- get_secrets_integrations_linked - List linked integrations
- delete_secrets_integrations_id_ - Delete an integration
- get_customers_id_invoices_summary - Get a customer invoice summary
- get_invoices - List invoices
- post_invoices - Create a new one off invoice
- post_invoices_preview - Get a preview invoice
- post_invoices_search - List invoices by filter
- get_invoices_id_ - Get an invoice by ID
- put_invoices_id_ - Update an invoice
- post_invoices_id_comms_trigger - Trigger communication webhook for an invoice
- post_invoices_id_finalize - Finalize an invoice
- put_invoices_id_payment - Update invoice payment status
- post_invoices_id_payment_attempt - Attempt payment for an invoice
- get_invoices_id_pdf - Get PDF for an invoice
- post_invoices_id_recalculate - Recalculate invoice totals and line items
- post_invoices_id_void - Void an invoice
- get_payments - List payments
- post_payments - Create a new payment
- get_payments_id_ - Get a payment by ID
- put_payments_id_ - Update a payment
- delete_payments_id_ - Delete a payment
- post_payments_id_process - Process a payment
- get_plans - Get plans
- post_plans - Create a new plan
- post_plans_search - List plans by filter
- get_plans_id_ - Get a plan
- put_plans_id_ - Update a plan
- delete_plans_id_ - Delete a plan
- post_plans_id_sync_subscriptions - Synchronize plan prices
- get_prices_units - List price units
- post_prices_units - Create a new price unit
- get_prices_units_code_code_ - Get a price unit by code
- post_prices_units_search - List price units by filter
- get_prices_units_id_ - Get a price unit by ID
- put_prices_units_id_ - Update a price unit
- delete_prices_units_id_ - Delete a price unit
- get_prices - Get prices
- post_prices - Create a new price
- post_prices_bulk - Create multiple prices in bulk
- get_prices_id_ - Get a price by ID
- put_prices_id_ - Update a price
- delete_prices_id_ - Delete a price
- get_rbac_roles - List all RBAC roles
- get_rbac_roles_id_ - Get a specific RBAC role
- get_tasks_scheduled - List scheduled tasks
- post_tasks_scheduled - Create a scheduled task
- post_tasks_scheduled_schedule_update_billing_period - Schedule update billing period
- get_tasks_scheduled_id_ - Get a scheduled task
- put_tasks_scheduled_id_ - Update a scheduled task
- delete_tasks_scheduled_id_ - Delete a scheduled task
- post_tasks_scheduled_id_run - Trigger force run
- get_secrets_api_keys - List API keys
- post_secrets_api_keys - Create a new API key
- delete_secrets_api_keys_id_ - Delete an API key
- get_subscriptions - List subscriptions
- post_subscriptions - Create subscription
- post_subscriptions_addon - Add addon to subscription
- delete_subscriptions_addon - Remove addon from subscription
- put_subscriptions_lineitems_id_ - Update subscription line item
- delete_subscriptions_lineitems_id_ - Delete subscription line item
- post_subscriptions_search - List subscriptions by filter
- post_subscriptions_usage - Get usage by subscription
- get_subscriptions_id_ - Get subscription
- post_subscriptions_id_activate - Activate draft subscription
- get_subscriptions_id_addons_associations - Get active addon associations
- post_subscriptions_id_cancel - Cancel subscription
- post_subscriptions_id_change_execute - Execute subscription plan change
- post_subscriptions_id_change_preview - Preview subscription plan change
- get_subscriptions_id_entitlements - Get subscription entitlements
- get_subscriptions_id_grants_upcoming - Get upcoming credit grant applications
- post_subscriptions_id_pause - Pause a subscription
- get_subscriptions_id_pauses - List all pauses for a subscription
- post_subscriptions_id_resume - Resume a paused subscription
- get_tasks - List tasks
- post_tasks - Create a new task
- get_tasks_result - Get task processing result
- get_tasks_id_ - Get a task
- put_tasks_id_status - Update task status
- get_taxes_associations - List tax associations
- post_taxes_associations - Create Tax Association
- get_taxes_associations_id_ - Get Tax Association
- put_taxes_associations_id_ - Update tax association
- delete_taxes_associations_id_ - Delete tax association
- get_taxes_rates - Get tax rates
- post_taxes_rates - Create a tax rate
- get_taxes_rates_id_ - Get a tax rate
- put_taxes_rates_id_ - Update a tax rate
- delete_taxes_rates_id_ - Delete a tax rate
- get_tenant_billing - Get billing usage for the current tenant
- post_tenants - Create a new tenant
- put_tenants_update - Update a tenant
- get_tenants_id_ - Get tenant by ID
- post_users - Create service account
- get_users_me - Get user info
- post_users_search - List users with filters
- get_customers_wallets - Get Customer Wallets
- get_customers_id_wallets - Get wallets by customer ID
- get_wallets - List wallets
- post_wallets - Create a new wallet
- post_wallets_search - List wallets by filter
- post_wallets_transactions_search - List wallet transactions by filter
- get_wallets_id_ - Get wallet by ID
- put_wallets_id_ - Update a wallet
- get_wallets_id_balance_real_time - Get wallet balance
- post_wallets_id_terminate - Terminate a wallet
- post_wallets_id_top_up - Top up wallet
- get_wallets_id_transactions - Get wallet transactions
- post_webhooks_chargebee_tenant_id_environment_id_ - Handle Chargebee webhook events
- post_webhooks_hubspot_tenant_id_environment_id_ - Handle HubSpot webhook events
- post_webhooks_nomod_tenant_id_environment_id_ - Handle Nomod webhook events
- post_webhooks_quickbooks_tenant_id_environment_id_ - Handle QuickBooks webhook events
- post_webhooks_razorpay_tenant_id_environment_id_ - Handle Razorpay webhook events
- post_webhooks_stripe_tenant_id_environment_id_ - Handle Stripe webhook events
Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
Tip
For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
from flexprice_sdk_test import FlexPrice
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = flex_price.events.post_events_analytics(request=open("example.file", "rb"))
# Handle response
print(res)Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call:
from flexprice_sdk_test import FlexPrice
from flexprice_sdk_test.utils import BackoffStrategy, RetryConfig
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = flex_price.addons.get_addons(,
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
# Handle response
print(res)If you'd like to override the default retry strategy for all operations that support retries, you can use the retry_config optional parameter when initializing the SDK:
from flexprice_sdk_test import FlexPrice
from flexprice_sdk_test.utils import BackoffStrategy, RetryConfig
with FlexPrice(
server_url="https://api.example.com",
retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = flex_price.addons.get_addons()
# Handle response
print(res)FlexPriceError is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
|---|---|---|
err.message |
str |
Error message |
err.status_code |
int |
HTTP response status code eg 404 |
err.headers |
httpx.Headers |
HTTP response headers |
err.body |
str |
HTTP body. Can be empty string if no body is returned. |
err.raw_response |
httpx.Response |
Raw HTTP response |
err.data |
Optional. Some errors may contain structured data. See Error Classes. |
from flexprice_sdk_test import FlexPrice
from flexprice_sdk_test.models import errors
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
res = None
try:
res = flex_price.addons.get_addons()
# Handle response
print(res)
except errors.FlexPriceError as e:
# The base class for HTTP error responses
print(e.message)
print(e.status_code)
print(e.body)
print(e.headers)
print(e.raw_response)
# Depending on the method different errors may be thrown
if isinstance(e, errors.ErrorsErrorResponse):
print(e.data.error) # Optional[components.ErrorsErrorDetail]
print(e.data.success) # Optional[bool]Primary errors:
FlexPriceError: The base class for HTTP error responses.
Less common errors (5)
Network errors:
httpx.RequestError: Base class for request errors.httpx.ConnectError: HTTP client was unable to make a request to a server.httpx.TimeoutException: HTTP request timed out.
Inherit from FlexPriceError:
ResponseValidationError: Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via thecauseattribute.
* Check the method documentation to see if the error is applicable.
The Python SDK makes API calls using the httpx HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
Depending on whether you are using the sync or async version of the SDK, you can pass an instance of HttpClient or AsyncHttpClient respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of httpx.Client or httpx.AsyncClient directly.
For example, you could specify a header for every request that this sdk makes as follows:
from flexprice_sdk_test import FlexPrice
import httpx
http_client = httpx.Client(headers={"x-custom-header": "someValue"})
s = FlexPrice(client=http_client)or you could wrap the client with your own custom logic:
from flexprice_sdk_test import FlexPrice
from flexprice_sdk_test.httpclient import AsyncHttpClient
import httpx
class CustomClient(AsyncHttpClient):
client: AsyncHttpClient
def __init__(self, client: AsyncHttpClient):
self.client = client
async def send(
self,
request: httpx.Request,
*,
stream: bool = False,
auth: Union[
httpx._types.AuthTypes, httpx._client.UseClientDefault, None
] = httpx.USE_CLIENT_DEFAULT,
follow_redirects: Union[
bool, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
) -> httpx.Response:
request.headers["Client-Level-Header"] = "added by client"
return await self.client.send(
request, stream=stream, auth=auth, follow_redirects=follow_redirects
)
def build_request(
self,
method: str,
url: httpx._types.URLTypes,
*,
content: Optional[httpx._types.RequestContent] = None,
data: Optional[httpx._types.RequestData] = None,
files: Optional[httpx._types.RequestFiles] = None,
json: Optional[Any] = None,
params: Optional[httpx._types.QueryParamTypes] = None,
headers: Optional[httpx._types.HeaderTypes] = None,
cookies: Optional[httpx._types.CookieTypes] = None,
timeout: Union[
httpx._types.TimeoutTypes, httpx._client.UseClientDefault
] = httpx.USE_CLIENT_DEFAULT,
extensions: Optional[httpx._types.RequestExtensions] = None,
) -> httpx.Request:
return self.client.build_request(
method,
url,
content=content,
data=data,
files=files,
json=json,
params=params,
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
s = FlexPrice(async_client=CustomClient(httpx.AsyncClient()))The FlexPrice class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a context manager and reuse it across the application.
from flexprice_sdk_test import FlexPrice
def main():
with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
# Rest of application here...
# Or when using async:
async def amain():
async with FlexPrice(
server_url="https://api.example.com",
api_key_auth="<YOUR_API_KEY_HERE>",
) as flex_price:
# Rest of application here...You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass your own logger class directly into your SDK.
from flexprice_sdk_test import FlexPrice
import logging
logging.basicConfig(level=logging.DEBUG)
s = FlexPrice(server_url="https://example.com", debug_logger=logging.getLogger("flexprice_sdk_test"))This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.