commet-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Commet
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: commet-sdk
3
+ Version: 0.1.0
4
+ Summary: Commet SDK for Python - Billing and usage tracking for SaaS
5
+ Author: Commet Team
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://commet.co
8
+ Project-URL: Repository, https://github.com/commet-labs/commet-python
9
+ Keywords: billing,sdk,payments,invoicing,usage-based-billing,seat-licensing
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: httpx>=0.27
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest; extra == "dev"
25
+ Requires-Dist: ruff; extra == "dev"
26
+ Requires-Dist: mypy; extra == "dev"
27
+ Requires-Dist: respx; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # Commet Python SDK
31
+
32
+ Billing and usage tracking for SaaS applications.
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install commet
38
+ ```
39
+
40
+ ## Quick start
41
+
42
+ ```python
43
+ from commet import Commet
44
+
45
+ commet = Commet(api_key="ck_xxx", environment="production")
46
+
47
+ # Create a customer
48
+ commet.customers.create(email="user@example.com", external_id="user_123")
49
+
50
+ # Create a subscription
51
+ commet.subscriptions.create(external_id="user_123", plan_code="pro")
52
+
53
+ # Track usage
54
+ commet.usage.track(feature="api_calls", external_id="user_123")
55
+
56
+ # Track AI token usage
57
+ commet.usage.track(
58
+ feature="ai_generation",
59
+ external_id="user_123",
60
+ model="claude-sonnet-4-20250514",
61
+ input_tokens=1000,
62
+ output_tokens=500,
63
+ )
64
+ ```
65
+
66
+ ## Customer context
67
+
68
+ Scope all operations to a customer to avoid repeating `external_id`:
69
+
70
+ ```python
71
+ customer = commet.customer("user_123")
72
+
73
+ customer.usage.track("api_calls")
74
+ customer.features.check("custom_branding")
75
+ customer.seats.add("editor", count=3)
76
+ customer.portal.get_url()
77
+ ```
78
+
79
+ ## Webhook verification
80
+
81
+ ```python
82
+ from commet import Webhooks
83
+
84
+ webhooks = Webhooks()
85
+
86
+ payload = webhooks.verify_and_parse(
87
+ raw_body=request_body,
88
+ signature=request.headers["x-commet-signature"],
89
+ secret="whsec_xxx",
90
+ )
91
+
92
+ if payload is None:
93
+ raise ValueError("Invalid webhook signature")
94
+
95
+ if payload["event"] == "subscription.activated":
96
+ # handle activation
97
+ pass
98
+ ```
99
+
100
+ ## Context manager
101
+
102
+ ```python
103
+ with Commet(api_key="ck_xxx") as commet:
104
+ commet.usage.track(feature="api_calls", external_id="user_123")
105
+ # connection pool is automatically closed
106
+ ```
107
+
108
+ ## Environments
109
+
110
+ The SDK defaults to `sandbox`. Set `environment="production"` for live operations:
111
+
112
+ ```python
113
+ commet = Commet(api_key="ck_xxx", environment="production")
114
+ ```
115
+
116
+ ## License
117
+
118
+ MIT
@@ -0,0 +1,89 @@
1
+ # Commet Python SDK
2
+
3
+ Billing and usage tracking for SaaS applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install commet
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ```python
14
+ from commet import Commet
15
+
16
+ commet = Commet(api_key="ck_xxx", environment="production")
17
+
18
+ # Create a customer
19
+ commet.customers.create(email="user@example.com", external_id="user_123")
20
+
21
+ # Create a subscription
22
+ commet.subscriptions.create(external_id="user_123", plan_code="pro")
23
+
24
+ # Track usage
25
+ commet.usage.track(feature="api_calls", external_id="user_123")
26
+
27
+ # Track AI token usage
28
+ commet.usage.track(
29
+ feature="ai_generation",
30
+ external_id="user_123",
31
+ model="claude-sonnet-4-20250514",
32
+ input_tokens=1000,
33
+ output_tokens=500,
34
+ )
35
+ ```
36
+
37
+ ## Customer context
38
+
39
+ Scope all operations to a customer to avoid repeating `external_id`:
40
+
41
+ ```python
42
+ customer = commet.customer("user_123")
43
+
44
+ customer.usage.track("api_calls")
45
+ customer.features.check("custom_branding")
46
+ customer.seats.add("editor", count=3)
47
+ customer.portal.get_url()
48
+ ```
49
+
50
+ ## Webhook verification
51
+
52
+ ```python
53
+ from commet import Webhooks
54
+
55
+ webhooks = Webhooks()
56
+
57
+ payload = webhooks.verify_and_parse(
58
+ raw_body=request_body,
59
+ signature=request.headers["x-commet-signature"],
60
+ secret="whsec_xxx",
61
+ )
62
+
63
+ if payload is None:
64
+ raise ValueError("Invalid webhook signature")
65
+
66
+ if payload["event"] == "subscription.activated":
67
+ # handle activation
68
+ pass
69
+ ```
70
+
71
+ ## Context manager
72
+
73
+ ```python
74
+ with Commet(api_key="ck_xxx") as commet:
75
+ commet.usage.track(feature="api_calls", external_id="user_123")
76
+ # connection pool is automatically closed
77
+ ```
78
+
79
+ ## Environments
80
+
81
+ The SDK defaults to `sandbox`. Set `environment="production"` for live operations:
82
+
83
+ ```python
84
+ commet = Commet(api_key="ck_xxx", environment="production")
85
+ ```
86
+
87
+ ## License
88
+
89
+ MIT
@@ -0,0 +1,52 @@
1
+ [project]
2
+ name = "commet-sdk"
3
+ version = "0.1.0"
4
+ description = "Commet SDK for Python - Billing and usage tracking for SaaS"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.9"
8
+ authors = [{ name = "Commet Team" }]
9
+ keywords = [
10
+ "billing",
11
+ "sdk",
12
+ "payments",
13
+ "invoicing",
14
+ "usage-based-billing",
15
+ "seat-licensing",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Typing :: Typed",
27
+ ]
28
+ dependencies = ["httpx>=0.27"]
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pytest", "ruff", "mypy", "respx"]
32
+
33
+ [project.urls]
34
+ Homepage = "https://commet.co"
35
+ Repository = "https://github.com/commet-labs/commet-python"
36
+
37
+ [build-system]
38
+ requires = ["setuptools>=68", "wheel"]
39
+ build-backend = "setuptools.build_meta"
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [tool.ruff]
45
+ line-length = 100
46
+ target-version = "py39"
47
+
48
+ [tool.ruff.lint]
49
+ select = ["E", "F", "I", "UP"]
50
+
51
+ [tool.pytest.ini_options]
52
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,21 @@
1
+ from ._exceptions import CommetAPIError, CommetError, CommetValidationError
2
+ from ._http import ApiResponse
3
+ from .client import Commet
4
+ from .resources.webhooks import Webhooks
5
+
6
+ try:
7
+ from importlib.metadata import version
8
+
9
+ __version__ = version("commet")
10
+ except Exception:
11
+ __version__ = "0.1.0"
12
+
13
+ __all__ = [
14
+ "__version__",
15
+ "ApiResponse",
16
+ "Commet",
17
+ "CommetAPIError",
18
+ "CommetError",
19
+ "CommetValidationError",
20
+ "Webhooks",
21
+ ]
@@ -0,0 +1,119 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ._http import ApiResponse
7
+ from .resources.features import FeaturesResource
8
+ from .resources.portal import PortalResource
9
+ from .resources.seats import SeatsResource
10
+ from .resources.subscriptions import SubscriptionsResource
11
+ from .resources.usage import UsageResource
12
+
13
+
14
+ class CustomerContext:
15
+ """Customer-scoped API context.
16
+
17
+ All operations are automatically scoped to the customer's external_id.
18
+
19
+ Usage::
20
+
21
+ customer = commet.customer("user_123")
22
+
23
+ customer.features.get("team_members")
24
+ customer.seats.add("editor")
25
+ customer.usage.track("api_calls")
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ external_id: str,
31
+ *,
32
+ features: FeaturesResource,
33
+ seats: SeatsResource,
34
+ usage: UsageResource,
35
+ subscriptions: SubscriptionsResource,
36
+ portal: PortalResource,
37
+ ) -> None:
38
+ self._external_id = external_id
39
+ self.features = _CustomerFeatures(external_id, features)
40
+ self.seats = _CustomerSeats(external_id, seats)
41
+ self.usage = _CustomerUsage(external_id, usage)
42
+ self.subscription = _CustomerSubscription(external_id, subscriptions)
43
+ self.portal = _CustomerPortal(external_id, portal)
44
+
45
+
46
+ class _CustomerFeatures:
47
+ def __init__(self, external_id: str, resource: FeaturesResource) -> None:
48
+ self._external_id = external_id
49
+ self._resource = resource
50
+
51
+ def get(self, code: str) -> ApiResponse:
52
+ return self._resource.get(code=code, external_id=self._external_id)
53
+
54
+ def check(self, code: str) -> ApiResponse:
55
+ return self._resource.check(code=code, external_id=self._external_id)
56
+
57
+ def can_use(self, code: str) -> ApiResponse:
58
+ return self._resource.can_use(code=code, external_id=self._external_id)
59
+
60
+ def list(self) -> ApiResponse:
61
+ return self._resource.list(self._external_id)
62
+
63
+
64
+ class _CustomerSeats:
65
+ def __init__(self, external_id: str, resource: SeatsResource) -> None:
66
+ self._external_id = external_id
67
+ self._resource = resource
68
+
69
+ def add(self, seat_type: str, count: int = 1) -> ApiResponse:
70
+ return self._resource.add(
71
+ seat_type=seat_type, count=count, external_id=self._external_id
72
+ )
73
+
74
+ def remove(self, seat_type: str, count: int = 1) -> ApiResponse:
75
+ return self._resource.remove(
76
+ seat_type=seat_type, count=count, external_id=self._external_id
77
+ )
78
+
79
+ def set(self, seat_type: str, count: int) -> ApiResponse:
80
+ return self._resource.set(
81
+ seat_type=seat_type, count=count, external_id=self._external_id
82
+ )
83
+
84
+ def get_balance(self, seat_type: str) -> ApiResponse:
85
+ return self._resource.get_balance(seat_type=seat_type, external_id=self._external_id)
86
+
87
+
88
+ class _CustomerUsage:
89
+ def __init__(self, external_id: str, resource: UsageResource) -> None:
90
+ self._external_id = external_id
91
+ self._resource = resource
92
+
93
+ def track(
94
+ self,
95
+ feature: str,
96
+ value: int | None = None,
97
+ properties: dict[str, str] | None = None,
98
+ ) -> ApiResponse:
99
+ return self._resource.track(
100
+ feature=feature, external_id=self._external_id, value=value, properties=properties
101
+ )
102
+
103
+
104
+ class _CustomerSubscription:
105
+ def __init__(self, external_id: str, resource: SubscriptionsResource) -> None:
106
+ self._external_id = external_id
107
+ self._resource = resource
108
+
109
+ def get(self) -> ApiResponse:
110
+ return self._resource.get(self._external_id)
111
+
112
+
113
+ class _CustomerPortal:
114
+ def __init__(self, external_id: str, resource: PortalResource) -> None:
115
+ self._external_id = external_id
116
+ self._resource = resource
117
+
118
+ def get_url(self) -> ApiResponse:
119
+ return self._resource.get_url(external_id=self._external_id)
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+
4
+ class CommetError(Exception):
5
+ def __init__(
6
+ self,
7
+ message: str,
8
+ *,
9
+ code: str | None = None,
10
+ status_code: int | None = None,
11
+ details: object = None,
12
+ ) -> None:
13
+ super().__init__(message)
14
+ self.code = code
15
+ self.status_code = status_code
16
+ self.details = details
17
+
18
+
19
+ class CommetAPIError(CommetError):
20
+ def __init__(
21
+ self,
22
+ message: str,
23
+ *,
24
+ status_code: int,
25
+ code: str | None = None,
26
+ details: object = None,
27
+ ) -> None:
28
+ super().__init__(message, code=code, status_code=status_code, details=details)
29
+
30
+
31
+ class CommetValidationError(CommetError):
32
+ def __init__(
33
+ self,
34
+ message: str,
35
+ *,
36
+ validation_errors: dict[str, list[str]],
37
+ ) -> None:
38
+ super().__init__(message)
39
+ self.validation_errors = validation_errors