uptime-kuma-api2
A wrapper for the Uptime Kuma Socket.IO API — with full v2 support
About this project: uptime-kuma-api2 is an independent continuation of lucasheld/uptime-kuma-api, the original library created by Lucas Held. That project appears to be unmaintained — its last release was in 2023, and open issues and pull requests (including several adding Uptime Kuma 2.x support) have sat unreviewed and unmerged. Rather than leave 2.x users without a working library, this project carries the code forward with full v2.x support while keeping backward compatibility with v1.x.
It began as a fork and is published under the original MIT license. Lucas Held's copyright is retained in LICENSE alongside the later changes — full credit to him for building the foundation. This is a continuation, not a replacement: if the original project becomes active again, the changes here are available to contribute back upstream.
Naming: the PyPI distribution is
uptime-kuma-api2, while the import package remainsuptime_kuma_apiso existing code works unchanged. The similarly named PyPI projectsuptime-kuma-api(the original) anduptime-kuma-api-v2(a different maintainer) are separate from this one. The repository was renamed fromuptime-kuma-api-v2touptime-kuma-api2to match the PyPI name; the old URL redirects automatically.
uptime-kuma-api2 is a Python wrapper for the Uptime Kuma Socket.IO API.
This package was originally developed to configure Uptime Kuma with Ansible. The original Ansible collection can be found at https://github.com/lucasheld/ansible-uptime-kuma.
Python version 3.8+ is required. Tested on 3.8 through 3.13.
Supported Uptime Kuma versions:
| Uptime Kuma | uptime-kuma-api2 |
|---|---|
| 2.0.0 - 2.4.0 | 2.0.0 - 2.2.1 |
| 1.21.3 - 1.23.2 | 1.0.0 - 1.2.1 |
| 1.17.0 - 1.21.2 | 0.1.0 - 0.13.0 |
Releases 1.2.1 and earlier were published under the upstream uptime-kuma-api name; 2.0.0 onward are published as uptime-kuma-api2.
Installation
uptime-kuma-api2 is available on the Python Package Index (PyPI).
You can install it using pip:
pip install uptime-kuma-api2
Documentation
The API reference is published on Read the Docs.
You can also build it locally with Sphinx:
pip install -r dev-requirements.txt
cd docs && make html
Note: uptime-kuma-api.readthedocs.io (without the 2) is the original project's site and does not cover this project's v2 features.
Example
Once you have installed the python package, you can use it to communicate with an Uptime Kuma instance.
To do so, import UptimeKumaApi from the library and specify the Uptime Kuma server url (e.g. 'http://127.0.0.1:3001'), username and password to initialize the connection.
>>> from uptime_kuma_api import UptimeKumaApi, MonitorType
>>> api = UptimeKumaApi('INSERT_URL')
>>> api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
Now you can call one of the existing methods of the instance. For example create a new monitor:
>>> result = api.add_monitor(type=MonitorType.HTTP, name="Google", url="https://google.com")
>>> print(result)
{'msg': 'Added Successfully.', 'monitorID': 1}
At the end, the connection to the API must be disconnected so that the program does not block.
>>> api.disconnect()
With a context manager, the disconnect method is called automatically:
from uptime_kuma_api import UptimeKumaApi
with UptimeKumaApi('INSERT_URL') as api:
api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
api.add_monitor(
type=MonitorType.HTTP,
name="Google",
url="https://google.com"
)
MonitorBuilder
For complex monitor configurations, use the fluent MonitorBuilder:
from uptime_kuma_api import UptimeKumaApi, MonitorType, MonitorBuilder
with UptimeKumaApi('INSERT_URL') as api:
api.login('INSERT_USERNAME', 'INSERT_PASSWORD')
config = (
MonitorBuilder()
.type(MonitorType.HTTP)
.name("My Monitor")
.url("https://example.com")
.interval(60)
.conditions([
{"type": "expression", "variable": "response_status", "operator": "==", "value": "200", "andOr": ""}
])
.build()
)
result = api.add_monitor(**config)
print(result)
New in v2.1.0
- New monitor types: RabbitMQ, SNMP, SMTP, System Service
- New notification providers: Nextcloud Talk, Brevo, Evolution API
- MonitorBuilder: Fluent builder pattern for monitor configuration
- Logger support: Pass a custom logger for Socket.IO debugging
- v2-only parameters: Automatic version gating ensures backward compatibility with v1.x
Testing
The v2 unit tests need no live server. These are the tests CI runs:
pip install pytest
pytest tests/test_monitor_types_v2.py tests/test_monitor_params_v2.py tests/test_status_page_v2.py tests/test_notification_v2.py tests/test_logger.py tests/test_monitor_builder.py -v
The remaining test files are integration tests inherited from upstream. They expect a live Uptime Kuma instance at http://127.0.0.1:3001 and will delete all monitors, notifications, proxies, tags, status pages, docker hosts, maintenances and API keys on that instance, so never point them at a production server.
Test files:
| File | Coverage |
|---|---|
tests/test_monitor_types_v2.py |
New monitor types (RABBITMQ, SNMP, SMTP, SYSTEM_SERVICE) |
tests/test_monitor_params_v2.py |
v2 monitor parameters, version gating, validation |
tests/test_status_page_v2.py |
Status page analytics replacement, password removal, new fields |
tests/test_notification_v2.py |
Nextcloud Talk, Brevo, Evolution API providers |
tests/test_logger.py |
Logger parameter type validation |
tests/test_monitor_builder.py |
MonitorBuilder fluent API |
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 uptime_kuma_api2-2.2.1.tar.gz.
File metadata
- Download URL: uptime_kuma_api2-2.2.1.tar.gz
- Upload date:
- Size: 70.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c792ffb635f6682a189cff28de940e1690b40989d5a4fbcd362f7ddf70f8bc42
|
|
| MD5 |
c611973f0eb5b7edcccd63470c29b255
|
|
| BLAKE2b-256 |
d6a1944d2f8a2959249c9841cb9bd5176ec9e8a8bb3220d3870405e12208cbd1
|
File details
Details for the file uptime_kuma_api2-2.2.1-py3-none-any.whl.
File metadata
- Download URL: uptime_kuma_api2-2.2.1-py3-none-any.whl
- Upload date:
- Size: 54.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dcf0766862cc106c8281c7b2490a74a93ec7f482e778b1e6fe2be18ab2cb52a
|
|
| MD5 |
4b3d5ac8ae2f00a608be1327d3a73a01
|
|
| BLAKE2b-256 |
81296851fb111d5dba160dcb78f33c3284609d2774cfe39d962fe1b5ac5e0ca3
|