Skip to main content

An asynchronous client for the Live Update Server API.

Project description

Live Update Server Client

PyPI version

An asynchronous Python client library for interacting with the Live Update Server API.

This client allows your Python applications (e.g., tool wrappers) to easily send log messages and structured results to the server, and enables other applications (like a dashboard backend or monitoring tools) to poll for updates.

Features

  • Asynchronous interface using httpx.
  • Send updates (logs, results, status) associated with a scan_uuid and tool_name.
  • Fetch updates for a specific scan_uuid, with options to poll for new updates since a specific ID or timestamp.
  • Optional filtering of fetched updates by tool_name.
  • Simple error handling.

Requirements

  • Python 3.7+
  • A running instance of the Live Update Server that this client can connect to.

Installation

Install the package directly from PyPI:

pip install live-update-client

Usage

Here's a basic example demonstrating how to send and fetch updates:

import asyncio
import datetime
from live_update_client import UpdateServerClient, UpdateServerClientError

# Replace with the actual URL of your running Live Update Server
SERVER_URL = "http://localhost:5000"
TEST_SCAN_ID = "scan-abc-789"
TOOL_NAME = "example-scanner"

async def run_example():
    client = UpdateServerClient(base_url=SERVER_URL)
    last_id = None

    try:
        # --- Sending Updates ---
        print(f"Sending status update for {TEST_SCAN_ID}/{TOOL_NAME}...")
        status_update_id = await client.send_update(
            scan_uuid=TEST_SCAN_ID,
            tool_name=TOOL_NAME,
            log_type="status",
            content="Scanner initialized."
        )
        print(f"-> Sent update with ID: {status_update_id}")
        last_id = status_update_id # Keep track for polling

        print(f"\nSending a log line for {TEST_SCAN_ID}/{TOOL_NAME}...")
        log_update_id = await client.send_update(
            scan_uuid=TEST_SCAN_ID,
            tool_name=TOOL_NAME,
            log_type="stdout",
            content="[INFO] Target scanned: example.com"
        )
        print(f"-> Sent update with ID: {log_update_id}")
        last_id = log_update_id

        print(f"\nSending a result for {TEST_SCAN_ID}/{TOOL_NAME}...")
        result_update_id = await client.send_update(
            scan_uuid=TEST_SCAN_ID,
            tool_name=TOOL_NAME,
            log_type="result",
            content={"vulnerability": "XSS", "severity": "Medium", "path": "/search"}
        )
        print(f"-> Sent update with ID: {result_update_id}")
        last_id = result_update_id

        # --- Fetching Updates ---
        print(f"\nFetching all updates for {TEST_SCAN_ID}:")
        all_updates = await client.get_updates(scan_uuid=TEST_SCAN_ID)
        print(f"-> Received {len(all_updates)} total updates.")
        for update in all_updates:
             print(f"  - ID={update['id']}, Tool={update['tool_name']}, Type={update['log_type']}, Time={update['timestamp']}")
             # In a real polling scenario, you'd update last_id here
             # last_id = update['id']


        print(f"\nFetching only new updates for {TEST_SCAN_ID} (since ID {last_id}):")
        # Pass the ID of the last update you processed
        new_updates = await client.get_updates(scan_uuid=TEST_SCAN_ID, since_id=last_id)
        if new_updates:
            print(f"-> Received {len(new_updates)} new updates:")
            for update in new_updates:
                 print(f"  - ID={update['id']}, Tool={update['tool_name']}, Type={update['log_type']}, Time={update['timestamp']}")
                 last_id = update['id'] # Update last_id for next poll
        else:
            print("-> No new updates found.")

    except UpdateServerClientError as e:
        print(f"\nCLIENT ERROR: {e}")
    except Exception as e:
        print(f"\nUNEXPECTED ERROR: {e}")
    finally:
        # Close the client connection when done
        print("\nClosing client...")
        await client.close()
        print("Client closed.")

if __name__ == "__main__":
    asyncio.run(run_example())

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

live_update_client-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

live_update_client-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file live_update_client-0.1.1.tar.gz.

File metadata

  • Download URL: live_update_client-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.11

File hashes

Hashes for live_update_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 54674c639f7a4369dcb87bfef618ed87181255c8e6c97153e5b15bec36b1a23d
MD5 7368705133a1367e092d941bda84d08d
BLAKE2b-256 90b1410097c07eb17c951296728b30ff8afd443d85d65b55a52bcd14ed05d800

See more details on using hashes here.

File details

Details for the file live_update_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for live_update_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20c10968c6385b0c592ba96d61f3be06f607f322a30cc99803ca469920440d1d
MD5 4538a2ea4e7e3b6a3e965bbba2875688
BLAKE2b-256 7697445011421d4ba88a5bdb8877c260c7e402b36a91f8da9521515068c369b7

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