subscription-sdk-python
Python SDK for the Subscription and Entitlements Platform.
Installation
pip install subscription-sdk
Middleware Adapters
Flask
from flask import Flask, request, jsonify
from subscription_sdk.adapters.flask_adapter import subscription_flask
app = Flask(__name__)
# Apply Flask Middleware
subscription_flask(
app,
api_key="sub_live_...",
base_url="https://api.infosub.io",
get_org_id=lambda: request.headers.get("X-Org-Id")
)
@app.route("/api/v1/employees", methods=["GET"])
def get_employees():
return jsonify({"data": []}), 200
FastAPI
from fastapi import FastAPI, Request
from subscription_sdk.adapters.fastapi_adapter import SubscriptionMiddleware
app = FastAPI()
# Apply FastAPI Middleware
app.add_middleware(
SubscriptionMiddleware,
api_key="sub_live_...",
base_url="https://api.infosub.io",
get_org_id=lambda req: req.headers.get("x-org-id")
)
@app.get("/api/v1/employees")
def get_employees(request: Request):
return {"data": []}
Manual Client Usage
from subscription_sdk import SubscriptionClient
client = SubscriptionClient(api_key="sub_live_...", base_url="https://api.infosub.io")
client.start() # Starts background poller thread
mapping = client.match_route("GET", "/api/v1/employees")
if mapping:
check = client.check_entitlement(
organization_external_id="tenant-acme",
resource_mapping_id=mapping.id,
quantity=1.0
)
if check.allowed:
try:
# Execute business logic...
client.commit_reservation(check.reservationId)
except Exception:
client.cancel_reservation(check.reservationId)
Alternatively, you can simplify the manual transaction pattern using .execute(...), which handles the check-reserve-commit-cancel flow automatically.
Basic Example:
# The execute method takes a callback function to run
result = client.execute(
organization_id="tenant-acme",
resource_mapping_id=mapping.id,
callback=lambda: save_employee(employee),
quantity=1.0
)
Flask / FastAPI Route Handler Example:
@app.route("/employees-manual", methods=["POST"])
def create_employee_manual():
org_id = request.headers.get("X-Org-Id") or request.args.get("orgId")
mapping = client.match_route("POST", "/employees")
if not mapping:
return jsonify({"error": "Mapping not found"}), 500
try:
result = client.execute(
organization_id=org_id,
resource_mapping_id=mapping.id,
quantity=1.0,
callback=lambda: {
"status": "success",
"message": "Employee created successfully via manual execute wrapper."
}
)
return jsonify(result), 200
except PermissionError as err:
# Throws PermissionError if entitlement check is denied (check.allowed is False)
return jsonify({"status": "error", "message": str(err)}), 403
except Exception as err:
return jsonify({"status": "error", "message": str(err)}), 500
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
subscription_sdk-1.0.0.tar.gz
(13.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file subscription_sdk-1.0.0.tar.gz.
File metadata
- Download URL: subscription_sdk-1.0.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dad5be3eba72888c9e543b27729da765a869036cee8cf9ba2d688c6dbff567bd
|
|
| MD5 |
8fe91b1f164f1878dab22312efc6b32e
|
|
| BLAKE2b-256 |
691857bd54925389bc747be641955894e3f8b8a3d28db53324ce12f2203c10d4
|
File details
Details for the file subscription_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: subscription_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bbd2fc54c539ca97c14e380ae4947deb9d0581a7d21bb0ac0ddb495cb939c7e
|
|
| MD5 |
d0f6b35d99275855f08913d72c741504
|
|
| BLAKE2b-256 |
5245bd3c82029e7a8380b0a4f787a4d03d1c6e95181810276bbec3bcf1cdf13c
|