political-comms 0.2.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.
- political_comms-0.2.0/.gitignore +14 -0
- political_comms-0.2.0/LICENSE +21 -0
- political_comms-0.2.0/PKG-INFO +149 -0
- political_comms-0.2.0/README.md +122 -0
- political_comms-0.2.0/pyproject.toml +40 -0
- political_comms-0.2.0/src/political_comms/__init__.py +13 -0
- political_comms-0.2.0/src/political_comms/_client.py +630 -0
- political_comms-0.2.0/src/political_comms/_errors.py +24 -0
- political_comms-0.2.0/src/political_comms/py.typed +0 -0
- political_comms-0.2.0/tests/test_client.py +472 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Political Comms
|
|
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,149 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: political-comms
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python SDK for the Political Comms REST API. Direct-to-carrier political texting for campaigns, PACs, advocacy organizations, fundraisers, and elected officials.
|
|
5
|
+
Project-URL: Homepage, https://politicalcomms.com/
|
|
6
|
+
Project-URL: Documentation, https://docs.politicalcomms.com/api-reference/introduction
|
|
7
|
+
Project-URL: Repository, https://github.com/Political-Comms/political-comms-sdk
|
|
8
|
+
Author-email: Political Comms <support@politicalcomms.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,political comms,political texting,sdk,sms
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Communications :: Telephony
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# political-comms
|
|
29
|
+
|
|
30
|
+
Python SDK for the [Political Comms](https://politicalcomms.com/) REST API. Direct-to-carrier political texting for campaigns, PACs, advocacy organizations, fundraisers, and elected officials.
|
|
31
|
+
|
|
32
|
+
Synchronous client built on httpx. Python 3.10 or later.
|
|
33
|
+
|
|
34
|
+
The full API reference lives at [docs.politicalcomms.com](https://docs.politicalcomms.com/api-reference/introduction) and the OpenAPI 3.1 specification at [politicalcomms.com/openapi.json](https://politicalcomms.com/openapi.json).
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install political-comms
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Authentication
|
|
43
|
+
|
|
44
|
+
Requests authenticate with an API key in the `X-API-Key` header. Keys are created in the dashboard under Admin > API Keys and are prefixed `pc_live_`.
|
|
45
|
+
|
|
46
|
+
Set the key in the environment:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export POLITICAL_COMMS_API_KEY=pc_live_...
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from political_comms import PoliticalCommsClient
|
|
54
|
+
|
|
55
|
+
client = PoliticalCommsClient()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or pass it to the constructor:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
client = PoliticalCommsClient(api_key="pc_live_...")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Quickstart
|
|
65
|
+
|
|
66
|
+
Verify the credential, then run the standard send workflow: create a project, send yourself a test, and schedule it.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from political_comms import PoliticalCommsClient
|
|
70
|
+
|
|
71
|
+
client = PoliticalCommsClient()
|
|
72
|
+
|
|
73
|
+
# 1. Verify the credential.
|
|
74
|
+
orgs = client.list_organizations()
|
|
75
|
+
print([org.get("display_name") for org in orgs["data"]])
|
|
76
|
+
|
|
77
|
+
# 2. Create a project.
|
|
78
|
+
created = client.create_project(
|
|
79
|
+
organization_id="org_...",
|
|
80
|
+
name="GOTV reminder",
|
|
81
|
+
protocol="sms",
|
|
82
|
+
message_text="Polls are open until 8pm. Find your polling place: {link}",
|
|
83
|
+
phone_number_ids=["pn_..."],
|
|
84
|
+
contact_list_ids=["cl_..."],
|
|
85
|
+
brand_id="brand_...",
|
|
86
|
+
campaign_id="camp_...",
|
|
87
|
+
)
|
|
88
|
+
project_id = created["data"]["id"]
|
|
89
|
+
|
|
90
|
+
# 3. Send a test to yourself.
|
|
91
|
+
client.test_project(project_id, [{"phone": "+15555550100"}])
|
|
92
|
+
|
|
93
|
+
# 4. Schedule the send.
|
|
94
|
+
client.schedule_project(project_id, "2026-11-03T09:00:00", "America/New_York")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
One method exists per API operation, in snake_case: `list_organizations`, `get_hierarchy`, `list_brands`, `list_campaigns`, `list_tracking_domains`, `list_phone_numbers`, `list_toll_free_verifications`, `get_toll_free_verification`, `list_contact_lists`, `get_contact_list`, `import_contact_list`, `analyze_contact_list`, `delete_contact_list`, `list_media`, `import_media`, `get_media`, `delete_media`, `list_projects`, `create_project`, `get_all_project_stats`, `get_project`, `update_project`, `get_project_stats`, `test_project`, `schedule_project`, `unschedule_project`, `copy_project`, `archive_project`, `get_message_stats`, `get_ledger_usage`, `get_ledger_usage_by_initiator`.
|
|
98
|
+
|
|
99
|
+
Every method returns the parsed JSON response, a dict of the form `{"success": True, "data": ...}`.
|
|
100
|
+
|
|
101
|
+
## Error handling
|
|
102
|
+
|
|
103
|
+
Non-success responses raise `PoliticalCommsError` with the API's machine readable `code`, the HTTP `status_code`, and the raw response `body`.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from political_comms import PoliticalCommsClient, PoliticalCommsError
|
|
107
|
+
|
|
108
|
+
client = PoliticalCommsClient()
|
|
109
|
+
try:
|
|
110
|
+
client.get_project("proj_unknown")
|
|
111
|
+
except PoliticalCommsError as err:
|
|
112
|
+
print(err.code, err.status_code, err)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Network failures raise `PoliticalCommsError` with `code == "NETWORK_ERROR"` and `status_code == 0`.
|
|
116
|
+
|
|
117
|
+
## Retries
|
|
118
|
+
|
|
119
|
+
The client retries automatically with these rules:
|
|
120
|
+
|
|
121
|
+
- `400`, `401`, `403`, `404` are never retried.
|
|
122
|
+
- `429` is retried after waiting until the `X-RateLimit-Reset` timestamp.
|
|
123
|
+
- `500`, `502`, `503`, `504` are retried with exponential backoff and jitter: 1 second base, 60 second cap, at most 5 attempts total.
|
|
124
|
+
|
|
125
|
+
Configure the retry budget with `max_retries` (retries after the first attempt, default 4):
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
client = PoliticalCommsClient(max_retries=2)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Every `POST` and `PATCH` request carries an `Idempotency-Key` header (a random UUID) so retries are safe; the API returns the cached first response when a key is replayed. `DELETE` requests send the header only when you supply a key. Supply your own key per call when you need cross-process deduplication:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
client.create_project(..., idempotency_key="send-2026-11-03-wave-1")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Rate limits
|
|
138
|
+
|
|
139
|
+
The API allows, per key over a 60-second sliding window, 100 requests/minute for reads, 60/minute for writes, and 30/minute for deletes. The client exposes the most recent rate limit headers:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
client.list_organizations()
|
|
143
|
+
print(client.last_rate_limit)
|
|
144
|
+
# RateLimitState(limit=100, remaining=97, reset=1767225600) (reset is Unix seconds)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT. Questions: support@politicalcomms.com
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# political-comms
|
|
2
|
+
|
|
3
|
+
Python SDK for the [Political Comms](https://politicalcomms.com/) REST API. Direct-to-carrier political texting for campaigns, PACs, advocacy organizations, fundraisers, and elected officials.
|
|
4
|
+
|
|
5
|
+
Synchronous client built on httpx. Python 3.10 or later.
|
|
6
|
+
|
|
7
|
+
The full API reference lives at [docs.politicalcomms.com](https://docs.politicalcomms.com/api-reference/introduction) and the OpenAPI 3.1 specification at [politicalcomms.com/openapi.json](https://politicalcomms.com/openapi.json).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install political-comms
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Authentication
|
|
16
|
+
|
|
17
|
+
Requests authenticate with an API key in the `X-API-Key` header. Keys are created in the dashboard under Admin > API Keys and are prefixed `pc_live_`.
|
|
18
|
+
|
|
19
|
+
Set the key in the environment:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
export POLITICAL_COMMS_API_KEY=pc_live_...
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from political_comms import PoliticalCommsClient
|
|
27
|
+
|
|
28
|
+
client = PoliticalCommsClient()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or pass it to the constructor:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
client = PoliticalCommsClient(api_key="pc_live_...")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quickstart
|
|
38
|
+
|
|
39
|
+
Verify the credential, then run the standard send workflow: create a project, send yourself a test, and schedule it.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from political_comms import PoliticalCommsClient
|
|
43
|
+
|
|
44
|
+
client = PoliticalCommsClient()
|
|
45
|
+
|
|
46
|
+
# 1. Verify the credential.
|
|
47
|
+
orgs = client.list_organizations()
|
|
48
|
+
print([org.get("display_name") for org in orgs["data"]])
|
|
49
|
+
|
|
50
|
+
# 2. Create a project.
|
|
51
|
+
created = client.create_project(
|
|
52
|
+
organization_id="org_...",
|
|
53
|
+
name="GOTV reminder",
|
|
54
|
+
protocol="sms",
|
|
55
|
+
message_text="Polls are open until 8pm. Find your polling place: {link}",
|
|
56
|
+
phone_number_ids=["pn_..."],
|
|
57
|
+
contact_list_ids=["cl_..."],
|
|
58
|
+
brand_id="brand_...",
|
|
59
|
+
campaign_id="camp_...",
|
|
60
|
+
)
|
|
61
|
+
project_id = created["data"]["id"]
|
|
62
|
+
|
|
63
|
+
# 3. Send a test to yourself.
|
|
64
|
+
client.test_project(project_id, [{"phone": "+15555550100"}])
|
|
65
|
+
|
|
66
|
+
# 4. Schedule the send.
|
|
67
|
+
client.schedule_project(project_id, "2026-11-03T09:00:00", "America/New_York")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
One method exists per API operation, in snake_case: `list_organizations`, `get_hierarchy`, `list_brands`, `list_campaigns`, `list_tracking_domains`, `list_phone_numbers`, `list_toll_free_verifications`, `get_toll_free_verification`, `list_contact_lists`, `get_contact_list`, `import_contact_list`, `analyze_contact_list`, `delete_contact_list`, `list_media`, `import_media`, `get_media`, `delete_media`, `list_projects`, `create_project`, `get_all_project_stats`, `get_project`, `update_project`, `get_project_stats`, `test_project`, `schedule_project`, `unschedule_project`, `copy_project`, `archive_project`, `get_message_stats`, `get_ledger_usage`, `get_ledger_usage_by_initiator`.
|
|
71
|
+
|
|
72
|
+
Every method returns the parsed JSON response, a dict of the form `{"success": True, "data": ...}`.
|
|
73
|
+
|
|
74
|
+
## Error handling
|
|
75
|
+
|
|
76
|
+
Non-success responses raise `PoliticalCommsError` with the API's machine readable `code`, the HTTP `status_code`, and the raw response `body`.
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from political_comms import PoliticalCommsClient, PoliticalCommsError
|
|
80
|
+
|
|
81
|
+
client = PoliticalCommsClient()
|
|
82
|
+
try:
|
|
83
|
+
client.get_project("proj_unknown")
|
|
84
|
+
except PoliticalCommsError as err:
|
|
85
|
+
print(err.code, err.status_code, err)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Network failures raise `PoliticalCommsError` with `code == "NETWORK_ERROR"` and `status_code == 0`.
|
|
89
|
+
|
|
90
|
+
## Retries
|
|
91
|
+
|
|
92
|
+
The client retries automatically with these rules:
|
|
93
|
+
|
|
94
|
+
- `400`, `401`, `403`, `404` are never retried.
|
|
95
|
+
- `429` is retried after waiting until the `X-RateLimit-Reset` timestamp.
|
|
96
|
+
- `500`, `502`, `503`, `504` are retried with exponential backoff and jitter: 1 second base, 60 second cap, at most 5 attempts total.
|
|
97
|
+
|
|
98
|
+
Configure the retry budget with `max_retries` (retries after the first attempt, default 4):
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
client = PoliticalCommsClient(max_retries=2)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Every `POST` and `PATCH` request carries an `Idempotency-Key` header (a random UUID) so retries are safe; the API returns the cached first response when a key is replayed. `DELETE` requests send the header only when you supply a key. Supply your own key per call when you need cross-process deduplication:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
client.create_project(..., idempotency_key="send-2026-11-03-wave-1")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Rate limits
|
|
111
|
+
|
|
112
|
+
The API allows, per key over a 60-second sliding window, 100 requests/minute for reads, 60/minute for writes, and 30/minute for deletes. The client exposes the most recent rate limit headers:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
client.list_organizations()
|
|
116
|
+
print(client.last_rate_limit)
|
|
117
|
+
# RateLimitState(limit=100, remaining=97, reset=1767225600) (reset is Unix seconds)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT. Questions: support@politicalcomms.com
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "political-comms"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Python SDK for the Political Comms REST API. Direct-to-carrier political texting for campaigns, PACs, advocacy organizations, fundraisers, and elected officials."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Political Comms", email = "support@politicalcomms.com" }]
|
|
13
|
+
keywords = ["political texting", "sms", "api", "sdk", "political comms"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Communications :: Telephony",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["httpx>=0.27"]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = ["pytest>=8"]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://politicalcomms.com/"
|
|
33
|
+
Documentation = "https://docs.politicalcomms.com/api-reference/introduction"
|
|
34
|
+
Repository = "https://github.com/Political-Comms/political-comms-sdk"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/political_comms"]
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Python SDK for the Political Comms REST API."""
|
|
2
|
+
|
|
3
|
+
from ._client import PoliticalCommsClient, RateLimitState
|
|
4
|
+
from ._errors import PoliticalCommsError
|
|
5
|
+
|
|
6
|
+
__version__ = "0.2.0"
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"PoliticalCommsClient",
|
|
10
|
+
"PoliticalCommsError",
|
|
11
|
+
"RateLimitState",
|
|
12
|
+
"__version__",
|
|
13
|
+
]
|