Skip to main content

Automatic API fallback via Strale — when your primary API fails, Strale picks up the call

Project description

strale-fallback

When your agent's primary API fails, Strale picks up the call.

strale-fallback wraps any function in your agent pipeline. When the primary call fails (timeout, 429, 503, malformed response), it automatically finds a matching Strale capability and executes it — returning structured JSON with a quality score.

Install

pip install strale-fallback

Usage

import os
from strale_fallback import with_fallback

@with_fallback(
    task_description="validate IBAN number",
    strale_api_key=os.environ["STRALE_API_KEY"]
)
async def validate_iban(iban: str):
    # Your primary API call — if this fails, Strale takes over
    return await my_primary_api.validate_iban(iban)

result = await validate_iban("SE3550000000054910000003")
print(result.source)           # "primary" or "strale_fallback"
print(result.data)             # structured JSON either way
print(result.capability_used)  # e.g. "iban-validate" (if fallback used)

Sync functions work too:

@with_fallback(task_description="check company sanctions")
def check_sanctions(company_name: str):
    return requests.get(f"https://my-api.com/sanctions/{company_name}").json()

How it works

  1. Your primary function is called normally
  2. If it throws (any HTTP error, timeout, or exception), strale-fallback calls POST /v1/suggest with your taskDescription to find the best matching Strale capability
  3. It executes that capability with your function's arguments as inputs
  4. Returns a FallbackResult with source: "strale_fallback" so you know which path was taken

FallbackResult

Field Type Description
success bool Whether a result was obtained
data any The result data
source string "primary" or "strale_fallback"
capability_used string? Strale capability slug if fallback used
strale_sqs float? Quality score (0-100) if fallback used
error string? Error message if both paths failed

Quality threshold

# Only use Strale as fallback if SQS quality score >= 80
@with_fallback(
    task_description="check company sanctions",
    min_sqs=80
)
async def check_sanctions(company: str): ...

Environment

Set STRALE_API_KEY — or pass it directly to the decorator. Get a free key with trial credits: https://strale.dev/signup

Free capabilities (no key needed)

iban-validate, email-validate, dns-lookup, json-repair, url-to-markdown — these work even without an API key.

Full capability catalog: https://strale.dev/capabilities

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

strale_fallback-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

strale_fallback-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file strale_fallback-0.1.0.tar.gz.

File metadata

  • Download URL: strale_fallback-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for strale_fallback-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f6d387f3fa11c01ae2daab34d2c32c08e3960f925fc1fff6d646a762f19494e5
MD5 57fe2a7923136d5875f85906fbe393d7
BLAKE2b-256 17ecfa691493c786b6ff14c74e18cb2bf57b7cc1610c38995787395a3d374ede

See more details on using hashes here.

File details

Details for the file strale_fallback-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for strale_fallback-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 009cf7a527b132315e024301270ed4ee25cb5685edf4f6d8eac8f54f82432b3a
MD5 06ce2b9cf6001d82d258916b96d085c8
BLAKE2b-256 e36f8b5d9ce89bb357220d718d3703b57834b13d97e6e926030980d44733c4fd

See more details on using hashes here.

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