Skip to main content

augstash (Python)

Python client for the Augstash API. Not published yet - see ../README.md.

python -m pip install -e .[dev]
python ../tools/refresh.py --base-url http://localhost:8086 python   # generate the client
python -m pytest tests

Using it

import os
from augstash import AugstashClient, AugstashError
from augstash.generated.api import SmsApi, WalletApi
from augstash.generated.models import SendSmsRequest

client = AugstashClient(
    base_url=os.environ["AUGSTASH_BASE_URL"],   # required - there is no default host
    api_key=os.environ["AUGSTASH_API_KEY"],     # ask_live_<keyId>.<secret>
)

wallet = client.api(WalletApi).balance()

try:
    client.api(SmsApi).send_sms(SendSmsRequest(to="+919000000000", body="hello"))
except AugstashError as error:
    if error.code == "WALLET_INSUFFICIENT_FUNDS":   # branch on code, never on message
        print(error.detail, error.trace_id)

client.api(X) takes any of the 154 generated API classes and hands back a cached, configured instance. There is no hand-written list of accessors: one would drift the moment an endpoint is added.

Paging

from augstash import paginate_cursor, paginate_pages
from augstash.generated.api import ContactApi

contacts = client.api(ContactApi)
for contact in paginate_pages(lambda page: contacts.list_contacts(page=page, limit=100)):
    ...

Use paginate_cursor for message, conversation and event history - those endpoints are cursor-paged because an offset page over a table that grows at the top repeats and skips rows mid-scroll.

Webhooks

from augstash import verify_webhook_signature, SIGNATURE_HEADER

@app.post("/hooks/augstash")
def receive():
    # request.get_data(), not request.get_json(): the signature covers the bytes as sent, and a
    # parsed-then-reserialized body no longer matches.
    if not verify_webhook_signature(secret, request.get_data(), request.headers.get(SIGNATURE_HEADER)):
        return "", 401
    return "", 204

Options

Argument Default
base_url - required
api_key / bearer_token - one is required; a bearer token reaches endpoints a key cannot
timeout 30.0 seconds, per attempt
retry RetryPolicy(3, 0.5, 8.0) RetryPolicy(max_attempts=1) disables
idempotency True off also stops mutating calls being retried
headers - extra headers on every request

The client is a context manager (with AugstashClient(...) as client:) and holds a connection pool; call close() when you are done with it.

Layout

augstash/generated/ is machine-written and gitignored; augstash/*.py beside it is the hand-written core and is protected from the generator by .openapi-generator-ignore.

Metadata

Release files for augstash 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for augstash 0.2.0
File Size Uploaded
augstash-0.2.0.tar.gz 779.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for augstash 0.2.0
File Interpreter ABI Platform
augstash-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.8 MB

Release files / augstash-0.2.0.tar.gz

Download URL augstash-0.2.0.tar.gz
Size 779.0 kB
Tags Source
SHA-256 checksum
How to use checksums
97c680b134de7d58dcc75dc075584741427e4f2d64806e39d7b542af4d4fe912
BLAKE2b-256 checksum
How to use checksums
1d98ff1fb457dfa4e79b5311fb245a0fcd98ff095999edcb43a3c17f96e94a55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / augstash-0.2.0-py3-none-any.whl

Download URL augstash-0.2.0-py3-none-any.whl
Size 3.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b272119cef9d2d97fa9c426de529020670ed429868034be83be3b1f975d3c7fa
BLAKE2b-256 checksum
How to use checksums
16d1fddf1cb3a364a53845135f171693052409eaa3f4f5e9287c673e06ed88fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page