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. 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.

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=).

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.4.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.4.0
File Size Uploaded Provenance Actions
uprelic-0.4.0.tar.gz 10.3 kB Without provenance Details for uprelic-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.5 kB

Release files / uprelic-0.4.0.tar.gz

Download URL uprelic-0.4.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
edc0141f26685f6b3836589047f499bc1a679b9c74e55e4ffe4872dd503a051e
BLAKE2b-256 checksum
How to use checksums
cb42f563613c0e5e8a1abe9a6f194882ffe0abb2ca1f38a1a99917db03fa9af2
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.4.0-py3-none-any.whl

Download URL uprelic-0.4.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9ee7da312f1124b69478d3c3167599fc4ab34b11f9cdee4f8dc611658ca1e63
BLAKE2b-256 checksum
How to use checksums
16436ff3809a07faa5def250233abe2baddb667a8bfea2a61f3a0f077022d48d
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.4.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