Minimal Zabbix JSON-RPC API client (httpx-based)
Project description
zapi-lib
Minimal Zabbix JSON-RPC API client for Python — a thin,
httpx-only wrapper around the single /api_jsonrpc.php endpoint.
Spun out of zapi-mcp so that tools which only
need the API client — e.g. speedtest-z —
can depend on it without pulling in the MCP server stack (mcp, starlette, uvicorn, …).
Features
- Version-adaptive auth:
user+authfield (Zabbix ≤ 6.2) andusername+Authorization: Bearer(6.4 / 7.0), degrading to the proven path automatically. - Read helpers:
get_hosts,get_items,get_problems,count_problems,get_events. - Write helpers:
set_host_tag(idempotent host-tag upsert that preserves other tags),acknowledge_problem. - Provisioning (
ZapiProvisioner): config-driven client that auto-creates trapper hosts/items stamped with a managed-by tag —create_host,update_host,create_item,update_item,set_maintenance, plusensure_group/get_host_ids/get_item_ids. - Escape hatch:
call(method, params)invokes any JSON-RPC method directly. - A single runtime dependency:
httpx.
Install
pip install zapi-lib
Usage
from zapi_lib import ZapiClient, tag_filter
with ZapiClient("https://zabbix.example.com", "api-user", "api-pass") as z:
hosts = z.get_hosts(tags=[tag_filter("speedtest-z")])
z.set_host_tag("eduroam", "speedtest-z", "0.10.0")
The URL may be given with or without the /api_jsonrpc.php suffix.
Provisioning (config-driven)
ZapiProvisioner extends ZapiClient for metric-collection scripts that register the
targets they push values to. It reads connection and provisioning defaults from a
config.ini [zabbix] section and auto-creates trapper hosts/items tagged with a
managed-by marker:
[zabbix]
url = https://zabbix.example.com/api_jsonrpc.php
id = api-user ; or `user`
pw = api-pass ; or `password`
group = DefaultGroup ; default host group for created/updated hosts
location = tokyo ; optional; added as a `location` tag
tag = my-collector ; optional; managed-by marker tag on hosts/items
from zapi_lib import ZapiProvisioner
with ZapiProvisioner.from_config() as z: # ./config.ini, then ~/.config.ini
z.show_version()
host_ids = z.get_host_ids("pool-a") or z.create_host("pool-a", location="tokyo")
host_id = host_ids[0]
if not z.get_item_ids(host_id, "usage"):
z.create_item(host_id, "usage", value_type=0)
update_host replaces the host's groups and tags (use set_host_tag to upsert a single
tag instead). set_maintenance(location, since, till, name, description) opens an
idempotent maintenance window over hosts carrying a matching location tag.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zapi_lib-0.3.0.tar.gz.
File metadata
- Download URL: zapi_lib-0.3.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5d0b347ba0b31dbd9c2424f1c9760e585dbe24ff936c78c86c13590fe3d8a5d
|
|
| MD5 |
88923e7d153add53cad26cbed0bdc927
|
|
| BLAKE2b-256 |
04c7bd104cc43de01b7c09e993f97c797d9e54ffd79c6a69bc88b78a5dfdc6b7
|
Provenance
The following attestation bundles were made for zapi_lib-0.3.0.tar.gz:
Publisher:
release.yml on shigechika/zapi-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zapi_lib-0.3.0.tar.gz -
Subject digest:
e5d0b347ba0b31dbd9c2424f1c9760e585dbe24ff936c78c86c13590fe3d8a5d - Sigstore transparency entry: 1741068900
- Sigstore integration time:
-
Permalink:
shigechika/zapi-lib@e07e5d669e9e29f775700f5c37ce774e871f6589 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/shigechika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e07e5d669e9e29f775700f5c37ce774e871f6589 -
Trigger Event:
release
-
Statement type:
File details
Details for the file zapi_lib-0.3.0-py3-none-any.whl.
File metadata
- Download URL: zapi_lib-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
973af1b6f8eb24f327e471eb80c19d07d09815bb420de8ca7fb3fbb152fdce7d
|
|
| MD5 |
e2bb30ab76e1897a8134b45d8372db00
|
|
| BLAKE2b-256 |
20e074644b9af98b71859214355f148976bffcda0418f41cb58bb8bc2b2dece3
|
Provenance
The following attestation bundles were made for zapi_lib-0.3.0-py3-none-any.whl:
Publisher:
release.yml on shigechika/zapi-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zapi_lib-0.3.0-py3-none-any.whl -
Subject digest:
973af1b6f8eb24f327e471eb80c19d07d09815bb420de8ca7fb3fbb152fdce7d - Sigstore transparency entry: 1741068946
- Sigstore integration time:
-
Permalink:
shigechika/zapi-lib@e07e5d669e9e29f775700f5c37ce774e871f6589 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/shigechika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e07e5d669e9e29f775700f5c37ce774e871f6589 -
Trigger Event:
release
-
Statement type: