captionpack — Python client for the Caption-Pack API
Turn a topic, audience, and tone into ready-to-post social captions + hashtags, as JSON. Built for developers and AI agents.
Install
pip install captionpack
(Get your API key at the Caption-Pack site — $10 for 500 calls.)
Quickstart
from captionpack import Client
client = Client(api_key="cp_live_...")
pack = client.caption_pack(topic="morning routines", audience="busy parents")
print(pack.captions[0].body, pack.hashtags)
You can also set the CAPTIONPACK_API_KEY environment variable instead of passing api_key=.
Usage
from captionpack import (
Client,
AuthenticationError,
InsufficientCreditsError,
RateLimitedError,
)
client = Client() # reads CAPTIONPACK_API_KEY
# Generate captions (1 credit per call)
pack = client.caption_pack(
topic="password managers",
audience="small business owners",
tone="warm", # warm | bold | professional | playful
platform="linkedin", # instagram | linkedin | x | tiktok
count=5, # 1-10
include_hashtags=True,
)
for caption in pack.captions:
print(caption.hook, "|", caption.body, "|", caption.cta)
print(pack.hashtags)
print("credits left:", pack.credits_remaining) # from X-Credits-Remaining
# Check balance
balance = client.balance()
print(balance.credits)
# Handle errors explicitly
try:
pack = client.caption_pack(topic="x", audience="y")
except InsufficientCreditsError as e:
print("Out of credits — top up:", e.top_up_url)
except RateLimitedError:
print("Slow down — 60 requests/minute per key.")
except AuthenticationError:
print("Bad API key.")
Behavior notes
- One automatic retry on HTTP 429 (with backoff, honoring
Retry-After). X-Credits-Remainingis surfaced on everycaption_packresult.- Point at a local/dev server with
Client(api_key=..., base_url="http://localhost:8000").
Development
pip install -e ".[dev]" # or: pip install -e . && pip install pytest
# integration tests need the API source; set CAPTIONPACK_TEST_API_DIR
CAPTIONPACK_TEST_API_DIR=/path/to/caption-pack-api pytest
Metadata
Release files for captionpack 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| captionpack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / captionpack-0.1.0-py3-none-any.whl
| Download URL | captionpack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acb7bcb2ed1483123ab9110f7cdb05109b3701e483d5c4f454a060ebeda8702d
|
|
BLAKE2b-256 checksum How to use checksums |
7e75b44219a813e7a585869e8c1d0d5c366321d7b840ecac35ebb6df9b2091a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|