post-analytics-python 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.
- post_analytics_python-0.1.0/LICENSE +23 -0
- post_analytics_python-0.1.0/PKG-INFO +75 -0
- post_analytics_python-0.1.0/README.md +52 -0
- post_analytics_python-0.1.0/pyproject.toml +38 -0
- post_analytics_python-0.1.0/setup.cfg +4 -0
- post_analytics_python-0.1.0/src/post_analytics/__init__.py +5 -0
- post_analytics_python-0.1.0/src/post_analytics/client.py +70 -0
- post_analytics_python-0.1.0/src/post_analytics/py.typed +1 -0
- post_analytics_python-0.1.0/src/post_analytics_python.egg-info/PKG-INFO +75 -0
- post_analytics_python-0.1.0/src/post_analytics_python.egg-info/SOURCES.txt +10 -0
- post_analytics_python-0.1.0/src/post_analytics_python.egg-info/dependency_links.txt +1 -0
- post_analytics_python-0.1.0/src/post_analytics_python.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
CREDVAULT POST ANALYTICS SDK LICENSE
|
|
2
|
+
Version 1.0 — 1 December 2026
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 CredVault. All rights reserved.
|
|
5
|
+
|
|
6
|
+
This license applies only to the CredVault Post Analytics SDK package that includes this file (the “SDK”). It does not license the Post hosted service, APIs, documentation, or any third-party component.
|
|
7
|
+
|
|
8
|
+
1. Permission to use
|
|
9
|
+
CredVault grants you a non-exclusive, worldwide, royalty-free, non-transferable license to download, install, run, copy, and modify the SDK as reasonably necessary to develop, build, test, and operate your applications that integrate with the Post Analytics service. You may distribute the SDK only as incorporated into your application or as a dependency needed to build that application. You may not sell, sublicense, or distribute the SDK as a standalone product or package, or remove its copyright and license notices.
|
|
10
|
+
|
|
11
|
+
2. Ownership and third-party materials
|
|
12
|
+
CredVault and its licensors retain all rights in the SDK except for the limited permission in section 1. Third-party materials included in a package remain subject to their own license notices and terms; this license does not replace those terms.
|
|
13
|
+
|
|
14
|
+
3. Service access
|
|
15
|
+
This license does not grant an account, API access, or any right to use the Post hosted service. Those are governed by the applicable Post service terms and account plan.
|
|
16
|
+
|
|
17
|
+
4. Ending the license
|
|
18
|
+
The license ends if you materially breach it and do not correct the breach within 30 days after receiving written notice from CredVault. When it ends, stop using the SDK and remove standalone copies, except copies retained in application releases already distributed under section 1.
|
|
19
|
+
|
|
20
|
+
5. Disclaimer
|
|
21
|
+
The SDK is provided “as is” and “as available,” without warranties, to the maximum extent permitted by applicable law. Nothing in this license excludes a warranty or liability that cannot legally be excluded.
|
|
22
|
+
|
|
23
|
+
For questions about these terms, contact support@credvault.net.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: post-analytics-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: First-party Post Analytics SDK for Python
|
|
5
|
+
Author: CredVault
|
|
6
|
+
License-Expression: LicenseRef-CredVault-Post-Analytics-SDK
|
|
7
|
+
Project-URL: Homepage, https://post.credvault.net/
|
|
8
|
+
Project-URL: Source, https://github.com/CREDVAULTHQ/CredVault-DB/tree/main/post-anayltics/packages/post-analytics-python
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Post Analytics Python SDK
|
|
25
|
+
|
|
26
|
+
CredVault's synchronous Python client for sending events, identifying users, and loading feature flags from Post Analytics.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
python -m pip install post-analytics-python
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Requires Python 3.10 or newer. The SDK uses Python's standard library and has no runtime dependencies.
|
|
35
|
+
|
|
36
|
+
## Configure and send an event
|
|
37
|
+
|
|
38
|
+
Set the project key and Post ingestion host in your server environment. Keep the project key out of browser and mobile code.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
export POST_PROJECT_API_KEY="your-project-key"
|
|
42
|
+
export POST_ANALYTICS_HOST="https://post.credvault.net"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import os
|
|
47
|
+
|
|
48
|
+
from post_analytics import PostAnalytics
|
|
49
|
+
|
|
50
|
+
post = PostAnalytics(
|
|
51
|
+
api_key=os.environ["POST_PROJECT_API_KEY"],
|
|
52
|
+
host=os.environ["POST_ANALYTICS_HOST"],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
post.capture(
|
|
56
|
+
"invoice_paid",
|
|
57
|
+
distinct_id="customer-123",
|
|
58
|
+
properties={"amount": 49.50, "currency": "USD"},
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`api_key` and `host` can also be omitted from the constructor to read `POST_PROJECT_API_KEY` and `POST_ANALYTICS_HOST` from the environment.
|
|
63
|
+
|
|
64
|
+
## Identify users and load feature flags
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
post.identify("customer-123", anonymous_id="visitor-456", properties={"plan": "team"})
|
|
68
|
+
flags = post.load_feature_flags("customer-123")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Requests use Post's `/i/v0/e/` event-ingestion endpoint and `/flags/?v=2` feature-flags endpoint. Network and HTTP failures raise `PostAnalyticsError`.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
This SDK is distributed under the CredVault Post Analytics SDK license included in [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Post Analytics Python SDK
|
|
2
|
+
|
|
3
|
+
CredVault's synchronous Python client for sending events, identifying users, and loading feature flags from Post Analytics.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install post-analytics-python
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Python 3.10 or newer. The SDK uses Python's standard library and has no runtime dependencies.
|
|
12
|
+
|
|
13
|
+
## Configure and send an event
|
|
14
|
+
|
|
15
|
+
Set the project key and Post ingestion host in your server environment. Keep the project key out of browser and mobile code.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
export POST_PROJECT_API_KEY="your-project-key"
|
|
19
|
+
export POST_ANALYTICS_HOST="https://post.credvault.net"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import os
|
|
24
|
+
|
|
25
|
+
from post_analytics import PostAnalytics
|
|
26
|
+
|
|
27
|
+
post = PostAnalytics(
|
|
28
|
+
api_key=os.environ["POST_PROJECT_API_KEY"],
|
|
29
|
+
host=os.environ["POST_ANALYTICS_HOST"],
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
post.capture(
|
|
33
|
+
"invoice_paid",
|
|
34
|
+
distinct_id="customer-123",
|
|
35
|
+
properties={"amount": 49.50, "currency": "USD"},
|
|
36
|
+
)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`api_key` and `host` can also be omitted from the constructor to read `POST_PROJECT_API_KEY` and `POST_ANALYTICS_HOST` from the environment.
|
|
40
|
+
|
|
41
|
+
## Identify users and load feature flags
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
post.identify("customer-123", anonymous_id="visitor-456", properties={"plan": "team"})
|
|
45
|
+
flags = post.load_feature_flags("customer-123")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Requests use Post's `/i/v0/e/` event-ingestion endpoint and `/flags/?v=2` feature-flags endpoint. Network and HTTP failures raise `PostAnalyticsError`.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
This SDK is distributed under the CredVault Post Analytics SDK license included in [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "post-analytics-python"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "First-party Post Analytics SDK for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "LicenseRef-CredVault-Post-Analytics-SDK"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "CredVault" }]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Programming Language :: Python :: 3.14",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://post.credvault.net/"
|
|
29
|
+
Source = "https://github.com/CREDVAULTHQ/CredVault-DB/tree/main/post-anayltics/packages/post-analytics-python"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools]
|
|
32
|
+
package-dir = {"" = "src"}
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.setuptools.package-data]
|
|
38
|
+
post_analytics = ["py.typed"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import urllib.error
|
|
6
|
+
import urllib.request
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PostAnalyticsError(RuntimeError):
|
|
12
|
+
"""Raised when the Post Analytics ingestion service rejects a request."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PostAnalytics:
|
|
16
|
+
"""Small synchronous client for Post Analytics' event and feature-flag APIs."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, api_key: str | None = None, host: str | None = None, timeout: float = 10.0):
|
|
19
|
+
self.api_key = (api_key or os.getenv("POST_PROJECT_API_KEY", "")).strip()
|
|
20
|
+
self.host = (host or os.getenv("POST_ANALYTICS_HOST", "")).strip().rstrip("/")
|
|
21
|
+
if not self.api_key:
|
|
22
|
+
raise ValueError("api_key or POST_PROJECT_API_KEY is required")
|
|
23
|
+
if not self.host.startswith(("https://", "http://")):
|
|
24
|
+
raise ValueError("host or POST_ANALYTICS_HOST must be an absolute HTTP(S) URL")
|
|
25
|
+
if timeout <= 0:
|
|
26
|
+
raise ValueError("timeout must be greater than zero")
|
|
27
|
+
self.timeout = timeout
|
|
28
|
+
|
|
29
|
+
def capture(self, event: str, distinct_id: str, properties: dict[str, Any] | None = None) -> None:
|
|
30
|
+
if not event.strip() or not distinct_id:
|
|
31
|
+
raise ValueError("event and distinct_id are required")
|
|
32
|
+
self._post("/i/v0/e/", {
|
|
33
|
+
"api_key": self.api_key,
|
|
34
|
+
"event": event,
|
|
35
|
+
"distinct_id": distinct_id,
|
|
36
|
+
"properties": {**(properties or {}), "$lib": "post-analytics-python", "$lib_version": "0.1.0"},
|
|
37
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
def identify(self, user_id: str, anonymous_id: str | None = None, properties: dict[str, Any] | None = None) -> None:
|
|
41
|
+
if not user_id:
|
|
42
|
+
raise ValueError("user_id is required")
|
|
43
|
+
fields: dict[str, Any] = {"$set": properties or {}}
|
|
44
|
+
if anonymous_id:
|
|
45
|
+
fields["$anon_distinct_id"] = anonymous_id
|
|
46
|
+
self.capture("$identify", user_id, fields)
|
|
47
|
+
|
|
48
|
+
def load_feature_flags(self, distinct_id: str, groups: dict[str, str] | None = None) -> dict[str, Any]:
|
|
49
|
+
if not distinct_id:
|
|
50
|
+
raise ValueError("distinct_id is required")
|
|
51
|
+
return self._post("/flags/?v=2", {
|
|
52
|
+
"api_key": self.api_key,
|
|
53
|
+
"distinct_id": distinct_id,
|
|
54
|
+
**({"groups": groups} if groups else {}),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
def _post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
|
|
58
|
+
body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
|
|
59
|
+
request = urllib.request.Request(
|
|
60
|
+
f"{self.host}{path}", body, {"Content-Type": "application/json", "Accept": "application/json"}, method="POST"
|
|
61
|
+
)
|
|
62
|
+
try:
|
|
63
|
+
with urllib.request.urlopen(request, timeout=self.timeout) as response:
|
|
64
|
+
content = response.read()
|
|
65
|
+
return json.loads(content) if content else {}
|
|
66
|
+
except urllib.error.HTTPError as error:
|
|
67
|
+
detail = error.read().decode("utf-8", errors="replace")
|
|
68
|
+
raise PostAnalyticsError(f"Post Analytics returned HTTP {error.code}: {detail[:500]}") from error
|
|
69
|
+
except urllib.error.URLError as error:
|
|
70
|
+
raise PostAnalyticsError(f"Could not reach Post Analytics: {error.reason}") from error
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: post-analytics-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: First-party Post Analytics SDK for Python
|
|
5
|
+
Author: CredVault
|
|
6
|
+
License-Expression: LicenseRef-CredVault-Post-Analytics-SDK
|
|
7
|
+
Project-URL: Homepage, https://post.credvault.net/
|
|
8
|
+
Project-URL: Source, https://github.com/CREDVAULTHQ/CredVault-DB/tree/main/post-anayltics/packages/post-analytics-python
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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: Programming Language :: Python :: 3.14
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Post Analytics Python SDK
|
|
25
|
+
|
|
26
|
+
CredVault's synchronous Python client for sending events, identifying users, and loading feature flags from Post Analytics.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
python -m pip install post-analytics-python
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Requires Python 3.10 or newer. The SDK uses Python's standard library and has no runtime dependencies.
|
|
35
|
+
|
|
36
|
+
## Configure and send an event
|
|
37
|
+
|
|
38
|
+
Set the project key and Post ingestion host in your server environment. Keep the project key out of browser and mobile code.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
export POST_PROJECT_API_KEY="your-project-key"
|
|
42
|
+
export POST_ANALYTICS_HOST="https://post.credvault.net"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import os
|
|
47
|
+
|
|
48
|
+
from post_analytics import PostAnalytics
|
|
49
|
+
|
|
50
|
+
post = PostAnalytics(
|
|
51
|
+
api_key=os.environ["POST_PROJECT_API_KEY"],
|
|
52
|
+
host=os.environ["POST_ANALYTICS_HOST"],
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
post.capture(
|
|
56
|
+
"invoice_paid",
|
|
57
|
+
distinct_id="customer-123",
|
|
58
|
+
properties={"amount": 49.50, "currency": "USD"},
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`api_key` and `host` can also be omitted from the constructor to read `POST_PROJECT_API_KEY` and `POST_ANALYTICS_HOST` from the environment.
|
|
63
|
+
|
|
64
|
+
## Identify users and load feature flags
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
post.identify("customer-123", anonymous_id="visitor-456", properties={"plan": "team"})
|
|
68
|
+
flags = post.load_feature_flags("customer-123")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Requests use Post's `/i/v0/e/` event-ingestion endpoint and `/flags/?v=2` feature-flags endpoint. Network and HTTP failures raise `PostAnalyticsError`.
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
This SDK is distributed under the CredVault Post Analytics SDK license included in [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/post_analytics/__init__.py
|
|
5
|
+
src/post_analytics/client.py
|
|
6
|
+
src/post_analytics/py.typed
|
|
7
|
+
src/post_analytics_python.egg-info/PKG-INFO
|
|
8
|
+
src/post_analytics_python.egg-info/SOURCES.txt
|
|
9
|
+
src/post_analytics_python.egg-info/dependency_links.txt
|
|
10
|
+
src/post_analytics_python.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
post_analytics
|