Skip to main content

A Python SDK for uptimer

Project description

Uptimer Python SDK

Uptimer

A Python SDK for uptimer - a monitoring and uptime checking service.

License

This project is licensed under the MIT License - see the LICENSE file for details.

For third-party license information, see the NOTICE file.

Installation

pip install uptimer-python-sdk

or

uv add uptimer-python-sdk

Usage

Create client

self-hosted

from uptimer.client import UptimerClient
client = UptimerClient(
    api_key="your-api-key-here",
    base_url="http://127.0.0.1:2517/api",  # or your custom base URL
)

cloud

from uptimer.client import UptimerCloudClient
client = UptimerCloudClient(
    api_key="your-api-key-here",
)

Basic example

from uptimer.client import UptimerClient
from uptimer.models.rule import CreateRuleRequest, RuleRequest, RuleResponse, RuleResponseBody
from uptimer.errors import DefaultUptimerApiError, UptimerInvalidHttpCodeError, UptimerError
# Initialize the client
client = UptimerClient(
    api_key="your-api-key-here",
    base_url="http://127.0.0.1:2517/api",  # or your custom base URL
)
regions = client.v1.regions.all()
workspaces = client.v1.workspaces.all()
workspace_id = workspaces[0].id
rules =client.v1.rules.all(workspace_id)

new_rule = client.v1.rules.create(
    CreateRuleRequest(
        name="My Test Rule",
        interval=60,  # Check every 60 seconds
        workspace_id=workspace_id,
        request=RuleRequest(
            url="https://example.com",
            method="GET",  # PATCH, POST, HEAD
            content_type="application/json",  # expected content type
            data="",  # data (substring) that should be contained in resonse
        ),
        response=RuleResponse(
            statuses=[200, 201, 202],  # any of this status means site is up
            body=RuleResponseBody(content="expected response"),
        ),
    ),
)

new_rule_updated = client.v1.rules.update(
    new_rule.id,
    CreateRuleRequest(
        name="Updated Rule Name",
        interval=120,  # Change to 2 minutes
        workspace_id=workspace_id,
        request=RuleRequest(
            url="https://updated-example.com",
            method="POST",
            content_type="application/json",
            data='{"key": "value"}',
        ),
        response=RuleResponse(
            statuses=[200, 201],
            body=RuleResponseBody(content="updated expected response"),
        ),
    ),
)

# caching errors on delete example
try:
  client.v1.rules.delete(new_rule_updated.id)
except DefaultUptimerApiError as e:
  # error responses from uptimer server
  print(
    e.message,  # user message
    e.code,  # error id
    e.error_type,  # class of error,
    e.details,  # detailed message for a developer
  )
except UptimerInvalidHttpCodeError as e:
  # uptimer api always return 200, if not -> http transport error
  # for an example 404 status is really page (url) not found, it doesn't mean that an object with id not found.
  print(
    e.url,
    e.status_code,
  )
except UptimerError as e: # base error, if you need one
  raise

Also, check out examples directory

Development Setup

  1. Clone the repository:
git clone <repository-url>
cd uptimer-python-sdk
  1. Install dependencies:
uv sync --dev
# for integration tests
uv run playwright install chromium
  1. Run tests:
uv run pytest
# integration
docker pull myuptime/uptimer
docker run -p 2517:2517 myuptime/uptimer
UPTIMER_URL=http://localhost:2517  uv run --integration
  1. Run linting:
uv run ruff check .
uv run mypy src
  1. Format code:
uv run ruff format .
  1. Run pre-commit hooks:
uv run pre-commit run --all-files

Third-Party Licenses

This project uses the following third-party libraries:

Production Dependencies

  • httpx (BSD 3-Clause License) - HTTP client for Python

Development Dependencies

  • mypy (Apache 2.0 License) - Static type checker
  • playwright (Apache 2.0 License) - Browser automation
  • pre-commit (MIT License) - Git hooks framework
  • pytest (MIT License) - Testing framework
  • pytest-cov (MIT License) - Coverage plugin for pytest
  • pytest-httpx (MIT License) - HTTPX plugin for pytest
  • pytest-playwright (MIT License) - Playwright plugin for pytest
  • responses (Apache 2.0 License) - Mock library for requests
  • ruff (MIT License) - Fast Python linter and formatter

All third-party licenses are compatible with the MIT License used by this project. Note that the BSD 3-Clause License (used by httpx) includes an additional restriction prohibiting the use of the copyright holder's name for endorsement without permission.

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

uptimer_python_sdk-0.3.0.tar.gz (72.8 kB view details)

Uploaded Source

Built Distribution

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

uptimer_python_sdk-0.3.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file uptimer_python_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: uptimer_python_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 72.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for uptimer_python_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d43de71341d74b29224a9e5c526451686bf3463c9742a3827084f7b163e7c0cd
MD5 ff87c1f0a942baab58497bc1469d4595
BLAKE2b-256 88fb807af5996f168ee92b1a9ba4cf154a4bd1da73e161952279aa83f497d85f

See more details on using hashes here.

File details

Details for the file uptimer_python_sdk-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for uptimer_python_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf043313bd7db8cad518bd28553df351c903477d2525d6adb7e9912890d3e65
MD5 9da1d8f9e067dbc60dcce10b495f2968
BLAKE2b-256 32d66a4db01b3b1ad54dac2413a7b21bd557cc2ee87c23e80f6b8adb6481410d

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