Skip to main content

Official Python SDK for the ThrustLab API

Project description

thrustlab — official Python SDK for the ThrustLab API

PyPI Python License

Install

pip install thrustlab

Requires Python 3.10+.

Quickstart

from thrustlab import Client

client = Client(api_key="key_...")  # or set $THRUSTLAB_API_KEY

# Create a project
project = client.projects.create(name="my project")

# Run a simulation and wait for the result
sim = client.simulations.create(
    project_id=project["id"],
    motor="comp_motor_xxx",
    propeller="comp_prop_xxx",
    battery="comp_batt_xxx",
    throttle=0.7,
)
result = client.simulations.wait(sim["id"], timeout=300)
print(result)

Configuration

Setting Constructor arg Env var Default
API key api_key= THRUSTLAB_API_KEY (required)
Base URL base_url= THRUSTLAB_BASE_URL https://thrustlab.com
Timeout timeout= 30 (seconds)
Max retries max_retries= 3

Resources

Every /v1/ route family is exposed as an attribute on the client:

client.api_keys
client.users
client.projects
client.simulations
client.sweeps
client.components
client.submissions
client.starred_components
client.geometry
client.credits
client.subscriptions
client.webhook_endpoints

Error handling

from thrustlab import Client
from thrustlab.exceptions import (
    AuthenticationError,
    ValidationError,
    RateLimitError,
    NotFoundError,
)

client = Client()
try:
    client.simulations.create(project_id="proj_xxx", motor="comp_xxx", ...)
except ValidationError as exc:
    print(f"bad request: {exc.code} ({exc.param}): {exc.message}")
except RateLimitError as exc:
    print(f"rate limited; retry after {exc.retry_after}s")
except NotFoundError as exc:
    print(f"not found: {exc.message}")
except AuthenticationError as exc:
    print(f"auth failed: {exc.message}")

Every error carries .code, .type, .request_id, .http_status, and .message. ValidationError additionally exposes .param. See thrustlab.com/docs/guides/errors for the full code reference.

Pagination

List endpoints return a CursorPager — a lazy iterator that fetches the next page only when needed:

# Iterate all pages automatically
for project in client.projects.list():
    print(project["id"])

# Materialise the first page only
first_page = list(client.projects.list(limit=20))

Async polling

simulations.wait() and sweeps.wait() block until the resource reaches a terminal state (succeeded, failed, or cancelled) or the timeout fires:

sweep = client.sweeps.create(...)
result = client.sweeps.wait(sweep["id"], timeout=600, poll_interval=2.0)
if result["status"] == "succeeded":
    print(result["outputs"])

Webhooks

from thrustlab import Webhook
from thrustlab.exceptions import SignatureVerificationError

WEBHOOK_SECRET = "whsec_..."

@app.post("/webhooks/thrustlab")
async def handle(request):
    payload = await request.body()
    sig    = request.headers["Thrustlab-Signature"]
    try:
        event = Webhook.verify(payload, sig, WEBHOOK_SECRET)
    except SignatureVerificationError:
        return Response(status_code=400)
    if event.type == "simulation.succeeded":
        print(event.data)

Retries

The client automatically retries on 429 (rate limit) and 5xx responses using exponential backoff with jitter. Set max_retries=0 to disable:

client = Client(max_retries=0)

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thrustlab-0.1.1.tar.gz (55.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thrustlab-0.1.1-py3-none-any.whl (117.3 kB view details)

Uploaded Python 3

File details

Details for the file thrustlab-0.1.1.tar.gz.

File metadata

  • Download URL: thrustlab-0.1.1.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for thrustlab-0.1.1.tar.gz
Algorithm Hash digest
SHA256 517d1b134187382fe33ae3c1fbd4bdbc97fa7a54a9be12429283a260ddfd16df
MD5 b7e6236e67ba6ae66a15cca539c707bb
BLAKE2b-256 90136bcf846e3f1de0f4e599271e4acdd7c47c6f900dc4f30abfdfe5c07b3687

See more details on using hashes here.

Provenance

The following attestation bundles were made for thrustlab-0.1.1.tar.gz:

Publisher: sdk-publish.yml on kbedrich/thrustlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file thrustlab-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: thrustlab-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 117.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for thrustlab-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dcea9deb6720eac00f1fe8f5c09e6a03785b1812551d53d30a321f5d6ec90e4
MD5 89b1f91b83ed5f2d1bd6732e8c6798c0
BLAKE2b-256 d6760d21286be9bd6b3c789280d739c19ac5f4a90bf9d30881d43ac7fa080511

See more details on using hashes here.

Provenance

The following attestation bundles were made for thrustlab-0.1.1-py3-none-any.whl:

Publisher: sdk-publish.yml on kbedrich/thrustlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page