Skip to main content

Uprelic Python SDK

pip install uprelic

Set UPRELIC_API_KEY (create a key at https://platform.uprelic.com), or pass api_key= to the client.

from uprelic import Uprelic, Noul, Choice, Score

client = Uprelic()
response = client.system_one(
    model="strom-1.0.7",
    state="I was charged twice for my subscription. Please fix this today.",
    questions={
        "billing": Noul("Is this message about billing?"),
        "tone": Choice("What is the tone?", criteria={"angry": "Upset or hostile", "calm": "Neutral or polite"}),
        "urgency": Score("How urgent is this?", criteria=["Can wait", "This week", "Today"]),
    },
)

response.nouls["billing"].noul        # 0.98
response.choices["tone"].choice       # "angry"
response.scores["urgency"].score      # 1.8
response.usage.input_tokens
response.usage.cost                   # in response.usage.currency
response.metadata.server_processing_time_ms

Images go in images= as http(s) or data:image/... URLs. Box("the white SUV", image=0) (beta) finds an object in an image: response.boxes["suv"].box has its left, top, right and bottom edges as fractions of the image's width and height. With multiple=True it finds every match instead: response.boxes["cars"].boxes lists each one's box and probability, most likely first. client.models() lists the available models: strom-1.0.7 (alias strom-fast) and strom-base-1.0 (alias strom-base, in beta).

Document extraction

client.extract() takes one PDF (at most 8 pages) or image and a JSON Schema whose properties are the fields to extract: strings (format: date), numbers (format: amount or percent), booleans or string enums.

from pathlib import Path

response = client.extract(
    model="strom-1.0.7",
    document=Path("invoice.pdf"),  # or bytes, or an http(s) or data: URL
    schema={"properties": {
        "invoice_date": {"type": "string", "format": "date"},
        "total": {"type": "number", "format": "amount", "description": "The total including tax"},
    }},
)

response.fields["total"].value        # 1234.5
response.fields["total"].text         # "Total EUR 1.234,50", the line it came from
response.fields["total"].confidence   # 0.94
response.fields["total"].page, response.fields["total"].box

A field the document doesn't give is None. When the line holds more than one value of the field's type, value is the whole line.

Zero data retention

private=True sends client.system_one() or client.extract() to the private endpoint, which stores no request or response content. It costs 20% more and needs a paid plan or the zero data retention subscription. See https://platform.uprelic.com/docs/zero-data-retention.

response = client.extract(model="strom-1.0.7", document=Path("payslip.pdf"), schema=schema, private=True)

Agent guard

Rules in plain words, checked at one of three stages: a tool call before it runs (before_tool, the default), a tool's result before the agent sees it (after_tool), or a reply before the user sees it (before_reply):

client.create_guard_rule("refund-limit", text="Block refunds above 500 unless the user's role is manager.",
                         tools=["refund"], mode="enforce", threshold=0.9)
client.create_guard_rule("no-secrets", text="Block file contents that contain passwords or API keys.",
                         stage="after_tool", tools=["read_file"], mode="enforce")

create_guard_rule raises APIError (409) when the id is taken. Change a rule with update_guard_rule(), which takes the same arguments and saves a new version.

Decorate a tool with client.guard(). Each call is checked first, with the function's arguments as params:

@client.guard("refund", context=lambda: {"role": current_user.role})
def refund(order_id, amount):
    ...

try:
    refund("A1", amount=800)
except uprelic.Blocked as blocked:
    str(blocked)   # "refund blocked by refund-limit: Refunds over 500 need a manager." Return it to the model.

Blocked is raised when an enforced rule matches, and also when the check itself fails (no balance, network down), so an unchecked action never runs. With @client.guard("read_file", check_result=True) the return value is checked as well, and Blocked (with .stage == "after_tool") is raised instead of returning it. A rule in observe mode only reports would_block; the function runs.

To check without the decorator, call client.check(action="refund", params={...}), add result=... for a tool's result, or client.check(response="...", request="...") for a reply. Each rule that applies costs $0.01 per 1,000 checks.

Before enforcing a rule, see what it would have blocked: client.guard_checks(decision="would_block") returns your checks of the last 90 days, newest first (.checks, .total; page with page= and page_size=).

Video detection

client.video_detection() finds the object you describe in every frame of a video at a public http(s) URL (at most 10 minutes and 500 MB). It waits for the job, about 30 seconds per video minute, and costs 0.10 USD per video minute.

job = client.video_detection(description="Player with the ball", video="https://example.com/match.mp4")

for frame in job.frames:  # 5 a second
    if frame.box:         # None when the object isn't in the frame
        print(frame.t, frame.box.left, frame.box.top, frame.box.right, frame.box.bottom, frame.confidence)

A job that fails raises uprelic.VideoDetectionFailed, with the job as .job and the reason as .job.error.

Async

from uprelic import AsyncUprelic

async with AsyncUprelic() as client:
    response = await client.system_one(model="strom-1.0.7", state="...", questions={...})

Errors and retries

Failed requests raise uprelic.APIError subclasses: AuthenticationError (401), InsufficientBalanceError (402), InvalidRequestError (400, 413, 422), RateLimitError (429) and ServerError (5xx). Each has status_code and detail.

Rate limits (429), 502/503/504 responses and connection failures are retried twice with backoff. Change this with Uprelic(max_retries=...).

API reference: https://api.uprelic.com/v1/docs

Metadata

Release files for uprelic 0.6.0

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

Source distribution (sdist)

Source distribution for uprelic 0.6.0
File Size Uploaded Provenance Actions
uprelic-0.6.0.tar.gz 12.4 kB Without provenance Details for uprelic-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uprelic 0.6.0
File Interpreter ABI Platform Actions
uprelic-0.6.0-py3-none-any.whl Python 3 none any Details for uprelic-0.6.0-py3-none-any.whl

Total release size: 23.1 kB

Release files / uprelic-0.6.0.tar.gz

Download URL uprelic-0.6.0.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6cc49d54cc62a1ffbab5b491ecd4398a6f57117893e9be265d6bc2bc167773de
BLAKE2b-256 checksum
How to use checksums
a16f292b06599dc33f40ddeddfaaec7f8321dc52fbfca6568dcb59ae11b4741b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / uprelic-0.6.0-py3-none-any.whl

Download URL uprelic-0.6.0-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
968c9934b5295e4de13c108ef567d360b94a76d795112817c9b92a66de4b2995
BLAKE2b-256 checksum
How to use checksums
f962098b18b1f48c87f5e7e1691efd151438a34570b1d66e04d51765b59cb316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for uprelic 0.6.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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