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 fromlist_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 authenticationpassword(str): Password for authentication
HostSchema
id(str): Host identifierhostname(str): Host hostname
PagedHostSchema
items(list[HostSchema]): List of hostscount(int): Total count of hostslimit(int): Limit used in requestoffset(int): Offset used in request
HostConfigurationSchema
ctype(str): Configuration typename(str): Configuration namevalue(str): Configuration value
HostDetailsSchema
time(datetime): Timestampdomain(str | None): Domain nameosname(str): Operating system nameosrelease(str): Operating system releaserkr(str): RKR valuecosmosrepourl(str): Cosmos repository URLipv4(str | None): IPv4 addressipv6(str | None): IPv6 addressfail2ban(bool): Fail2ban status
PackageSchema
id(int): Package identifiername(str): Package nameversion(str): Package version
ServerContainerSchema
image(str): Container image nameimageid(str): Container image ID
CombinedHostSchema
host(HostSchema): Basic host informationdetails(HostDetailsSchema): Detailed host informationpackages(list[PackageSchema]): Installed packagescontainers(list[ServerContainerSchema]): Running containersconfigs(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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hittade_client-0.1.2.tar.gz.
File metadata
- Download URL: hittade_client-0.1.2.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30bdca44ecd28b8124568ae13c639da875cc3ec8e40e0f8b4bd4da3158f395bc
|
|
| MD5 |
d55ca8a14bbfedd155ba1b83feade148
|
|
| BLAKE2b-256 |
81d4ab3639ec36108a1a78ad87b0478c4a765137897de64413b41db546d2cd12
|
Provenance
The following attestation bundles were made for hittade_client-0.1.2.tar.gz:
Publisher:
publish-to-pypi.yml on SUNET/python-hittade-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hittade_client-0.1.2.tar.gz -
Subject digest:
30bdca44ecd28b8124568ae13c639da875cc3ec8e40e0f8b4bd4da3158f395bc - Sigstore transparency entry: 760971171
- Sigstore integration time:
-
Permalink:
SUNET/python-hittade-client@ed2f32e80d49bce129eafc1d01c429f0c993a489 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/SUNET
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ed2f32e80d49bce129eafc1d01c429f0c993a489 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hittade_client-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hittade_client-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edde669f85a88adba3981bf2a8b2658e6b212ede7d1d05bda60e5a7993a08217
|
|
| MD5 |
7e714d68eec1ddfecdd91cbe0cb92d72
|
|
| BLAKE2b-256 |
d1af2d8b0e68f317cb245224186e3b1c7195838bd20c92eab9da300634eedf89
|
Provenance
The following attestation bundles were made for hittade_client-0.1.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on SUNET/python-hittade-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hittade_client-0.1.2-py3-none-any.whl -
Subject digest:
edde669f85a88adba3981bf2a8b2658e6b212ede7d1d05bda60e5a7993a08217 - Sigstore transparency entry: 760971176
- Sigstore integration time:
-
Permalink:
SUNET/python-hittade-client@ed2f32e80d49bce129eafc1d01c429f0c993a489 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/SUNET
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ed2f32e80d49bce129eafc1d01c429f0c993a489 -
Trigger Event:
push
-
Statement type: