Overview

The ParityDeals Python SDK provides a convenient way to interact with the ParityDeals REST APIs from your Python application. The SDK supports both synchronous and asynchronous operations.

Installation

To install the ParityDeals SDK in your environment, run the following command:

pip install paritydeals-sdk

Prerequisites

Before you can initialize the client and use the SDK methods, you need a Server API Key.

You can obtain this key from the ParityDeals application:

  1. Navigate to Settings.
  2. Go to the Developers section.
  3. Copy the Server API Key.

Once copied, add this key to your environment variables or directly in your code (though environment variables are recommended for security).

# Example of setting it in your code (ensure you handle this securely)
ACCESS_TOKEN = "__YOUR_API_KEY__"

Configuring the Client

The SDK supports both synchronous and asynchronous clients. The primary difference lies in how you create the client instance. Once created, both client types can invoke the same methods to communicate with the ParityDeals application.

How to Create a Synchronous Client

Use the synchronous client for traditional, blocking I/O operations.

from paritydeals_sdk import ParityDeals

client = ParityDeals.create_sync_client(access_token=ACCESS_TOKEN)

How to Create an Asynchronous Client

Use the asynchronous client for non-blocking I/O operations, suitable for applications using asyncio.

from paritydeals_sdk import ParityDeals

async_client = ParityDeals.create_async_client(access_token=ACCESS_TOKEN)

Supported Functionalities

The SDK currently supports the following operations:

  1. Customers

  2. Checkout

  3. Entitlements

  4. Reporting

  5. Subscriptions

Further details on each method, including parameters and return values, should be added under each functionality.


Customers

The customers module allows you to manage customer records within ParityDeals. You can access these operations via the customers attribute on an initialized ParityDeals client instance.

All methods are available in both synchronous and asynchronous versions, depending on how the ParityDeals client was instantiated.


Creates a new customer

Synchronous:

new_customer = client.customers.create(
    customerId="unique-customer-id-123",
    email="new.customer@example.com",
    name="John Doe",
    metadata={"source": "sdk_import", "priority": "high"}
)
print(f"Customer Created: ID = {new_customer.id}, Customer Client ID = {new_customer.customerId}")

Asynchronous:

new_customer = await async_client.customers.create(
    customerId="unique-customer-id-456",
    email="another.new.customer@example.com",
    name="Jane Roe"
)
print(f"Customer Created (Async): ID = {new_customer.id}, Customer Client ID = {new_customer.customerId}")

Required Parameters:

  • customerId (str): A unique identifier for the customer that you define. This ID will be used to reference the customer in subsequent API calls.

Optional Parameters:

  • email (str): The email address of the customer. Must be a valid email format.
  • name (str): The name of the customer.
  • metadata (Dict[str, str]): A dictionary of custom key-value pairs to store additional information about the customer.

Returns: An instance of CustomerResponse (Pydantic model), representing the newly created customer record. Key attributes include:

  • id (str): The server-generated unique UUID for the customer record.
  • customerId (str): The client-provided customer identifier.
  • name (str): The customer’s name.
  • email (str): The customer’s email.
  • details ([Dict[str, Any]]): Any server-added details about the customer (typically read-only).
  • metadata ([Dict[str, str]]): The metadata associated with the customer.
  • createdOn (string) : ISO 8601 timestamp of when the customer was created.
  • modifiedOn (string) : ISO 8601 timestamp of when the customer was last modified.

Updates an existing customer

This operation performs a partial update (PATCH), so you only need to provide the fields you want to change.

Synchronous:

    updated_customer = client.customers.update(
        customerId="unique-customer-id-123",
        name="Johnathan Doe",
        metadata={"source": "sdk_import", "priority": "very_high", "status": "active"}
    )
    print(f"Customer Updated: {updated_customer.name}")

Asynchronous:

    updated_customer = await async_client.customers.update(
        customerId="unique-customer-id-456",
        email="jane.roe.updated@example.com"
    )
    print(f"Customer Updated (Async): {updated_customer.email}")

Parameters:

Required Parameters:

  • customerId (str): A unique identifier for the customer that you define. This ID will be used to reference the customer in subsequent API calls.

Optional Parameters:

  • email (str): The email address of the customer. Must be a valid email format.
  • name (str): The name of the customer.
  • metadata (Dict[str, str]): A dictionary of custom key-value pairs to store additional information about the customer.

Returns: An instance of CustomerResponse (Pydantic model), representing the newly created customer record. Key attributes include:

  • id (str): The server-generated unique UUID for the customer record.
  • customerId (str): The client-provided customer identifier.
  • name (str): The customer’s name.
  • email (str): The customer’s email.
  • details ([Dict[str, Any]]): Any server-added details about the customer (typically read-only).
  • metadata ([Dict[str, Any]]): The metadata associated with the customer.
  • createdOn (string) : ISO 8601 timestamp of when the customer was created.
  • modifiedOn (string) : ISO 8601 timestamp of when the customer was last modified.

Checkout

The checkout module provides functionalities for creating and managing checkout sessions. You can access these operations via the checkout attribute on an initialized ParityDeals client instance.

create_session(...) This operation creates a new checkout session for a customer, allowing them to proceed with a purchase or subscription.

Synchronous:

response = client.checkout.create_session(
    planIdentifier="plan-pro-monthly",
    chargePeriod="MONTHLY",
    customerId="cust_789", // Recommended, otherwise it will create a new customer
    successUrl="https://paritydeals.com/checkout/success"
)
print(f"Checkout Session URL: {response.checkoutUrl}")

Asynchronous:

response = await async_client.checkout.create_session(
    planIdentifier="plan-pro-monthly",
    chargePeriod="MONTHLY",
    customerId="cust_789",
    successUrl="https://paritydeals.com/checkout/success",
    offeringId="96d3a293-34ac-48a5-b73d-976b15781afd",
    pricingTableId="6db2717a-4e43-4ae1-a293-6c0a775f6264",
    ruleId="f2ebc23f-3f79-4cf4-b17e-fe8e30a42ab2",
    features=[{'identifier':"seats", 'quantity': 5}],
    ipAddress="103.154.35.20",
)
print(f"Checkout Session URL: {response.checkoutUrl}")

Required Parameters:

  • planIdentifier (str): The identifier of the specific plan the customer is checking out with. planIdentifier is mandatory.

  • successUrl (str): The URL to which the user will be redirected after a successful checkout.

  • chargePeriod (str): Required. The billing cycle for the subscription. Must be one of:

    • "ONE_TIME"

    • "MONTHLY"

    • "YEARLY"

    • "WEEKLY"

    • "DAILY"

    • "THREE_MONTHS"

    • "SIX_MONTHS"

Optional Parameters:

  • offeringId (str): The ID (uuid) of the offering the customer is checking out with.

  • pricingTableId (str): Required. The id (uuid) of the pricingTable being used for this checkout. (Considered only if offeringId is not provided)

  • ruleId (str): Required. The id (uuid) of the pricing rule being applied. (Considered only if offeringId is not provided)

  • customerId (str): Required. The ID of the customer initiating the checkout. (If not provided, a new customer will be created)

  • features (List[Dict[str, Union[str, int]]]): Required. A list of dictionaries, where each dictionary represents a feature and its desired quantity. Each dictionary must have two keys:

    • "identifier" (str): The unique identifier for the feature.
    • "quantity" (int): The desired quantity for this feature.
      • Example: [{"identifier": "seats", "quantity": 10}, {"identifier": "api-calls-tier1", "quantity": 5000}]
  • ipAddress (str): The IP Address of the customer, used for location based pricing.

Returns:

An instance of CreateCheckoutSessionResponse (Pydantic model), which includes:

  • checkoutSessionId (str): The unique ID for the created checkout session.

  • checkoutUrl (str): The URL that the customer should be redirected to in order to complete the payment and activate the subscription/purchase.


Entitlements

The entitlements module allows you to check and retrieve customer entitlements for various features. These operations target a specific edge API endpoint (https://edge.api.paritydeals.com by default) and use the GET HTTP method with query parameters.

Checks if a specific customer has access to a particular feature.

This method directly returns a boolean indicating access status.

Synchronous:

has_feature_access = client.entitlements.has_access(
    customerId="cust_123",
    featureId="premium-reporting"
)

Asynchronous:

has_feature_access = await async_client.entitlements.has_access(
    customerId="cust_456",
    featureId="advanced-analytics"
)

Required Parameters:

  • customerId (str): The unique identifier for the customer.

  • featureId (str): The unique identifier for the feature whose access is being checked.

Returns:

  • bool: True if the customer has access to the specified feature (considering feature type, limits, etc.), False otherwise or if the feature is not found in their entitlements.

Retrieves the detailed entitlement information for a specific feature for a given customer.

Synchronous:

entitlement_response = client.entitlements.get_entitlement(
    customerId="cust_123",
    featureId="premium-reporting"
)

Asynchronous:

entitlement_response = await async_client.entitlements.get_entitlement(
    customerId="cust_456",
    featureId="advanced-analytics"
)

Required Parameters:

  • customerId (str): The unique identifier for the customer.

  • featureId (str): The unique identifier for the feature whose access is being checked.

Returns:

An instance of CheckEntitlementsResponse (Pydantic model). When querying for a specific featureId, the entitlements list within this response is typically expected to contain a single EntitlementDetail object corresponding to the requested feature if found. The structure includes:

  • customerId (str): The customer’s ID.

  • entitlements (List[EntitlementDetail]): A list containing the details for the requested feature. Each EntitlementDetail has fields like:

    • featureId: str

    • hasAccess: bool

    • featureType: str

    • resetAt: str

    • hardLimit: Optional[bool]

    • usageLimit: Optional[int]

    • currentUsage: Optional[int]

    • remaining: Optional[int]

Retrieves all entitlements for a given customer.

Synchronous:

all_entitlements_response = client.entitlements.get_all_entitlements(
    customerId="cust_123"
)

Asynchronous:

all_entitlements_response = await async_client.entitlements.get_all_entitlements(
    customerId="cust_456"
)

Required Parameters:

  • customerId (str): The unique identifier for the customer.

Returns:

  • customerId (str): The customer’s ID.

  • entitlements (List[EntitlementDetail]): A list containing the details for the requested feature. Each EntitlementDetail has fields like:

    • featureId: str

    • hasAccess: bool

    • featureType: str

    • resetAt: str

    • hardLimit: Optional[bool]

    • usageLimit: Optional[int]

    • currentUsage: Optional[int]

    • remaining: Optional[int]


Reporting

Reporting pre-aggregated usages for customer

This endpoint is used for reporting the pre-aggregated feature usage from your application (client-level) to the ParityDeals application. It allows you to update the usage count for a specific feature associated with a customer.

Synchronous:

# Assuming 'client' is your synchronous ParityDeals client
response = client.reporting.report_usage(
    value=150,
    customerId="customer_001",
    featureId="seats",
    behaviour="SET" # Or 'DELTA'
)

Asynchronous:

# Assuming 'async_client' is your asynchronous ParityDeals client
response = await async_client.reporting.report_usage(
    value=75,
    customerId="customer_001",
    featureId="seats",
    behaviour="DELTA"
)

Required Parameters:

  • value (int): The usage value being reported.

  • customerId (str): The unique identifier for the customer associated with this usage.

  • featureId (str): The unique identifier for the feature for which usage is being reported.

  • behaviour parameter dictates how the usage is updated:

    • SET: This will replace the current usage value for the feature with the new value provided.

    • DELTA: This will increment the existing usage value for the feature by the amount specified in the value parameter

Returns:

An instance of ReportUsageResponse (Pydantic model), which includes:

  • value (int): The usage value that was recorded.

  • customerId (str): The customer ID associated with the usage.

  • featureId (str): The feature Identifier for which usage was recorded.

  • behaviour (str): The behaviour type (“SET” or “DELTA”) that was processed.

  • orgId (str): The organization ID associated with this record, as determined by the server.

  • eventName (str): An internal event name generated by the server for this usage report (e.g., “aggregated.usage”).

  • idempotencyKey (str): A unique idempotency key generated by the server for this specific usage report instance.

  • timestamp (str): The server-generated UTC timestamp (str format) indicating when the usage report was processed.

Subscriptions

The subscriptions module allows you to manage customer subscriptions, including updates and cancellation. You can access these operations via the subscriptions attribute on an initialized ParityDeals client instance.

Updates an existing subscription to a new plan

Synchronous:

# Assuming 'client' is your synchronous ParityDeals client
try:
    response = client.subscriptions.update(
        subscriptionId="78058918-9746-4280-9b9b-1bd5115eec6e",
        planIdentifier="premium-plan",
        chargePeriod="MONTHLY",
    )
    print(response.subscriptionId)
except Exception as e:
    print(f"Error updating subscription: {e}")

Asynchronous:

# Assuming 'async_client' is your asynchronous ParityDeals client
try:
    response = await async_client.subscriptions.update(
        subscriptionId="78058918-9746-4280-9b9b-1bd5115eec6e",
        planIdentifier="new_plan_enterprise",
        chargePeriod="YEARLY",
        offeringId="offer_abc",
        pricingTableId="pw_def",
        ruleId="rule_ghi",
        ipAddress="103.154.35.20",
        features=[{'identifier': "seats", 'quantity': 10}]
    )
    print(response.subscriptionId)
except Exception as e:
    print(f"Error updating subscription: {e}")

Required Parameters:

  • subscriptionId (str): Required. The unique identifier of the subscription to be updated.
  • planIdentifier (str): Required. The identifier of the new plan.
  • chargePeriod (str): Required. The new charging period for the subscription. Must be one of:
    • "ONE_TIME"
    • "MONTHLY"
    • "YEARLY"
    • "WEEKLY"
    • "DAILY"
    • "THREE_MONTHS"
    • "SIX_MONTHS"

Optional Parameters:

  • offeringId (str): Optional. The ID of the new offering, if applicable.
  • pricingTableId (str): Optional. The ID of the new pricingTable, if applicable.
  • ruleId (str): Optional. The ID of the new pricing rule, if applicable.
  • ipAddress (str): The IP Address of the customer, used for location based pricing.
  • features ([List[Dict[str, Any]]]): Optional. A list of dictionaries, where each dictionary represents a feature and its desired quantity to update for the subscription. Each dictionary must have two keys:
    • "identifier" (str): The unique identifier for the feature.
    • "quantity" (int): The desired quantity for this feature.
      • Example: [{'identifier': 'seats', 'quantity': 10}, {'identifier': 'projects', 'quantity': 5}]

Returns:

An instance of UpdateSubscriptionResponse, which includes:

  • subscriptionId (str): UUID of the updated subscription.

Cancel an active subscription for a customer.

Synchronous:

# Assuming 'client' is your synchronous ParityDeals client
try:
    response = client.subscriptions.cancel(
        subscriptionId="78058918-9746-4280-9b9b-1bd5115eec6e",
        cancellationType="CURRENT_PERIOD_ENDS" # Or "IMMEDIATE", "SPECIFIC_DATE"
        # cancellationDate="2025-12-31" # Required if cancellationType is "SPECIFIC_DATE"
    )
    print(response.message)
except Exception as e:
    print(f"Error cancelling subscription: {e}")

Asynchronous:

# Assuming 'async_client' is your asynchronous ParityDeals client
try:
    response = await async_client.subscriptions.cancel(
        subscriptionId="78058918-9746-4280-9b9b-1bd5115eec6e",
        cancellationType="IMMEDIATE"
    )
    print(response.message)
except Exception as e:
    print(f"Error cancelling subscription: {e}")

Required Parameters:

  • subscriptionId (str): The unique identifier of the subscription to be cancelled.

  • cancellationType (str): The type of cancellation to perform. Must be one of:

    • "IMMEDIATE": The subscription is cancelled immediately.
    • "CURRENT_PERIOD_ENDS": The subscription will remain active until the end of the current billing period and then cancel.
    • "SPECIFIC_DATE": The subscription will be cancelled on the specified cancellationDate.
  • cancellationDate (str): The specific date for cancellation if cancellationType is "SPECIFIC_DATE". Must be in YYYY-MM-DD format. This parameter is required if cancellationType is "SPECIFIC_DATE".

Returns:

An instance of CancelSubscriptionResponse, which includes:

  • message (str): A confirmation message indicating the result of the cancellation request.