Async and sync Python client for the LibreNMS API.
- Dual interface β use
LibreClientAsyncfor async/await orLibreClientSyncfor traditional blocking calls. - Typed responses β all endpoints return Pydantic models with full IDE autocomplete.
- Environment-driven config β configure via
LIBRENMS_URLandLIBRENMS_TOKENenv vars or pass values directly.
pip install libreclientOr with uv:
uv add libreclientfrom libreclient import LibreClientSync
client = LibreClientSync(url="https://librenms.example.com", token="your-api-token")
# List all devices
response = client.devices.list_devices()
for device in response.devices:
print(device["hostname"])
# Get a specific alert
alert = client.alerts.get_alert(42)import asyncio
from libreclient import LibreClientAsync
async def main():
client = LibreClientAsync(url="https://librenms.example.com", token="your-api-token")
response = await client.devices.list_devices()
for device in response.devices:
print(device["hostname"])
await client.close()
asyncio.run(main())# Sync
with LibreClientSync(url="https://librenms.example.com", token="your-api-token") as client:
print(client.system.ping())
# Async
async with LibreClientAsync(url="https://librenms.example.com", token="your-api-token") as client:
print(await client.system.ping())Configuration is handled by pydantic-settings. You can pass values directly or set environment variables:
| Env Variable | Description | Default |
|---|---|---|
LIBRENMS_URL |
Base URL of your LibreNMS instance | (required) |
LIBRENMS_TOKEN |
API token (X-Auth-Token) |
(required) |
LIBRENMS_VERIFY_SSL |
Verify TLS certificates | true |
LIBRENMS_API_VERSION |
API version path segment | v0 |
A .env file is auto-discovered by searching from your current working directory upward. If none is found, it falls
back to ~/.env. Copy the included sample to get started:
cp sample.env .env
# Edit .env with your LibreNMS URL and API tokenThe search order is:
.envin the current working directory or any parent directory~/.env(home directory fallback)
All route namespaces are accessible as properties on the client:
| Property | Description |
|---|---|
client.alerts |
Alert management and alert rules/templates |
client.arp |
ARP table lookups |
client.bills |
Billing data and graphs |
client.device_groups |
Device group management |
client.devices |
Device CRUD, discovery, components, graphs |
client.index |
List available API endpoints |
client.inventory |
Hardware inventory |
client.locations |
Location management |
client.logs |
Event, syslog, alert, and auth logs |
client.poller_groups |
Poller group info |
client.pollers |
Poller status |
client.port_groups |
Port group management |
client.port_security |
Port security (802.1X/MAB) |
client.ports |
Port info, search, and descriptions |
client.routing |
BGP, OSPF, VRF, MPLS, IPsec |
client.services |
Service monitoring |
client.switching |
VLANs, links, FDB, NAC |
client.system |
Ping and system info |
Contributions are welcome! We're actively looking for contributors to help with:
- π Bug fixes and edge case handling
- β¨ Support for new routes as LibreNMS adds API endpoints
- π Documentation improvements
- π§ͺ Test coverage expansion
- π§ Tooling and CI improvements
Getting started:
- Fork the repo and create a branch from
dev - Follow the Development setup below
- Make your changes with tests
- Open a PR against
devβ CI will lint, test, and auto-fix formatting
See CONTRIBUTING.md for detailed guidelines, or just open an issue to discuss your idea first.
This section covers everything you need to set up a local development environment and contribute code to libreclient.
- Python 3.12+
- uv (package manager)
git clone https://github.com/jjeff07/libreclient.git
cd libreclient
uv syncThis project uses custom git hooks in the .githooks/ directory.
Setup (once per clone):
git config core.hooksPath .githooks| Hook | Purpose |
|---|---|
pre-commit |
Runs ruff check --fix and ruff format on staged .py files, re-stages fixes, then runs complexipy to enforce max cognitive complexity (15). |
commit-msg |
Validates commit messages against Conventional Commits format via commitizen. |
# Unit tests
uv run pytest tests/unit
# Functional tests (requires .env with LIBRENMS_URL and LIBRENMS_TOKEN)
uv run pytest tests/functionalThis project uses Ruff for both linting and formatting:
# Check for lint issues
uv run ruff check
# Auto-fix lint issues
uv run ruff check --fix
# Format code
uv run ruff format
# Check formatting without changing files
uv run ruff format --checkcomplexipy is used to enforce a maximum cognitive complexity of 15 per function:
uv run complexipy .Results are output to complexipy-results.json. Any function exceeding the threshold will cause the check to fail.
The project uses a single-implementation pattern: each route is written once as an async class. The synchronicity library then wraps each async class to produce a synchronous counterpart at runtime.
src/libreclient/routes/
βββ alerts.py β async implementation (the only code you write)
βββ alerts_sync.py β sync wrapper (imports Alerts, wraps with synchronizer)
This means:
- You only maintain one implementation per route.
- Both
LibreClientAsyncandLibreClientSyncshare the same logic. - No code duplication between sync and async interfaces.
Because synchronicity generates wrapper classes dynamically, IDEs can't infer their method signatures. To restore full
autocomplete and type checking, .pyi stub files are auto-generated.
Regenerate stubs locally:
uv run python scripts/generate_stubs.pyStubs are generated automatically during the GitHub Actions release workflow, so you don't need to commit them β they're
in .gitignore.
- Create
src/libreclient/routes/myroute.pywith an async class. - Create
src/libreclient/routes/myroute_sync.pywithMyRouteSync = synchronizer.wrap(...). - Create
src/libreclient/models/myroute.pywith Pydantic response models. - Add exports to
src/libreclient/models/__init__.py. - Wire up the route in
src/libreclient/client.py(both sync and async clients). - Run
uv run python scripts/generate_stubs.pyto regenerate stubs and__init__files. - Add tests in
tests/unit/routes/test_myroute.pyandtests/unit/models/test_myroute.py.
This project enforces Conventional Commits via commitizen. A git hook validates every commit message automatically.
Format:
type(scope)?: description
[optional body]
[optional footer]
Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, bump
See COMMIT_TYPES.md for full definitions and scope conventions.
Examples:
feat(routing): add OSPFv3 port listing
fix: handle empty response from list_devices
docs: add upstream tracking section to README
test: add functional tests for switching routes
This project tracks which LibreNMS release tag the route implementations are based on. The pinned version is stored in
upstream_tracking.toml.
# Check if upstream has a newer release
python scripts/check_upstream.py
# See which API doc files changed
python scripts/check_upstream.py --diff
# See full unified diffs of changed docs
python scripts/check_upstream.py --full
# Compare against a specific tag instead of latest
python scripts/check_upstream.py --diff --tag 26.6.0
# Bump the pinned tag after reviewing changes
python scripts/check_upstream.py --bumplibreclient/
βββ src/libreclient/
β βββ __init__.py # Public API exports
β βββ client.py # LibreClientSync & LibreClientAsync
β βββ config.py # Pydantic-settings configuration
β βββ _base_client.py # Shared HTTP transport logic
β βββ models/ # Pydantic response models
β βββ routes/ # Route namespaces (async + sync wrappers)
β βββ _types.py # ClientProtocol & utilities
β βββ _synchronicity.py # Shared Synchronizer instance
β βββ alerts.py # Async route implementation
β βββ alerts_sync.py # Sync wrapper
β βββ ...
βββ tests/
β βββ unit/
β β βββ models/ # Model validation tests
β β βββ routes/ # Route logic tests (MockClient)
β βββ functional/ # Live API tests (requires .env)
βββ scripts/
β βββ check_upstream.py # Detect upstream API doc changes
β βββ generate_stubs.py # .pyi stub generator
βββ .githooks/
β βββ pre-commit # Ruff lint & format
β βββ commit-msg # Conventional commit validation
βββ upstream_tracking.toml # Pinned LibreNMS release tag
βββ pyproject.toml
βββ CHANGELOG.md
βββ LICENSE