Skip to main content

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.

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.4.0.tar.gz (78.0 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.4.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for uptimer_python_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 09730a6e600e2b9200bec81d5b20efd59a5cebc16cd3d7370acc7d6067ffd951
MD5 d4c8c9bab7338583169ab84e9bdaae06
BLAKE2b-256 c24cc38a9e7455d9ec50ac1d55bcac8cba8a662ad62e302cb25ac65b2e8afd0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uptimer_python_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62688b2351b6ee7d1af07eddff31e6bf4720f3d33dcaf00f38d810be9d5f1024
MD5 8e9aa5cad26a0d340567d922cd02aeb2
BLAKE2b-256 a95b1901856bc794e908fda7fd3d6236e4fb7a2ba3539716dfe679c00cfbe791

See more details on using hashes here.

Release history Release notifications | RSS feed

1.5.0

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

Supported by

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