Setalabs Python SDK
Client for the Setalabs gateway. Each API has its own uuid, key, and set of endpoints. The gateway address is shared.
The key secret is used only to sign requests. It is never sent.
Installation
pip install setalabs
Until the package is published, install it from a local path:
pip install -e ../setalabs-python-sdk
Requests
The default gateway address is setalabs.Gateway.URL (https://gw.setalabs.com). Pass gateway to use another one. An OpenAPI server URL already includes the API uuid; this SDK takes the uuid separately.
from setalabs import Client
from setalabs.exceptions import ApiException, RateLimitException, ValidationException
client = Client(
api_uuid="05141812-7772-403e-9ca6-5e8e8bf22730",
api_key="your-key",
api_secret="your-secret",
)
local = Client(
api_uuid="05141812-7772-403e-9ca6-5e8e8bf22730",
api_key="your-key",
api_secret="your-secret",
gateway="http://localhost:8080",
)
response = client.get("/catalog", {"language": "en"})
data = response.json()
The path is the endpoint path from the OpenAPI document (/catalog, /product/{id}, /search), without the /v1/api/{uuid} prefix. Substitute path parameters yourself: /product/12345.
Another API on the same gateway:
other = client.with_api("another-api-uuid", "other-key", "other-secret")
If the key has no secret, pass an empty string. The request is not signed.
client.post("/orders", {"sku": "A1"})
client.request(
"PUT",
"/orders/1",
json={"status": "paid"},
query={"language": "en"},
timeout=10,
)
A successful response is the upstream body and status, unchanged. The gateway returns the request id in X-Request-Id:
response.status_code
response.request_id()
response.json()
Client can be used as a context manager. That closes the underlying HTTP connection pool.
Signature
When a secret is set, every request includes:
X-Api-KeyX-Api-Timestamp— Unix time in secondsX-Api-Sign—HMAC-SHA256(key + secret + timestamp + path?query, secret), lowercase hex
path?query is the path the gateway sees, plus the raw query string. For example: /v1/api/{uuid}/catalog?language=en. Parameter order is preserved. The query string uses the same encoding as PHP http_build_query with PHP_QUERY_RFC3986.
Errors
A response with status 400 or higher raises an exception. The message comes from the gateway reason. Every API error exposes status_code, error, reason, request_id, and the original response.
| HTTP | error |
Exception | When |
|---|---|---|---|
| 400 | bad_request |
BadRequestException |
The API has no base URL |
| 401 | unauthorized |
UnauthorizedException |
Missing or invalid key, missing or invalid signature, missing timestamp |
| 403 | forbidden |
ForbiddenException |
Key is blocked, subscription has expired, no active tariff, or the key belongs to another API |
| 404 | not_found |
NotFoundException |
API or endpoint was not found |
| 422 | validation_error |
ValidationException |
Required fields are missing; names are in missing_fields |
| 429 | rate_limited |
RateLimitException |
Plan RPS limit exceeded; wait retry_after seconds |
| 429 | usage_limit_exceeded |
UsageLimitException |
Call quota for the period is exhausted |
| 500 | internal_error |
ServerException |
Gateway internal error |
| 502 | bad_gateway |
BadGatewayException |
Upstream is unavailable |
A network failure raises TransportException. SetalabsException is the base type for gateway and transport errors. Invalid client arguments raise ValueError.
import time
try:
data = client.get("/search", {"text": "phone", "page": 1, "limit": 24}).json()
except ValidationException as exc:
exc.missing_fields
except RateLimitException as exc:
time.sleep(exc.retry_after or 1)
except ApiException as exc:
exc.status_code
exc.reason
exc.request_id
Metadata
Release files for setalabs 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| setalabs-1.0.0.tar.gz | 12.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| setalabs-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.9 kB
Release files / setalabs-1.0.0.tar.gz
| Download URL | setalabs-1.0.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e44cf5ecc91c23471fcd3a13244dd1cef8de32ebf3106a204cc46d52d7cb04b
|
|
BLAKE2b-256 checksum How to use checksums |
73bd058e6fad21fd29f9a3dbcc0cb4b3d478f8c1a096213a88f3d934d9fd111f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / setalabs-1.0.0-py3-none-any.whl
| Download URL | setalabs-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
06ca6d17992d687b379efd78e4e90eb0bb7ec1a73b0b546d9fa418961a065ef3
|
|
BLAKE2b-256 checksum How to use checksums |
236a3f6e89a3f839873934ab1502fc655c7e66bdd28bd303a02d7c31f3093483
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for setalabs 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.