Python SDK
Documentation for the ParityDeals Python SDK
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:
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:
- Navigate to Settings.
- Go to the Developers section.
- 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).
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.
How to Create an Asynchronous Client
Use the asynchronous client for non-blocking I/O operations, suitable for applications using asyncio
.
Supported Functionalities
The SDK currently supports the following operations:
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:
Asynchronous:
Response
Response
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:
Asynchronous:
Response
Response
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:
Asynchronous:
Response
Response
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 ifofferingId
is not provided) -
ruleId
(str): Required. The id (uuid) of the pricing rule being applied. (Considered only ifofferingId
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}]
- Example:
-
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:
Asynchronous:
Response
Response
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:
Asynchronous:
Response
Response
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:
Asynchronous:
Response
Response
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:
Asynchronous:
Response
Response
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 newvalue
provided. -
DELTA
: This will increment the existing usage value for the feature by the amount specified in thevalue
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:
Asynchronous:
Response
Response
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}]
- Example:
Returns:
An instance of UpdateSubscriptionResponse
, which includes:
subscriptionId
(str): UUID of the updated subscription.
Cancel an active subscription for a customer.
Synchronous:
Asynchronous:
Response
Response
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 specifiedcancellationDate
.
-
cancellationDate
(str): The specific date for cancellation ifcancellationType
is"SPECIFIC_DATE"
. Must be inYYYY-MM-DD
format. This parameter is required ifcancellationType
is"SPECIFIC_DATE"
.
Returns:
An instance of CancelSubscriptionResponse
, which includes:
message
(str): A confirmation message indicating the result of the cancellation request.