Unofficial Hack The Box Python SDK
Project description
Unofficial Hack The Box (HTB) Python SDK & API Client (pyhtb)
An unofficial, modern, and type-safe Python SDK and API client wrapper for the Hack The Box (HTB) platform. This library exposes fully type-hinted synchronous and asynchronous interfaces to interact programmatically with HTB APIs.
Whether you are automating machine status checking, managing teams, tracking starting point progression, or scripting challenge submissions, pyhtb provides a single unified interface.
Key Features
- Complete API Coverage: Seamlessly combines the HTB API
v4,v5, andexperience/v1specifications. - Cookie-Simple Developer Experience: No deep package imports or manually passing connection objects. Endpoints are dynamically bound directly onto the version clients.
- Modern Async & Sync Backend: Powered by
httpxfor fast, lightweight HTTP execution with full async support out of the box. - Type Safety & IDE Autocomplete: Generated with strict model definitions utilizing
attrsand type hints for robust code completion. - Zero Overhead Boilerplate: Authenticate once, and credentials automatically propagate across all supported API versions.
Installation
Install the package via pip from PyPI:
pip install pyhtb
For local development or running modifications, clone the repository and install in editable mode:
pip install -e .
Quick Start
1. Basic Client Initialization
Initialize the PyHTB client wrapper. If you want to access protected endpoints, provide your Hack The Box API token (generated on the app.hackthebox.com settings page).
from pyhtb import PyHTB
# Initialize authenticated SDK
client = PyHTB(token="YOUR_HTB_API_TOKEN")
# The unified client organizes endpoints by API version:
# - client.v4
# - client.v5
# - client.experience_v1
2. Accessing Endpoints (v5 Example)
All OpenAPI operations are dynamically bound as callable methods directly on the version clients.
Synchronous Call
from pyhtb import PyHTB
client = PyHTB(token="YOUR_HTB_API_TOKEN")
# Call any endpoint directly. Client authentication parameters are injected automatically!
machines_response = client.v5.get_machines()
for machine in machines_response.data:
print(f"Machine: {machine.name} | OS: {machine.os} | Difficulty: {machine.difficulty}")
Asynchronous Call
All asynchronous methods share the same name as sync ones but are postfixed with _async.
import asyncio
from pyhtb import PyHTB
async def main():
client = PyHTB(token="YOUR_HTB_API_TOKEN")
# Asynchronous endpoint invocation
machines_response = await client.v5.get_machines_async()
for machine in machines_response.data:
print(f"Async loaded: {machine.name}")
asyncio.run(main())
Accessing Detailed Responses (Metadata & Headers)
If you need to inspect HTTP status codes or response headers, append _detailed or _async_detailed to the method name:
response = client.v5.get_machines_detailed()
print(f"HTTP Status: {response.status_code}")
print(f"Response Headers: {response.headers}")
print(f"Parsed Body Model: {response.parsed}")
Supported APIs and Specs
The SDK is compiled from official and community-maintained reverse-engineered OpenAPI specifications:
| Version | Description | Target Submodule |
|---|---|---|
| API v4 | Primary platform endpoints (User, Teams, Challenges, Tracks, etc.) | client.v4 |
| API v5 | Modern dashboard & user activity endpoints (Machines status, University, User dashboard) | client.v5 |
| Experience v1 | Experience, Levels, and Streak endpoints | client.experience_v1 |
CLI Tool (Proof of Concept)
pyhtb ships with an experimental command-line interface that wraps the SDK into a quick-fire workflow tool. After installing the package, the yahtbcli command is available globally.
Authentication
# Store your HTB App Token (generates from app.hackthebox.com → Settings → App Tokens)
yahtbcli auth set
# Or pass it inline
yahtbcli auth set --token eyJ...
# Verify your credentials
yahtbcli auth status
# You can also export the token as an environment variable
export HTB_TOKEN="eyJ..."
Machines
# List active machines
yahtbcli machine list
# List retired machines, filtered by difficulty
yahtbcli machine list --retired --difficulty hard --os linux
# Show detailed info for a machine (by name or ID)
yahtbcli machine info Checkpoint
# Start a machine and wait for IP assignment
yahtbcli machine start Checkpoint
# Check your active machine
yahtbcli machine active
# Submit a flag
yahtbcli machine own Checkpoint <flag>
# Stop or reset the active machine
yahtbcli machine stop
yahtbcli machine reset
Challenges
# List challenges, optionally filtered by category
yahtbcli challenge list --category Web --search void
# Show challenge details (docker status, ports, etc.)
yahtbcli challenge info spookifier
# Start/stop a Docker container (by name or ID)
yahtbcli challenge start spookifier
yahtbcli challenge stop spookifier
# Submit a flag
yahtbcli challenge own spookifier <flag>
VPN
# Check active VPN connections
yahtbcli vpn status
# List available VPN servers
yahtbcli vpn servers --pool labs
# Switch to a different VPN server
yahtbcli vpn switch 113
# Download an .ovpn config file
yahtbcli vpn download 113 -o lab.ovpn
yahtbcli vpn download 113 --tcp
Search & Profile
# Global search across machines and challenges
yahtbcli search void
# Display your authenticated profile
yahtbcli whoami
Note: The CLI is a proof-of-concept companion to the SDK. It covers the most common workflows but does not expose every API endpoint. Use the SDK directly for full coverage.
Code Regeneration
The SDK contains a build pipeline to automatically compile clients from raw OpenAPI YAML specs. To regenerate the submodules after modifying any specification, execute:
./api/regen.sh
This requires openapi-python-client to be installed in your active Python environment.
License
This project is released under the Unlicense — dedicated to the public domain. See the LICENSE file for details.
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 pyhtb-0.1.2.tar.gz.
File metadata
- Download URL: pyhtb-0.1.2.tar.gz
- Upload date:
- Size: 197.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bc7917ce59ea60c10fa302b06395d8de587bd72f2f807b72d95294ba320ce25
|
|
| MD5 |
d36be7a49598dd356eb682fdaa44984c
|
|
| BLAKE2b-256 |
c64e442ab410c3c0937fb9197174994e98c1d8fc584edf2abd14a98fdea1357d
|
Provenance
The following attestation bundles were made for pyhtb-0.1.2.tar.gz:
Publisher:
publish.yml on Gubarz/pyhtb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhtb-0.1.2.tar.gz -
Subject digest:
8bc7917ce59ea60c10fa302b06395d8de587bd72f2f807b72d95294ba320ce25 - Sigstore transparency entry: 1958270667
- Sigstore integration time:
-
Permalink:
Gubarz/pyhtb@6acfdbd202ecf77a6895283a4d19f12ea8a014eb -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Gubarz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6acfdbd202ecf77a6895283a4d19f12ea8a014eb -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyhtb-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pyhtb-0.1.2-py3-none-any.whl
- Upload date:
- Size: 573.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b69f6c8a717239c9667c3b4804c767fbe196b899c16aef86e246506194a5155
|
|
| MD5 |
b5295b8cc47f89e29a95db962dd38dc1
|
|
| BLAKE2b-256 |
a30598b96b15f35a12dc3f51fb3901fc079b1d99deae61268d7185387b67d3bb
|
Provenance
The following attestation bundles were made for pyhtb-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on Gubarz/pyhtb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyhtb-0.1.2-py3-none-any.whl -
Subject digest:
6b69f6c8a717239c9667c3b4804c767fbe196b899c16aef86e246506194a5155 - Sigstore transparency entry: 1958270750
- Sigstore integration time:
-
Permalink:
Gubarz/pyhtb@6acfdbd202ecf77a6895283a4d19f12ea8a014eb -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Gubarz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6acfdbd202ecf77a6895283a4d19f12ea8a014eb -
Trigger Event:
push
-
Statement type: