Skip to main content

Client library for the Hittade API

Project description

Hittade Client

A Python HTTP client library for the Hittade API, providing both synchronous and asynchronous interfaces with full type safety.

Features

  • 🔄 Both synchronous and asynchronous clients
  • 🔒 Full type safety with Pydantic models
  • ✅ Comprehensive test coverage (42 tests, 100% passing)
  • 🔐 BasicAuth authentication support
  • 📄 Built-in pagination helpers
  • 🎯 Clean, minimal API
  • 📦 Context manager support for automatic cleanup

Installation

pip install hittade-client

Or with uv:

uv pip install hittade-client

Quick Start

Synchronous Client

from hittade_client import HittadeClient

# Basic usage
with HittadeClient(base_url="https://api.example.com") as client:
    # List all hosts
    hosts = client.list_hosts(limit=100)
    for host in hosts.items:
        print(f"{host.id}: {host.hostname}")
    
    # Paginate through all hosts
    page = client.list_hosts(limit=50)
    while page is not None:
        for host in page.items:
            print(f"{host.id}: {host.hostname}")
        page = client.next_page(page)
    
    # Get host configuration
    config = client.get_host_config("host-123")
    for entry in config:
        print(f"{entry.ctype}: {entry.name} = {entry.value}")
    
    # Get detailed host information
    details = client.get_host_details("host-123")
    print(f"OS: {details.details.osname} {details.details.osrelease}")
    print(f"IP: {details.details.ipv4}")
    print(f"Packages: {len(details.packages)}")
    print(f"Containers: {len(details.containers)}")

Asynchronous Client

from hittade_client import AsyncHittadeClient

async def main():
    async with AsyncHittadeClient(base_url="https://api.example.com") as client:
        # List hosts
        hosts = await client.list_hosts(limit=100)
        
        # Paginate through all hosts
        page = await client.list_hosts(limit=50)
        while page is not None:
            for host in page.items:
                print(f"{host.id}: {host.hostname}")
            page = await client.next_page(page)
        
        # Get host configuration
        config = await client.get_host_config("host-123")
        
        # Get detailed host information
        details = await client.get_host_details("host-123")

Authentication

from hittade_client import HittadeClient, BasicAuth

# With BasicAuth
auth = BasicAuth(username="your-username", password="your-password")

with HittadeClient(base_url="https://api.example.com", auth=auth) as client:
    hosts = client.list_hosts()

Custom Configuration

from hittade_client import HittadeClient, BasicAuth

client = HittadeClient(
    base_url="https://api.example.com",
    timeout=60.0,  # Request timeout in seconds
    headers={"X-Custom-Header": "value"},  # Custom headers
    follow_redirects=True,  # Follow HTTP redirects
    auth=BasicAuth(username="user", password="pass"),  # BasicAuth
)

# Use the client
hosts = client.list_hosts(limit=50, offset=100)

# Don't forget to close when not using context manager
client.close()

API Reference

Client Methods

list_hosts(limit=500, offset=0)

List hosts with pagination.

Parameters:

  • limit (int): Maximum number of results (default: 500, minimum: 1)
  • offset (int): Offset for pagination (default: 0, minimum: 0)

Returns: PagedHostSchema with items (list of hosts), count (total count), limit, and offset

next_page(paged_data)

Get the next page of hosts based on current page data.

Parameters:

  • paged_data (PagedHostSchema): Current page data from list_hosts()

Returns: PagedHostSchema for the next page, or None if no more results

Example:

page = client.list_hosts(limit=50)
while page is not None:
    # Process page.items
    page = client.next_page(page)

get_host_config(host_id)

Get host configuration entries.

Parameters:

  • host_id (str): The host identifier

Returns: List of HostConfigurationSchema objects

get_host_details(host_id)

Get complete host details including OS information, network configuration, packages, and containers.

Parameters:

  • host_id (str): The host identifier

Returns: CombinedHostSchema with all host details

Models

BasicAuth

  • username (str): Username for authentication
  • password (str): Password for authentication

HostSchema

  • id (str): Host identifier
  • hostname (str): Host hostname

PagedHostSchema

  • items (list[HostSchema]): List of hosts
  • count (int): Total count of hosts
  • limit (int): Limit used in request
  • offset (int): Offset used in request

HostConfigurationSchema

  • ctype (str): Configuration type
  • name (str): Configuration name
  • value (str): Configuration value

HostDetailsSchema

  • time (datetime): Timestamp
  • domain (str | None): Domain name
  • osname (str): Operating system name
  • osrelease (str): Operating system release
  • rkr (str): RKR value
  • cosmosrepourl (str): Cosmos repository URL
  • ipv4 (str | None): IPv4 address
  • ipv6 (str | None): IPv6 address
  • fail2ban (bool): Fail2ban status

PackageSchema

  • id (int): Package identifier
  • name (str): Package name
  • version (str): Package version

ServerContainerSchema

  • image (str): Container image name
  • imageid (str): Container image ID

CombinedHostSchema

  • host (HostSchema): Basic host information
  • details (HostDetailsSchema): Detailed host information
  • packages (list[PackageSchema]): Installed packages
  • containers (list[ServerContainerSchema]): Running containers
  • configs (list[HostConfigurationSchema]): Configuration entries

Exceptions

HittadeError

Base exception for all Hittade client errors.

HittadeAPIError

Raised when the API returns an HTTP error (4xx, 5xx status codes).

HittadeValidationError

Raised when response validation fails (invalid response data from API).

Development

Setup

# Install dependencies
uv sync

# Install in editable mode
uv pip install -e .

Running Tests

# Run all tests
make test

# Run with pytest directly
uv run pytest tests/ -v

Code Formatting

# Format and lint code
make reformat

Type Checking

# Run mypy type checker
make typecheck

Building Package

# Build distribution packages (wheel and source)
make build

# Clean build artifacts
make clean

Requirements

  • Python 3.11 or higher
  • httpx >= 0.28.1
  • pydantic >= 2.12.1

License

This project is licensed under the BSD 2-Clause License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

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

hittade_client-0.1.1.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

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

hittade_client-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hittade_client-0.1.1.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hittade_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a638bddd446a6a255975554a9d97cfca193d235cc9a63db6b11b095bd6fdb1f8
MD5 4c55cefd2278d046cbbee9d12a2f6bf5
BLAKE2b-256 1c050d656dcd32b1722c0e012be312c8687dc1d0564ec9e356860f54594359d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for hittade_client-0.1.1.tar.gz:

Publisher: publish-to-pypi.yml on SUNET/python-hittade-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: hittade_client-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hittade_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a61fba649de92183d2d3e2b9ebf7777d7a6c0d93fbc3285914cf7fe9c8c0ef3c
MD5 89d574d04e3fb9eb2e5013a3dbb496f0
BLAKE2b-256 d48f75e23916f2f4e1a516857065b0f72a9116c1bee096fdfcd08e0a4e5ba17d

See more details on using hashes here.

Provenance

The following attestation bundles were made for hittade_client-0.1.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on SUNET/python-hittade-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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