Skip to main content

weft-sdk for Python

The supported Python buyer client for Weft. Generated OpenAPI APIs remain available under weft_sdk.generated as an advanced escape hatch.

Install and authenticate

Use Python compatible with the requires-python contract in pyproject.toml. For source development, use the pinned Mise runtime and installation/build/unit steps in the repository README; those checks need no buyer key. This package is a library, not a server, so no independent start/stop step applies.

The examples below call a real Weft account and are optional consumer usage, not source setup verification. Create a buyer wk_* key in Dashboard → API keys, then:

pip install weft-sdk
export WEFT_API_KEY="wk_..."
import os

from weft_sdk import Client

api_key = os.environ["WEFT_API_KEY"]
with Client(api_key=api_key) as weft:
    account = weft.me()
    results = weft.search(query="weather data API", max_results=5)

print(account.data)
print(results.results)

The client defaults to https://weft.network.

Bounded paid fetch

Paid fetches require both a maximum cost and an idempotency key. Reuse the key when retrying the same logical purchase after an uncertain response.

from uuid import uuid4

idempotency_key = str(uuid4())
artifact = weft.fetch(
    url="https://merchant.example/data",
    max_cost_usd="0.05",
    idempotency_key=idempotency_key,
)

Handle API errors

All buyer-client methods raise the same WeftError shape, including the HTTP status, stable error code, request ID, retry hint, and structured details.

from weft_sdk import WeftError

try:
    results = weft.search(query="weather data API")
except WeftError as error:
    print(error.status, error.code, error.request_id, error.retryable, error.charge)
    print(error.details)
    raise
  • 401: confirm that WEFT_API_KEY contains a current buyer wk_* key.
  • 403: inspect code and details for an insufficient balance or spending policy denial before changing the request.
  • 409 (IDEMPOTENCY_CONFLICT): this buyer already used the supplied idempotency key for a different fetch request. Generate a new key for the new operation; the original operation retries unchanged with its own key. retryable is False — resending the conflicting request will conflict again.
  • 429: honor Retry-After and back off.
  • 5xx: retry transient failures with backoff; reuse the idempotency key for a paid fetch.
  • status == 0 (NETWORK_ERROR): the request failed before any Weft response, so the outcome is uncertain. retryable is True; retry with backoff and reuse the idempotency key for a paid fetch.
  • charge: "none" means this call cannot have paid. For a fetch, Weft refused before it signed a payment (for example EXCEEDED_MAX_COST or MERCHANT_RETURNED_NON_402). "possible" means this fetch can have paid (a 5xx, a network error, PAID_DELIVERY_FAILED). After "possible", retry only with the same idempotency key and the same request: Weft returns the stored response or reuses the existing payment. A new key can pay again. "none" covers this call only; an earlier call with the same key can still have paid.

See the API reference for the complete contract. Product guides live on weftlabs.com.

Seller middleware

Use WeftASGIMiddleware. weft_require_payment, weft_flask_require_payment, and WeftPaymentMiddleware do not work on x402 2.x. create_auth_headers must be synchronous. x402 reads those headers on a sync call.

Metadata

Release files for weft-sdk 0.32.5

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

Source distribution (sdist)

Source distribution for weft-sdk 0.32.5
File Size Uploaded Provenance
weft_sdk-0.32.5.tar.gz 138.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for weft-sdk 0.32.5
File Interpreter ABI Platform
weft_sdk-0.32.5-py3-none-any.whl Python 3 none any Details

Total release size: 579.3 kB

Release files / weft_sdk-0.32.5.tar.gz

Download URL weft_sdk-0.32.5.tar.gz
Size 138.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f0b759227ab02fc7354022df90f2f85858d3ebd07d11ccee027bbc62a74321bf
BLAKE2b-256 checksum
How to use checksums
42dc1985b86ad96f034be7cb5642f7dacdde7a529c3ae1cd79212e7c6c1e2db5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / weft_sdk-0.32.5-py3-none-any.whl

Download URL weft_sdk-0.32.5-py3-none-any.whl
Size 440.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab9e9a3435eb3326e215c740775cfffa8ef36036742939e45f53ba2da95d22e2
BLAKE2b-256 checksum
How to use checksums
2b967e01c91ee1c34a0ca7209f0abebd66accba52f90c946c167d076b8270201
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for weft-sdk 0.32.5

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for weft_sdk-0.32.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

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.

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