bulkit 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.
- bulkit-0.1.0/.gitignore +31 -0
- bulkit-0.1.0/LICENSE +21 -0
- bulkit-0.1.0/PKG-INFO +346 -0
- bulkit-0.1.0/README.md +311 -0
- bulkit-0.1.0/pyproject.toml +121 -0
- bulkit-0.1.0/spec/openapi.json +8788 -0
- bulkit-0.1.0/src/bulkit/__init__.py +307 -0
- bulkit-0.1.0/src/bulkit/_base_client.py +1147 -0
- bulkit-0.1.0/src/bulkit/_constants.py +15 -0
- bulkit-0.1.0/src/bulkit/_exceptions.py +306 -0
- bulkit-0.1.0/src/bulkit/_pagination.py +226 -0
- bulkit-0.1.0/src/bulkit/_resource.py +19 -0
- bulkit-0.1.0/src/bulkit/_response.py +85 -0
- bulkit-0.1.0/src/bulkit/_types.py +52 -0
- bulkit-0.1.0/src/bulkit/_version.py +3 -0
- bulkit-0.1.0/src/bulkit/client.py +146 -0
- bulkit-0.1.0/src/bulkit/py.typed +0 -0
- bulkit-0.1.0/src/bulkit/resources/__init__.py +85 -0
- bulkit-0.1.0/src/bulkit/resources/channels.py +305 -0
- bulkit-0.1.0/src/bulkit/resources/media.py +1319 -0
- bulkit-0.1.0/src/bulkit/resources/platforms.py +122 -0
- bulkit-0.1.0/src/bulkit/resources/posts.py +1186 -0
- bulkit-0.1.0/src/bulkit/resources/stats.py +267 -0
- bulkit-0.1.0/src/bulkit/resources/tags.py +107 -0
- bulkit-0.1.0/src/bulkit/resources/usage.py +108 -0
- bulkit-0.1.0/src/bulkit/resources/webhooks.py +823 -0
- bulkit-0.1.0/src/bulkit/types/__init__.py +233 -0
- bulkit-0.1.0/src/bulkit/types/_base.py +10 -0
- bulkit-0.1.0/src/bulkit/types/_errors.py +113 -0
- bulkit-0.1.0/src/bulkit/types/channel.py +52 -0
- bulkit-0.1.0/src/bulkit/types/comment.py +35 -0
- bulkit-0.1.0/src/bulkit/types/media.py +48 -0
- bulkit-0.1.0/src/bulkit/types/platform.py +105 -0
- bulkit-0.1.0/src/bulkit/types/post.py +250 -0
- bulkit-0.1.0/src/bulkit/types/shared.py +123 -0
- bulkit-0.1.0/src/bulkit/types/stats.py +112 -0
- bulkit-0.1.0/src/bulkit/types/tag.py +10 -0
- bulkit-0.1.0/src/bulkit/types/usage.py +29 -0
- bulkit-0.1.0/src/bulkit/types/webhook.py +145 -0
- bulkit-0.1.0/src/bulkit/webhooks.py +141 -0
- bulkit-0.1.0/tests/conftest.py +139 -0
- bulkit-0.1.0/tests/test_client.py +235 -0
- bulkit-0.1.0/tests/test_live.py +38 -0
- bulkit-0.1.0/tests/test_media.py +403 -0
- bulkit-0.1.0/tests/test_pagination.py +134 -0
- bulkit-0.1.0/tests/test_parity.py +86 -0
- bulkit-0.1.0/tests/test_resources.py +196 -0
- bulkit-0.1.0/tests/test_retries.py +196 -0
- bulkit-0.1.0/tests/test_serialization.py +222 -0
- bulkit-0.1.0/tests/test_webhooks.py +164 -0
bulkit-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
.eggs/
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.whl
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv/
|
|
13
|
+
venv/
|
|
14
|
+
env/
|
|
15
|
+
|
|
16
|
+
# Tooling caches
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.pyright/
|
|
21
|
+
.coverage
|
|
22
|
+
coverage.xml
|
|
23
|
+
htmlcov/
|
|
24
|
+
|
|
25
|
+
# Environment & IDE
|
|
26
|
+
.env
|
|
27
|
+
.env.*
|
|
28
|
+
!.env.example
|
|
29
|
+
.DS_Store
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
bulkit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bulkit
|
|
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.
|
bulkit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bulkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for bulkit.io — schedule and publish social media posts programmatically.
|
|
5
|
+
Project-URL: Homepage, https://bulkit.io
|
|
6
|
+
Project-URL: Documentation, https://docs.bulkit.io
|
|
7
|
+
Project-URL: Repository, https://github.com/bulkit-io/bulkit-python
|
|
8
|
+
Project-URL: Issues, https://github.com/bulkit-io/bulkit-python/issues
|
|
9
|
+
Author-email: Bulkit <support@bulkit.io>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,bulkit,publishing,scheduling,sdk,social-media
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: httpx<1.0.0,>=0.27.0
|
|
24
|
+
Requires-Dist: pydantic<3.0.0,>=2.7.0
|
|
25
|
+
Requires-Dist: typing-extensions>=4.10.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: mypy>=1.13.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pyright>=1.1.389; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=8.3.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: respx>=0.21.1; extra == 'dev'
|
|
33
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# Bulkit Python SDK
|
|
37
|
+
|
|
38
|
+
Schedule and publish social posts from Python. The official [Bulkit](https://bulkit.io)
|
|
39
|
+
SDK provides typed sync and async clients for channels, posts, comments, media, analytics,
|
|
40
|
+
usage, and webhooks.
|
|
41
|
+
|
|
42
|
+
Requires **Python 3.10 or later**.
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pip install bulkit
|
|
48
|
+
# or
|
|
49
|
+
uv add bulkit
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Create an API key in **Developers → API & Webhooks** in the Bulkit app and set it in your
|
|
53
|
+
environment. Start with a test key; `bk_test_…` keys validate and save requests without
|
|
54
|
+
publishing to real accounts or billing.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
export BULKIT_API_KEY=bk_test_your_key
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quickstart
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from bulkit import Bulkit
|
|
64
|
+
|
|
65
|
+
with Bulkit() as client: # reads BULKIT_API_KEY
|
|
66
|
+
print(client.is_test_mode)
|
|
67
|
+
channels = client.channels.list()
|
|
68
|
+
post = client.posts.create(
|
|
69
|
+
intent="draft",
|
|
70
|
+
channels=[{"channel_id": channels[0].id, "blocks": [{"content": "Shipping today."}]}],
|
|
71
|
+
)
|
|
72
|
+
print(post.id, post.status)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The async client exposes the same methods and parameters:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
from bulkit import AsyncBulkit
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
async def main() -> None:
|
|
83
|
+
async with AsyncBulkit() as client:
|
|
84
|
+
channels = await client.channels.list()
|
|
85
|
+
print(client.is_test_mode, channels)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Context managers close connections automatically. You can also call `client.close()` or
|
|
92
|
+
`await client.aclose()`. If you supply an `httpx.Client` or `httpx.AsyncClient` through
|
|
93
|
+
`http_client=`, you retain responsibility for closing it.
|
|
94
|
+
|
|
95
|
+
## Create and schedule posts
|
|
96
|
+
|
|
97
|
+
One post can target several channels, each with its own text, media, and platform options.
|
|
98
|
+
Additional blocks create a thread on platforms that support it.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from bulkit import Bulkit, NOT_GIVEN
|
|
102
|
+
|
|
103
|
+
with Bulkit() as client:
|
|
104
|
+
post = client.posts.create(
|
|
105
|
+
intent="schedule", # "draft", "schedule", or "now"
|
|
106
|
+
scheduled_at="2027-01-15T09:00:00Z",
|
|
107
|
+
tag_ids=NOT_GIVEN,
|
|
108
|
+
channels=[
|
|
109
|
+
{
|
|
110
|
+
"channel_id": "chn_x",
|
|
111
|
+
"blocks": [
|
|
112
|
+
{"content": "Our launch is here."},
|
|
113
|
+
{"content": "Here is how we built it."},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"channel_id": "chn_linkedin",
|
|
118
|
+
"blocks": [{"content": "A longer version for LinkedIn."}],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
idempotency_key="campaign-launch-2027",
|
|
122
|
+
)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Optional arguments default to `NOT_GIVEN` (also exported as `OMIT`), which omits the field
|
|
126
|
+
entirely from the JSON body. Arbitrary keys in `options`, `media_alt_text`, and
|
|
127
|
+
`media_user_tags` are preserved. Use `client.platforms.list()` and
|
|
128
|
+
`client.channels.capabilities(channel_id)` to inspect supported formats and limits.
|
|
129
|
+
|
|
130
|
+
Publishing is asynchronous: `intent="now"` and `posts.publish(id)` queue work and may return
|
|
131
|
+
`publishing`. Follow the result with webhooks or `posts.retrieve(id)`; individual channels
|
|
132
|
+
can fail independently.
|
|
133
|
+
|
|
134
|
+
## Media
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from pathlib import Path
|
|
138
|
+
from bulkit import Bulkit
|
|
139
|
+
|
|
140
|
+
with Bulkit() as client:
|
|
141
|
+
image = client.media.upload(Path("photo.jpg"))
|
|
142
|
+
# Also accepts a string path, binary stream, or (filename, content, MIME type) tuple.
|
|
143
|
+
other = client.media.upload(b"image bytes", file_name="other.jpg")
|
|
144
|
+
|
|
145
|
+
video = client.media.upload_multipart(
|
|
146
|
+
Path("launch.mp4"),
|
|
147
|
+
concurrency=4,
|
|
148
|
+
idempotency_key="launch-video",
|
|
149
|
+
)
|
|
150
|
+
client.posts.create(
|
|
151
|
+
intent="draft",
|
|
152
|
+
channels=[
|
|
153
|
+
{
|
|
154
|
+
"channel_id": "chn_x",
|
|
155
|
+
"blocks": [{"content": "Watch the launch.", "media_ids": [video.id]}],
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`upload_multipart` streams file parts from disk, signs each batch, uploads it to storage,
|
|
162
|
+
and completes the session. It also accepts bytes or a seekable binary stream; stream
|
|
163
|
+
positions are restored afterward. Pass `file_name` for bytes or unnamed streams, and
|
|
164
|
+
`mime_type` if the filename does not identify a type. Concurrency is clamped to 1–100.
|
|
165
|
+
Multipart idempotency keys may contain at most 246 characters. Failed uploads abort their
|
|
166
|
+
session automatically. The same API is available with `await` on `AsyncBulkit`.
|
|
167
|
+
|
|
168
|
+
For explicit session management, use `media.uploads.start`, `sign_parts`, `complete`, and
|
|
169
|
+
`abort`.
|
|
170
|
+
|
|
171
|
+
## Pagination
|
|
172
|
+
|
|
173
|
+
Posts, comments, media, and webhook deliveries paginate automatically:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
with Bulkit() as client:
|
|
177
|
+
for post in client.posts.list(status=["failed", "draft"]):
|
|
178
|
+
print(post.id)
|
|
179
|
+
|
|
180
|
+
# Or fetch one page at a time.
|
|
181
|
+
page = client.posts.list(limit=50)
|
|
182
|
+
print(page.data)
|
|
183
|
+
while page.has_next_page():
|
|
184
|
+
page = page.get_next_page()
|
|
185
|
+
print(page.data)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
async with AsyncBulkit() as client:
|
|
190
|
+
async for post in client.posts.list(): # no await before async for
|
|
191
|
+
print(post.id)
|
|
192
|
+
|
|
193
|
+
page = await client.posts.list(limit=50)
|
|
194
|
+
async for batch in page.iter_pages():
|
|
195
|
+
print(batch.data)
|
|
196
|
+
# Manual paging: await page.get_next_page() when page.has_next_page().
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Response metadata
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
with Bulkit() as client:
|
|
203
|
+
response = client.with_raw_response.posts.list(limit=10)
|
|
204
|
+
print(response.request_id, response.status_code)
|
|
205
|
+
print(response.rate_limit.limit, response.rate_limit.remaining, response.rate_limit.reset)
|
|
206
|
+
print(response.headers)
|
|
207
|
+
page = response.parse() # cached; response.data returns the same object
|
|
208
|
+
print(page.data)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Every REST endpoint has a `with_raw_response` counterpart. Its `http_response` is the
|
|
212
|
+
underlying `httpx.Response`. Async raw methods are awaited; their `.parse()` is synchronous.
|
|
213
|
+
Include the request ID when contacting support.
|
|
214
|
+
|
|
215
|
+
## Errors, retries, and configuration
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from bulkit import APIError, Bulkit, QuotaExceededError
|
|
219
|
+
|
|
220
|
+
with Bulkit(max_retries=2, timeout=30.0) as client:
|
|
221
|
+
try:
|
|
222
|
+
post = client.posts.retrieve("post_123", max_retries=0)
|
|
223
|
+
except QuotaExceededError:
|
|
224
|
+
print("Plan allowance exhausted; inspect client.usage.retrieve().")
|
|
225
|
+
except APIError as error:
|
|
226
|
+
if error.code == "not_found":
|
|
227
|
+
print("Post no longer exists")
|
|
228
|
+
else:
|
|
229
|
+
print(error.status_code, error.code, error.field, error.request_id)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
| Status | Exception |
|
|
233
|
+
| --- | --- |
|
|
234
|
+
| 400 | `BadRequestError` |
|
|
235
|
+
| 401 | `AuthenticationError` |
|
|
236
|
+
| 402 | `QuotaExceededError` |
|
|
237
|
+
| 403 | `PermissionDeniedError` |
|
|
238
|
+
| 404 | `NotFoundError` |
|
|
239
|
+
| 409 | `ConflictError` |
|
|
240
|
+
| 413 | `PayloadTooLargeError` |
|
|
241
|
+
| 415 | `UnsupportedMediaTypeError` |
|
|
242
|
+
| 422 | `UnprocessableEntityError` |
|
|
243
|
+
| 429 | `RateLimitError` |
|
|
244
|
+
| 5xx | `InternalServerError` |
|
|
245
|
+
|
|
246
|
+
Network failures raise `APIConnectionError` or `APIConnectionTimeoutError`; invalid success
|
|
247
|
+
responses raise `APIResponseValidationError`. All SDK errors extend `BulkitError`.
|
|
248
|
+
|
|
249
|
+
The SDK retries connection failures, timeouts, 408, 429, 502, 503, 504, and
|
|
250
|
+
`409 request_in_progress` twice by default. It retries 500 on GET and DELETE only.
|
|
251
|
+
`QuotaExceededError` and other client errors are never retried. Backoff includes jitter;
|
|
252
|
+
numeric `Retry-After` values on 429 are honored up to 60 seconds.
|
|
253
|
+
|
|
254
|
+
POST and PUT automatically receive a UUID idempotency key, reused with identical body bytes
|
|
255
|
+
across retries. Supply `idempotency_key=` to reuse a logical write across process restarts
|
|
256
|
+
(255 characters maximum for individual REST calls). GET and DELETE never carry this header.
|
|
257
|
+
|
|
258
|
+
Configure `api_key`, `base_url` (or `BULKIT_BASE_URL`), `timeout` (60 seconds per I/O phase by
|
|
259
|
+
default), `max_retries`, `default_headers`, and `http_client` in either constructor.
|
|
260
|
+
Per-call options include `extra_headers`, `extra_query`, `timeout`, and `max_retries`.
|
|
261
|
+
|
|
262
|
+
## Webhooks
|
|
263
|
+
|
|
264
|
+
Verify the raw request body before using an event. Store your endpoint secret separately
|
|
265
|
+
from the API key. Both clients provide a synchronous `client.webhooks.unwrap` helper;
|
|
266
|
+
standalone `verify_webhook` needs no client.
|
|
267
|
+
|
|
268
|
+
FastAPI:
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
import os
|
|
272
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
273
|
+
from bulkit import WebhookVerificationError, verify_webhook
|
|
274
|
+
|
|
275
|
+
app = FastAPI()
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
@app.post("/webhooks/bulkit")
|
|
279
|
+
async def receive(request: Request):
|
|
280
|
+
body = await request.body()
|
|
281
|
+
try:
|
|
282
|
+
event = verify_webhook(body, request.headers, secret=os.environ["BULKIT_WEBHOOK_SECRET"])
|
|
283
|
+
except WebhookVerificationError as error:
|
|
284
|
+
raise HTTPException(status_code=400, detail="Invalid webhook") from error
|
|
285
|
+
# Deduplicate on event.id before processing; deliveries are at least once.
|
|
286
|
+
return {"received": event.id}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Django:
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
import os
|
|
293
|
+
from django.http import HttpResponse
|
|
294
|
+
from django.views.decorators.csrf import csrf_exempt
|
|
295
|
+
from bulkit import WebhookVerificationError, verify_webhook
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
@csrf_exempt
|
|
299
|
+
def receive(request):
|
|
300
|
+
try:
|
|
301
|
+
event = verify_webhook(
|
|
302
|
+
request.body, request.headers, secret=os.environ["BULKIT_WEBHOOK_SECRET"]
|
|
303
|
+
)
|
|
304
|
+
except WebhookVerificationError:
|
|
305
|
+
return HttpResponse(status=400)
|
|
306
|
+
# Deduplicate and process event.id.
|
|
307
|
+
return HttpResponse(status=200)
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Use Django's `request.headers`, **not `request.META`**: verification expects HTTP header
|
|
311
|
+
names. Never deserialize and re-serialize the body before verifying. The default replay
|
|
312
|
+
tolerance is 300 seconds; `tolerance_seconds=None` disables the timestamp check.
|
|
313
|
+
Known events parse into typed payloads; new event types or forward-compatible payload changes fall back to `UnknownWebhookEvent` rather than failing verification.
|
|
314
|
+
Use `client.webhooks.test(endpoint_id)` to test your receiver and
|
|
315
|
+
`sign_webhook_payload(payload, secret)` to build signatures in local tests.
|
|
316
|
+
|
|
317
|
+
## Low-level requests
|
|
318
|
+
|
|
319
|
+
Access new routes while keeping authentication, retries, and error handling:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
with Bulkit() as client:
|
|
323
|
+
data = client.get("/future-route", query={"limit": 10})
|
|
324
|
+
created = client.post("/future-route", body={"name": "example"})
|
|
325
|
+
updated = client.put("/future-route/id", body={"name": "updated"})
|
|
326
|
+
client.delete("/future-route/id")
|
|
327
|
+
data = client.request("GET", "/future-route")
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Paths are relative to `/public/v1`; the default host is `https://api.bulkit.io`.
|
|
331
|
+
|
|
332
|
+
## Development
|
|
333
|
+
|
|
334
|
+
```sh
|
|
335
|
+
python -m pip install -e '.[dev]'
|
|
336
|
+
ruff check .
|
|
337
|
+
ruff format --check .
|
|
338
|
+
mypy --strict src tests
|
|
339
|
+
pyright
|
|
340
|
+
pytest --cov=bulkit
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Read-only live smoke tests run only when `BULKIT_TEST_API_KEY` is set.
|
|
344
|
+
|
|
345
|
+
[Documentation](https://docs.bulkit.io) · [API keys](https://app.bulkit.io) ·
|
|
346
|
+
[MIT license](./LICENSE)
|
bulkit-0.1.0/README.md
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# Bulkit Python SDK
|
|
2
|
+
|
|
3
|
+
Schedule and publish social posts from Python. The official [Bulkit](https://bulkit.io)
|
|
4
|
+
SDK provides typed sync and async clients for channels, posts, comments, media, analytics,
|
|
5
|
+
usage, and webhooks.
|
|
6
|
+
|
|
7
|
+
Requires **Python 3.10 or later**.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
pip install bulkit
|
|
13
|
+
# or
|
|
14
|
+
uv add bulkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Create an API key in **Developers → API & Webhooks** in the Bulkit app and set it in your
|
|
18
|
+
environment. Start with a test key; `bk_test_…` keys validate and save requests without
|
|
19
|
+
publishing to real accounts or billing.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
export BULKIT_API_KEY=bk_test_your_key
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from bulkit import Bulkit
|
|
29
|
+
|
|
30
|
+
with Bulkit() as client: # reads BULKIT_API_KEY
|
|
31
|
+
print(client.is_test_mode)
|
|
32
|
+
channels = client.channels.list()
|
|
33
|
+
post = client.posts.create(
|
|
34
|
+
intent="draft",
|
|
35
|
+
channels=[{"channel_id": channels[0].id, "blocks": [{"content": "Shipping today."}]}],
|
|
36
|
+
)
|
|
37
|
+
print(post.id, post.status)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The async client exposes the same methods and parameters:
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import asyncio
|
|
44
|
+
from bulkit import AsyncBulkit
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async def main() -> None:
|
|
48
|
+
async with AsyncBulkit() as client:
|
|
49
|
+
channels = await client.channels.list()
|
|
50
|
+
print(client.is_test_mode, channels)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
asyncio.run(main())
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Context managers close connections automatically. You can also call `client.close()` or
|
|
57
|
+
`await client.aclose()`. If you supply an `httpx.Client` or `httpx.AsyncClient` through
|
|
58
|
+
`http_client=`, you retain responsibility for closing it.
|
|
59
|
+
|
|
60
|
+
## Create and schedule posts
|
|
61
|
+
|
|
62
|
+
One post can target several channels, each with its own text, media, and platform options.
|
|
63
|
+
Additional blocks create a thread on platforms that support it.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from bulkit import Bulkit, NOT_GIVEN
|
|
67
|
+
|
|
68
|
+
with Bulkit() as client:
|
|
69
|
+
post = client.posts.create(
|
|
70
|
+
intent="schedule", # "draft", "schedule", or "now"
|
|
71
|
+
scheduled_at="2027-01-15T09:00:00Z",
|
|
72
|
+
tag_ids=NOT_GIVEN,
|
|
73
|
+
channels=[
|
|
74
|
+
{
|
|
75
|
+
"channel_id": "chn_x",
|
|
76
|
+
"blocks": [
|
|
77
|
+
{"content": "Our launch is here."},
|
|
78
|
+
{"content": "Here is how we built it."},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"channel_id": "chn_linkedin",
|
|
83
|
+
"blocks": [{"content": "A longer version for LinkedIn."}],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
idempotency_key="campaign-launch-2027",
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Optional arguments default to `NOT_GIVEN` (also exported as `OMIT`), which omits the field
|
|
91
|
+
entirely from the JSON body. Arbitrary keys in `options`, `media_alt_text`, and
|
|
92
|
+
`media_user_tags` are preserved. Use `client.platforms.list()` and
|
|
93
|
+
`client.channels.capabilities(channel_id)` to inspect supported formats and limits.
|
|
94
|
+
|
|
95
|
+
Publishing is asynchronous: `intent="now"` and `posts.publish(id)` queue work and may return
|
|
96
|
+
`publishing`. Follow the result with webhooks or `posts.retrieve(id)`; individual channels
|
|
97
|
+
can fail independently.
|
|
98
|
+
|
|
99
|
+
## Media
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from pathlib import Path
|
|
103
|
+
from bulkit import Bulkit
|
|
104
|
+
|
|
105
|
+
with Bulkit() as client:
|
|
106
|
+
image = client.media.upload(Path("photo.jpg"))
|
|
107
|
+
# Also accepts a string path, binary stream, or (filename, content, MIME type) tuple.
|
|
108
|
+
other = client.media.upload(b"image bytes", file_name="other.jpg")
|
|
109
|
+
|
|
110
|
+
video = client.media.upload_multipart(
|
|
111
|
+
Path("launch.mp4"),
|
|
112
|
+
concurrency=4,
|
|
113
|
+
idempotency_key="launch-video",
|
|
114
|
+
)
|
|
115
|
+
client.posts.create(
|
|
116
|
+
intent="draft",
|
|
117
|
+
channels=[
|
|
118
|
+
{
|
|
119
|
+
"channel_id": "chn_x",
|
|
120
|
+
"blocks": [{"content": "Watch the launch.", "media_ids": [video.id]}],
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`upload_multipart` streams file parts from disk, signs each batch, uploads it to storage,
|
|
127
|
+
and completes the session. It also accepts bytes or a seekable binary stream; stream
|
|
128
|
+
positions are restored afterward. Pass `file_name` for bytes or unnamed streams, and
|
|
129
|
+
`mime_type` if the filename does not identify a type. Concurrency is clamped to 1–100.
|
|
130
|
+
Multipart idempotency keys may contain at most 246 characters. Failed uploads abort their
|
|
131
|
+
session automatically. The same API is available with `await` on `AsyncBulkit`.
|
|
132
|
+
|
|
133
|
+
For explicit session management, use `media.uploads.start`, `sign_parts`, `complete`, and
|
|
134
|
+
`abort`.
|
|
135
|
+
|
|
136
|
+
## Pagination
|
|
137
|
+
|
|
138
|
+
Posts, comments, media, and webhook deliveries paginate automatically:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
with Bulkit() as client:
|
|
142
|
+
for post in client.posts.list(status=["failed", "draft"]):
|
|
143
|
+
print(post.id)
|
|
144
|
+
|
|
145
|
+
# Or fetch one page at a time.
|
|
146
|
+
page = client.posts.list(limit=50)
|
|
147
|
+
print(page.data)
|
|
148
|
+
while page.has_next_page():
|
|
149
|
+
page = page.get_next_page()
|
|
150
|
+
print(page.data)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
async with AsyncBulkit() as client:
|
|
155
|
+
async for post in client.posts.list(): # no await before async for
|
|
156
|
+
print(post.id)
|
|
157
|
+
|
|
158
|
+
page = await client.posts.list(limit=50)
|
|
159
|
+
async for batch in page.iter_pages():
|
|
160
|
+
print(batch.data)
|
|
161
|
+
# Manual paging: await page.get_next_page() when page.has_next_page().
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Response metadata
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
with Bulkit() as client:
|
|
168
|
+
response = client.with_raw_response.posts.list(limit=10)
|
|
169
|
+
print(response.request_id, response.status_code)
|
|
170
|
+
print(response.rate_limit.limit, response.rate_limit.remaining, response.rate_limit.reset)
|
|
171
|
+
print(response.headers)
|
|
172
|
+
page = response.parse() # cached; response.data returns the same object
|
|
173
|
+
print(page.data)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Every REST endpoint has a `with_raw_response` counterpart. Its `http_response` is the
|
|
177
|
+
underlying `httpx.Response`. Async raw methods are awaited; their `.parse()` is synchronous.
|
|
178
|
+
Include the request ID when contacting support.
|
|
179
|
+
|
|
180
|
+
## Errors, retries, and configuration
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from bulkit import APIError, Bulkit, QuotaExceededError
|
|
184
|
+
|
|
185
|
+
with Bulkit(max_retries=2, timeout=30.0) as client:
|
|
186
|
+
try:
|
|
187
|
+
post = client.posts.retrieve("post_123", max_retries=0)
|
|
188
|
+
except QuotaExceededError:
|
|
189
|
+
print("Plan allowance exhausted; inspect client.usage.retrieve().")
|
|
190
|
+
except APIError as error:
|
|
191
|
+
if error.code == "not_found":
|
|
192
|
+
print("Post no longer exists")
|
|
193
|
+
else:
|
|
194
|
+
print(error.status_code, error.code, error.field, error.request_id)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
| Status | Exception |
|
|
198
|
+
| --- | --- |
|
|
199
|
+
| 400 | `BadRequestError` |
|
|
200
|
+
| 401 | `AuthenticationError` |
|
|
201
|
+
| 402 | `QuotaExceededError` |
|
|
202
|
+
| 403 | `PermissionDeniedError` |
|
|
203
|
+
| 404 | `NotFoundError` |
|
|
204
|
+
| 409 | `ConflictError` |
|
|
205
|
+
| 413 | `PayloadTooLargeError` |
|
|
206
|
+
| 415 | `UnsupportedMediaTypeError` |
|
|
207
|
+
| 422 | `UnprocessableEntityError` |
|
|
208
|
+
| 429 | `RateLimitError` |
|
|
209
|
+
| 5xx | `InternalServerError` |
|
|
210
|
+
|
|
211
|
+
Network failures raise `APIConnectionError` or `APIConnectionTimeoutError`; invalid success
|
|
212
|
+
responses raise `APIResponseValidationError`. All SDK errors extend `BulkitError`.
|
|
213
|
+
|
|
214
|
+
The SDK retries connection failures, timeouts, 408, 429, 502, 503, 504, and
|
|
215
|
+
`409 request_in_progress` twice by default. It retries 500 on GET and DELETE only.
|
|
216
|
+
`QuotaExceededError` and other client errors are never retried. Backoff includes jitter;
|
|
217
|
+
numeric `Retry-After` values on 429 are honored up to 60 seconds.
|
|
218
|
+
|
|
219
|
+
POST and PUT automatically receive a UUID idempotency key, reused with identical body bytes
|
|
220
|
+
across retries. Supply `idempotency_key=` to reuse a logical write across process restarts
|
|
221
|
+
(255 characters maximum for individual REST calls). GET and DELETE never carry this header.
|
|
222
|
+
|
|
223
|
+
Configure `api_key`, `base_url` (or `BULKIT_BASE_URL`), `timeout` (60 seconds per I/O phase by
|
|
224
|
+
default), `max_retries`, `default_headers`, and `http_client` in either constructor.
|
|
225
|
+
Per-call options include `extra_headers`, `extra_query`, `timeout`, and `max_retries`.
|
|
226
|
+
|
|
227
|
+
## Webhooks
|
|
228
|
+
|
|
229
|
+
Verify the raw request body before using an event. Store your endpoint secret separately
|
|
230
|
+
from the API key. Both clients provide a synchronous `client.webhooks.unwrap` helper;
|
|
231
|
+
standalone `verify_webhook` needs no client.
|
|
232
|
+
|
|
233
|
+
FastAPI:
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
import os
|
|
237
|
+
from fastapi import FastAPI, HTTPException, Request
|
|
238
|
+
from bulkit import WebhookVerificationError, verify_webhook
|
|
239
|
+
|
|
240
|
+
app = FastAPI()
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
@app.post("/webhooks/bulkit")
|
|
244
|
+
async def receive(request: Request):
|
|
245
|
+
body = await request.body()
|
|
246
|
+
try:
|
|
247
|
+
event = verify_webhook(body, request.headers, secret=os.environ["BULKIT_WEBHOOK_SECRET"])
|
|
248
|
+
except WebhookVerificationError as error:
|
|
249
|
+
raise HTTPException(status_code=400, detail="Invalid webhook") from error
|
|
250
|
+
# Deduplicate on event.id before processing; deliveries are at least once.
|
|
251
|
+
return {"received": event.id}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Django:
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
import os
|
|
258
|
+
from django.http import HttpResponse
|
|
259
|
+
from django.views.decorators.csrf import csrf_exempt
|
|
260
|
+
from bulkit import WebhookVerificationError, verify_webhook
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
@csrf_exempt
|
|
264
|
+
def receive(request):
|
|
265
|
+
try:
|
|
266
|
+
event = verify_webhook(
|
|
267
|
+
request.body, request.headers, secret=os.environ["BULKIT_WEBHOOK_SECRET"]
|
|
268
|
+
)
|
|
269
|
+
except WebhookVerificationError:
|
|
270
|
+
return HttpResponse(status=400)
|
|
271
|
+
# Deduplicate and process event.id.
|
|
272
|
+
return HttpResponse(status=200)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Use Django's `request.headers`, **not `request.META`**: verification expects HTTP header
|
|
276
|
+
names. Never deserialize and re-serialize the body before verifying. The default replay
|
|
277
|
+
tolerance is 300 seconds; `tolerance_seconds=None` disables the timestamp check.
|
|
278
|
+
Known events parse into typed payloads; new event types or forward-compatible payload changes fall back to `UnknownWebhookEvent` rather than failing verification.
|
|
279
|
+
Use `client.webhooks.test(endpoint_id)` to test your receiver and
|
|
280
|
+
`sign_webhook_payload(payload, secret)` to build signatures in local tests.
|
|
281
|
+
|
|
282
|
+
## Low-level requests
|
|
283
|
+
|
|
284
|
+
Access new routes while keeping authentication, retries, and error handling:
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
with Bulkit() as client:
|
|
288
|
+
data = client.get("/future-route", query={"limit": 10})
|
|
289
|
+
created = client.post("/future-route", body={"name": "example"})
|
|
290
|
+
updated = client.put("/future-route/id", body={"name": "updated"})
|
|
291
|
+
client.delete("/future-route/id")
|
|
292
|
+
data = client.request("GET", "/future-route")
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Paths are relative to `/public/v1`; the default host is `https://api.bulkit.io`.
|
|
296
|
+
|
|
297
|
+
## Development
|
|
298
|
+
|
|
299
|
+
```sh
|
|
300
|
+
python -m pip install -e '.[dev]'
|
|
301
|
+
ruff check .
|
|
302
|
+
ruff format --check .
|
|
303
|
+
mypy --strict src tests
|
|
304
|
+
pyright
|
|
305
|
+
pytest --cov=bulkit
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Read-only live smoke tests run only when `BULKIT_TEST_API_KEY` is set.
|
|
309
|
+
|
|
310
|
+
[Documentation](https://docs.bulkit.io) · [API keys](https://app.bulkit.io) ·
|
|
311
|
+
[MIT license](./LICENSE)
|