Skip to main content

A python wrapper for the Uptime Kuma WebSocket API (v2 support)

Project description

uptime-kuma-api-v2

A wrapper for the Uptime Kuma Socket.IO API — with full v2 support


Fork notice: This is an actively maintained fork of lucasheld/uptime-kuma-api, which appears to be unmaintained (last release: 2023, open PRs unanswered). This fork adds full Uptime Kuma v2.x support while maintaining backward compatibility with v1.x. Original work by Lucas Held — thank you for building the foundation.

uptime-kuma-api-v2 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.7+ is required.

Supported Uptime Kuma versions:

| Uptime Kuma | uptime-kuma-api |

|-----------------|-----------------|

| 2.0.0 - 2.4.0 | 2.0.0 - 2.1.0 |

| 1.21.3 - 1.23.2 | 1.0.0 - 1.2.1 |

| 1.17.0 - 1.21.2 | 0.1.0 - 0.13.0 |

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 available on Read the Docs.

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


Unit tests cover all v2 features and can be run without a live server:


pip install pytest

pytest tests/ -v

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 |

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uptime_kuma_api2-2.1.0.tar.gz (66.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uptime_kuma_api2-2.1.0-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file uptime_kuma_api2-2.1.0.tar.gz.

File metadata

  • Download URL: uptime_kuma_api2-2.1.0.tar.gz
  • Upload date:
  • Size: 66.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for uptime_kuma_api2-2.1.0.tar.gz
Algorithm Hash digest
SHA256 ffdd3471201a3e5b872e8c4959e46ac0726160e135d75095aba8d011777c98b9
MD5 9bbfd072bee8de2ae2809a15518e2492
BLAKE2b-256 e805abb99f8bd0c945ecfd40458229b5b5fe643416b8b39188f4742435f91afa

See more details on using hashes here.

File details

Details for the file uptime_kuma_api2-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uptime_kuma_api2-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 686aeb0970ce91ce37a0bf34f6e7689041368b28605c34235f0c9867ee6cde99
MD5 4640d6da62bc10637df9ecc8d7096ddd
BLAKE2b-256 55915945c64724385c4e7ede0eb6b164ba1f008be01a366a4ce18595d8a16b7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page