Skip to main content

Elastly API

Project description

Elastly Python SDK

The official Python client for the Elastly REST API.

Elastly prices quote and order lines for B2B sellers. Send a line (product, customer, quantity) and get back a price with the reasoning behind it: which pricing rules fired, what each one added, and how confident the engine is. The engine learns from the outcomes you feed back, so prices improve over time.

This client covers the full v1 API:

  • Prices: price up to 100 lines in one call.
  • Ingest: push products, customers, quotes, and orders from your own system in staged batches.
  • Write-backs: pull approved price changes into your system and confirm them once applied.

Install

pip install elastly

Requires Python 3.9 or newer.

Authenticate

Create an API key in the dashboard (Settings, then API keys). Keys are scoped: an erp key prices lines, a connector key ingests data and claims write-backs. Send the key as a bearer token.

Price a line

import uuid

import elastly

configuration = elastly.Configuration(access_token="elastly_live_...")

with elastly.ApiClient(configuration) as api_client:
    prices = elastly.PricesApi(api_client)

    response = prices.get_prices(
        idempotency_key=str(uuid.uuid4()),
        prices_request=elastly.PricesRequest(
            lines=[
                elastly.PricesRequestLinesInner(
                    product_sku="SKU-1042",
                    customer_external_id="CUST-88",
                    quantity=25,
                )
            ]
        ),
    )

    for line in response.lines:
        result = line.actual_instance
        if result.ok:
            print(result.price_cents, result.currency, result.reason_summary)
        else:
            print("failed:", result.code, result.message)

Every response line is either a priced result (ok is true) or a per-line error. One bad line never fails the batch.

Retries and idempotency

POST /v1/prices requires an Idempotency-Key header. Use a fresh key for each logical request and reuse the same key on retries. A replay returns the stored response, so a retried call never prices twice.

Price with a deadline and a fallback

If you price inside a checkout or quote flow, use the serving layer instead of calling the API directly. It puts a hard deadline on the call (800ms by default), retries transient failures with backoff, trips a circuit breaker when Elastly is down (5 failures, 30 second cooldown), and falls back to a price you supply instead of blocking your flow.

import elastly
from elastly.serving import FallbackPrice, PricesNamespace, static_fallback
from elastly.transport import ElastlyTransport

configuration = elastly.Configuration(access_token="elastly_live_...")
client = elastly.ApiClient(configuration)
prices = PricesNamespace(ElastlyTransport(client))

result = prices.get(
    elastly.PricesRequestLinesInner(product_sku="SKU-1042", quantity=25),
    fail_open=static_fallback(lambda line, cause: FallbackPrice(price_cents=1500)),
)

if result.source == "elastly":
    print(result.price_cents, result.reason_summary)
elif result.source == "fallback":
    print(result.price_cents, "fallback because", result.cause.reason)
else:
    print("no price available:", result.cause.reason)

Every result carries a source: "elastly" (a real price), "fallback" (your resolver's price), or "unavailable" (your resolver returned None). Mistakes on your side, like an invalid request or a bad key, always raise a typed error from elastly.errors instead of falling back. Prefer an exception over a fallback price? Pass fail_open=throw_on_failure().

The transport handles retries and idempotency keys for you, so you do not need to manage the Idempotency-Key header yourself on this path.

Verify webhooks

Verify the elastly-signature header on every webhook before trusting the payload:

from elastly.webhooks import SignatureVerificationError, WebhooksNamespace

webhooks = WebhooksNamespace()
try:
    event = webhooks.verify(raw_body, signature_header, "whsec_...")
except SignatureVerificationError:
    ...  # reject with a 400
print(event.event, event.data)

verify checks the HMAC signature in constant time, rejects replays older than 5 minutes, and returns a typed event.

Close the loop

Elastly learns from the difference between the price it recommended and the price your team actually charged. When you ingest quotes, echo the pricingDecisionId you received from the prices call on the matching quote line. Skip that and the engine has nothing to learn from.

Documentation

About this repository

This code is generated from the Elastly OpenAPI contract, so pull requests against generated files get overwritten by the next release. If something is broken or missing, open an issue or email support@elastly.io.

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

elastly-0.2.0.tar.gz (67.3 kB view details)

Uploaded Source

Built Distribution

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

elastly-0.2.0-py3-none-any.whl (102.7 kB view details)

Uploaded Python 3

File details

Details for the file elastly-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for elastly-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c8032b491fc2fd76eed6bd76d0bfcfca75a5d920678919735efb92bd2ba93b24
MD5 6d5aa57658bbeb52f7c324b80e34ea55
BLAKE2b-256 b9a7de1df34d4e4651db0d298def9fc59a8fe7f99ecb03cdeba70383d552e8de

See more details on using hashes here.

Provenance

The following attestation bundles were made for elastly-0.2.0.tar.gz:

Publisher: publish.yml on elastly/elastly-python

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

File details

Details for the file elastly-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for elastly-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 488e188e5fb83cb84d07e2615eb6cd2e5fa9d21a5313e6ad8d96c6effe1c02ae
MD5 6a82481596dfa3973565db67023e36af
BLAKE2b-256 49a06398544bf157365884dd4dd37bdd38f0512ea6189c857440476dbe5c85bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for elastly-0.2.0-py3-none-any.whl:

Publisher: publish.yml on elastly/elastly-python

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