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.

With model="strom-extract-1.0.1", you can send plain text as text= instead of a document. Each field then has start and end instead of page and box: its position in your text, counted in Unicode characters, so text[start:end] is the field's text.

text = "Invoice no. 17795\nDate: 16 Dec 2026\nTotal EUR 428.40"
response = client.extract(model="strom-extract-1.0.1", text=text, schema=schema)
total = response.fields["total"]
text[total.start:total.end]           # "EUR 428.40"

strom-extract-1.0.1 also takes list fields, "type": "array": a list of strings or numbers, or of objects for a table's rows. The answer is an ExtractedList, with a confidence for the whole list and its items; in a table, each item is a dict of the row's answers, None where the row doesn't give one.

schema = {"properties": {"line_items": {"type": "array", "items": {"type": "object", "properties": {
    "description": {"type": "string"}, "amount": {"type": "number", "format": "amount"}}}}}}
response = client.extract(model="strom-extract-1.0.1", document="invoice.pdf", schema=schema)
for row in response.fields["line_items"].items:
    print(row["description"].value, row["amount"].value if row["amount"] else None)

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.8.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.8.0
File Size Uploaded Provenance Actions
uprelic-0.8.0.tar.gz 13.4 kB Without provenance Details for uprelic-0.8.0.tar.gz

Built distribution (wheel)

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

Total release size: 24.7 kB

Release files / uprelic-0.8.0.tar.gz

Download URL uprelic-0.8.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b066f7ccc4156046524cb675497d5c4858d195129f6fa3d267f67d87cbd2705d
BLAKE2b-256 checksum
How to use checksums
2def2972daffe6b9edb6e48b0ea51e7c919fd920fc235ac8244fefebc376e1b6
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.8.0-py3-none-any.whl

Download URL uprelic-0.8.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f07704e5797941ece38967b0561e640b6a02cc0e789ca9138114d9ce62d832a
BLAKE2b-256 checksum
How to use checksums
692460a94ac0904af4770e34270643995f3c14b89031cb653e5e99be38f4a33a
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.8.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