Python client
The avrel Python package reaches everything an AI assistant can reach in Avrel, with an agent key: read telemetry and incidents, check a release, record releases and test results, import archived readings, and propose hardware, evidence and safety rules for a person to accept. It also installs the avrel command for CI pipelines and terminals.
It works on Python 3.9 or newer and needs no other packages. Each call goes through the same permission checks as the app and is written to your organization's audit log, with the key's name.
The client is licensed under the Apache License 2.0, so you can read, change and redistribute it. Keep the LICENSE and NOTICE files that come with it when you do. The Avrel server is not covered by that licence.
Install#
Install the client from PyPI:
pip install avrel
Every Avrel server also serves the client that matches it. If your organization runs Avrel itself, install from its address instead (for example pip install --index-url https://avrel.example.internal/deploy/python/simple avrel), so the install works with no internet access. See Self-hosting.
The package has no dependencies. To read telemetry into pandas DataFrames, install pandas as well (pip install pandas).
Make a key#
- In Avrel, open Settings > AI assistants and create a key under Key for CI and scripts. Only owners see this.
- Pick the lowest access that does the job (see the table below).
- Store the key as a secret named
AVREL_KEY, and setAVREL_URLto your Avrel address. Never put the key in code or a log.
| Access | What the client can do with it |
|---|---|
| Read | Look at what a member of the organization can see, and check releases. |
| Propose | Also draft things a person then accepts in the app: hardware, evidence, requirements, safety rules, incident findings. |
| Operate | Also do what a pipeline does: record releases and test results, run the release checks, import history, save runs. |
A key acts for the person who made it, with their role at the moment of each call, so if their role changes, so does what the key can do. See Accounts and access.
Use it from Python#
import avrel
client = avrel.Client() # reads AVREL_URL and AVREL_KEY; or avrel.Client(url, key)
site = client.get_site() # the organization, its systems, setup and release gate
Every tool the key may use is a method of the client, with the same name and arguments as in AI assistants (MCP). client.tools() lists them with what each does, and help(client.get_release) shows one. The client asks your Avrel server which tools there are, so a tool added to Avrel can be used without a new version of the package.
Arguments are checked against the tool before anything is sent, so a misspelt argument fails at once with the names the tool takes.
Check a release#
gate = client.gate(release="v1.4.2", sha="3f2c9e1")
print(gate.summary())
if gate.blocked:
for check in gate.failing:
print(check["name"], check.get("fix"))
gate.verdict is APPROVED, BLOCKED or NO_SUITE (no check can run yet). This checks the build as if it were recorded next, without recording it. client.check_release(...) returns the gate's full answer as it comes from Avrel.
Record a release and its test results#
client.record_release(release="v1.4.2", sha="3f2c9e1", rollback_sha="9a01b44")
client.record_test_result(
ref="REQ-012", title="Thermal soak, 40 °C, 8 h", result="pass",
item="SN-0042", build="v1.4.2", procedure="TP-THERM-03",
measurements=[{"name": "board_temp", "value": 71.2, "unit": "°C", "max": 85}],
)
Both need an Operate key. A pass is refused if any measurement is outside its own limits. See Requirements and readiness records.
Import archived readings#
totals = client.import_file("logger_2026-10.csv.gz", unit_id="RIG-01",
columns={"timestamp": "_time", "value": "_value", "name": "measure"})
print(totals["readings"], "sent,", totals["stored"], "new times stored")
Files are CSV (one value per row) or JSON Lines, optionally gzipped, in the format described in Import history. They are read in parts and sent 5,000 readings at a time, so large archives fit in memory. Importing the same readings again stores nothing new. client.import_readings(rows, source="...") sends readings you already have in Python. Both need an Operate key.
Upload a full-rate recording#
r = client.upload_recording("flight-14.mcap", unit_id="UAV-03", source="Flight 14")
for rec in r["recordings"]:
print(rec["id"], rec["readings"], "readings kept at full rate")
The file goes up as it is (CSV or JSON Lines, optionally gzipped, Parquet, MCAP or TDMS, or a log from a controller or data logger) and Avrel keeps every reading in it; see Full-rate recordings. From a terminal: avrel upload flight-14.mcap --unit-id UAV-03. A CAN log needs its DBC (dbc="car.dbc", --dbc car.dbc), a log without GPS time needs the time it started (start_time="2026-11-30T09:15:00Z", --start-time), and a Campbell TOA5 file needs the zone of its logger's clock (time_zone="UTC", --time-zone). Needs an Operate key.
Read telemetry#
data = client.telemetry("RIG-01", start=1790000000, end=1790086400)
frame = avrel.to_dataframe(data) # needs pandas: one column per reading, times in UTC
Long ranges are averaged into buckets, and gaps stay empty. Times are seconds since the epoch.
Check a signed approval on a device#
Before your updater installs a build, check its signed release approval. This needs no key and no network, and nothing beyond the standard library:
from avrel.approvals import ApprovalRefused, verify_approval
try:
verify_approval("avrel-approval.json", organization="your-org-id",
public_keys=["MCowBQYDK2VwAyEA..."], artifact="firmware.bin")
except ApprovalRefused as exc:
raise SystemExit(f"Not installing: {exc}")
From a shell, avrel verify-approval does the same and exits 1 when the approval is refused, and avrel approval v1.4.2 -o avrel-approval.json downloads a release's approval in CI.
When something fails#
Every error is an avrel.AvrelError:
| Error | Meaning |
|---|---|
avrel.AuthError | The key or the address is not set, or Avrel did not accept the key (wrong or revoked). |
avrel.UnknownTool | No such tool for this key: its access or its owner's role does not allow it. |
avrel.Refused | Avrel refused the call: a missing or bad argument, a missing permission, or a conflict. The message says which. |
avrel.ConnectionFailed | Avrel could not be reached or did not answer as Avrel. |
Reads are retried a few times while the server is briefly unavailable. A change, such as recording a release, is sent once, so it is never made twice.
Use it from a terminal or CI#
export AVREL_URL=https://app.getavrel.com
export AVREL_KEY=ava_...
avrel gate --release v1.4.2 --sha "$GIT_SHA"
avrel record-release --release v1.4.2 --sha "$GIT_SHA" --rollback-sha "$PREVIOUS_SHA"
avrel record-release --release v1.4.3 --sha "$GIT_SHA" --override-reason "Hotfix, rig run follows"
avrel import influx_2026-10-01.csv.gz --unit-id CELL-4 \
--time-column _time --value-column _value --name-column measure --unit-of-measure-column _measurement
avrel tools -v
avrel call get_release release=v1.4.2
avrel call get_telemetry unit_id=RIG-01 from:=1790000000 to:=1790086400
avrel call runs any tool and prints its answer as JSON. Give arguments as name=text, or name:=json for numbers, lists and objects. --input args.json reads them from a file.
avrel gate exits with:
| Exit code | Meaning |
|---|---|
| 0 | The gate approves the release. |
| 1 | The gate blocks the release. Fail the build. |
| 2 | The gate has no checks that can run yet, so it cannot approve. Pass --allow-no-checks while you are setting up. |
| 3 | The key, the address or the server failed. Nothing was decided. |
On GitHub Actions the gate's result is also written to the job summary.
GitHub Actions example#
name: Release gate
on:
pull_request:
push:
branches: [main]
jobs:
avrel:
runs-on: ubuntu-latest
env:
AVREL_URL: https://app.getavrel.com
AVREL_KEY: ${{ secrets.AVREL_KEY }}
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install the Avrel client
run: pip install avrel
- name: Is this release safe to ship?
run: avrel gate --release "${{ github.ref_name }}" --sha "${{ github.sha }}"
- name: Record the release
if: github.event_name == 'push'
run: avrel record-release --release "${{ github.ref_name }}" --sha "${{ github.sha }}"
Put the record step after your deploy step, so Avrel only records what really shipped. The single-file command line in Release checks in CI does the same without pip.