This is a Python API wrapper for Uptime Robot that provides async methods to interact with the Uptime Robot API for monitoring uptime and managing monitors.
pyuptimerobot is a Python library that wraps the Uptime Robot API, providing an easy-to-use async interface for fetching account details, managing monitors, and handling uptime data. The library is designed to be simple, reliable, and follows modern Python best practices.
- Run
scripts/lintto format code with isort and black - Run
scripts/testto ensure all tests pass - Use the provided scripts in the
scripts/directory for consistency
- Setup:
scripts/setup- Install dependencies and set up development environment - Test:
scripts/test- Run the full test suite with pytest - Lint:
scripts/lint- Format and lint code (isort + black + mypy) - Lint check:
scripts/lint-check- Check code formatting without making changes - Coverage:
scripts/coverage- Generate test coverage reports (must be 100%) - Build:
scripts/build- Build the package
pyuptimerobot/- Main package source code__init__.py- Package exportsuptimerobot.py- Main UptimeRobot API clientdecorator.py- Request decorators for API callsmodels.py- Data models for API responsesexceptions.py- Custom exception classesconst.py- Constants and configuration
tests/- Test suite using pytest and aresponsestest_*.py- Test files for different API endpointsfixtures/- Test fixtures and mock datacommon.py- Common test utilities
scripts/- Development scripts following "Scripts to Rule Them All" patternexample.py- Usage examples
- Python version: Support Python 3.13+ (as specified in pyproject.toml)
- Dependencies: Keep dependencies minimal - currently only aiohttp for runtime
- Type hints: Use type hints throughout for better IDE support
- Docstrings: Follow Google-style docstrings for classes and public methods
- Import style: Keep imports clean and organized (isort handles this)
- Async/await: All API methods use async/await pattern
- Use aiohttp for async HTTP requests
- Apply the
@endpointdecorator for API endpoint methods - Handle errors gracefully and provide meaningful exceptions
- Support all Uptime Robot API endpoints consistently
- 100% coverage required: All code must have test coverage
- Mock API responses: Use aresponses to mock HTTP responses
- Test fixtures: Use JSON fixtures in
tests/fixtures/for response data - Edge cases: Test error scenarios, timeouts, and malformed responses
- Async testing: Use pytest-asyncio for async test support
- Use custom exceptions from
exceptions.py - Provide clear error messages for API failures
- Handle connection errors, timeouts, and invalid responses
- Validate API responses before processing
- This library is used in production - maintain API compatibility
- Deprecate features gracefully before removal
- Follow semantic versioning for releases
- Add the method to
uptimerobot.pywith@endpointdecorator - Define response models in
models.pyif needed - Add test fixtures in
tests/fixtures/ - Create comprehensive tests in
tests/ - Update documentation and examples
from .exceptions import (
UptimeRobotException,
UptimeRobotApiKeyException,
UptimeRobotConnectionException,
)
# Raise specific exceptions for different error types
if api_key_invalid:
raise UptimeRobotApiKeyException("Invalid API key")
if connection_failed:
raise UptimeRobotConnectionException("Failed to connect to API")import pytest
from aresponses import ResponsesMockServer
from pyuptimerobot import UptimeRobot
from tests.common import fixture, TEST_API_TOKEN
@pytest.mark.asyncio
async def test_api_method(aresponses: ResponsesMockServer):
"""Test API method with mock response."""
aresponses.add(
"api.uptimerobot.com",
"/v2/endpoint",
"POST",
response=fixture("endpoint_response"),
status=200,
)
async with aiohttp.ClientSession() as session:
api = UptimeRobot(TEST_API_TOKEN, session)
result = await api.async_method()
assert result is not None- Use
scripts/testfor full test suite - Tests must pass and coverage must be 100%
- Use
scripts/coverageto verify coverage
- Follow the existing pattern in test files
- Use descriptive test names
- Mock all external API calls with aresponses
- Use fixtures for response data
- Test both success and failure scenarios
- Keep README.md updated with usage examples
- Use clear, concise examples that users can copy-paste
- Document any breaking changes in release notes
- Include type information in documentation
- Follow Google's Markdown style guide:
- ALWAYS put a blank line before and after headings - this is mandatory
- Use ATX-style headings (
#) - Use backticks for code, filenames, and technical terms
- Use numbered lists for procedures, bullet lists for non-sequential items
- Use conventional commit messages
- Keep commits focused and atomic
- Include tests with feature additions
- Update documentation for user-facing changes
- This is an API wrapper - maintain consistency with Uptime Robot API
- All API methods must be async
- Use the
@endpointdecorator for API methods - Mock all HTTP requests in tests - no real API calls
- Use the existing script system rather than running commands directly
- Maintain 100% test coverage requirement
- Do not add inline comments to code unless specifically requested by the user.
Before considering any code generation or changes complete, ensure all of the following pass:
- Tests must pass: Run
scripts/test- all tests must pass without errors - Linting must be clean: Run
scripts/lint- code must be properly formatted and linted - Coverage must be 100%: Run
scripts/coverage- test coverage must remain at 100%
Any pull request or code changes that don't meet these requirements should be considered incomplete. If coverage drops below 100%, add the necessary tests to restore full coverage.