Python client for HipHops Hook
Project description
HipHops Hook Python Client
Python client library for integrating with HipHops Hook.
Installation
pip install hiphops-hook
The package will automatically download the appropriate Hook binary for your platform during installation.
Quick Start
from hiphops_hook import license
# Get license information
info = license()
print(info)
Usage
Basic Usage
from hiphops_hook import license
# Get license information
license_info = license()
print(f"License verified: {license_info['verified']}")
Error Handling
from hiphops_hook import license, HookError, RequestError
try:
info = license()
except RequestError as e:
print(f"Request failed: {e}")
except HookError as e:
print(f"Hook error: {e}")
API Reference
Functions
license() -> LicenseInfo
Get license information using the global client instance.
Returns:
LicenseInfo: Dictionary containing license information
Raises:
RequestError: If the request failsResponseError: If the response is invalidServerStartupError: If the server fails to start
Types
LicenseInfo
TypedDict containing license information:
class LicenseInfo(TypedDict):
verified: bool
verify_failures: List[str]
license: Optional[Dict[str, Any]]
hiphops: Dict[str, str]
# Additional fields may be present
Exceptions
HookError: Base exception for all Hook-related errorsBinaryNotFoundError: Raised when the Hook binary cannot be foundServerStartupError: Raised when the Hook server fails to startServerTimeoutError: Raised when the server startup times outRequestError: Raised when an HTTP request failsResponseError: Raised when the server returns an invalid responseDownloadError: Raised when binary download fails
Configuration
Environment Variables
HIPHOPS_HOOK_BIN: Override the path to the Hook binarySKIP_HOOK_DOWNLOAD=true: Force skip binary download
Development Mode
When SKIP_HOOK_DOWNLOAD=true, the client will skip downloading the Hook binary during installation. This is useful for development environments where you want to use a custom binary.
Platform Support
The client supports the same platforms as the Hook binary:
- macOS:
hook-darwin-amd64,hook-darwin-arm64 - Linux:
hook-linux-amd64,hook-linux-arm64 - Windows:
hook-windows-amd64.exe
Development
Local Development (Source Code)
Setting Up Development Environment
# Clone the repository
git clone https://github.com/hiphops-io/hook.git
cd hook/clients/python
# Create a virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Testing Locally (Without Installation)
Test the source code directly without installing the package:
# Set PYTHONPATH and run the test script
PYTHONPATH=. python scripts/test.py
# Test with custom binary path
HIPHOPS_HOOK_BIN=/path/to/hook/binary PYTHONPATH=. python scripts/test.py
# Skip binary download during development
SKIP_HOOK_DOWNLOAD=true PYTHONPATH=. python scripts/test.py
# Test platform detection
PYTHONPATH=. python -c "from hiphops_hook.platform_utils import get_platform_info, get_binary_name; print(f'Platform: {get_platform_info()}'); print(f'Binary: {get_binary_name()}')"
# Test with license token (if available)
LICENSE_TOKEN=your_token_here PYTHONPATH=. python scripts/test.py
Installing for Local Development
# Install in development mode (editable install)
pip install -e .
# Install with development dependencies
pip install -e ".[dev]"
# Then test the installed package
python scripts/test.py
Note: If you encounter network/SSL issues with pip, you can work around them by:
- Using the PYTHONPATH approach for testing (shown above)
- Installing dependencies individually if needed
- Using
--no-build-isolationflag:pip install -e . --no-build-isolation
Binary Management During Development
# Skip binary download during development
export SKIP_HOOK_DOWNLOAD=true
pip install -e .
# Use a custom binary path
export HIPHOPS_HOOK_BIN=/path/to/your/hook/binary
pip install -e .
Package Building and Distribution
Building the Package
python setup.py sdist
This creates a source distribution in the dist/ directory:
hiphops-hook-<version>.tar.gz- Ready for distribution
Testing the Pip Package
Test Installation from Built Package
# Create a clean test environment
python -m venv test_env
source test_env/bin/activate # On Windows: test_env\Scripts\activate
# Install from built package
pip install dist/hiphops-hook-*.tar.gz
# Test the installed package
python -c "from hiphops_hook import license; print('Package installed successfully')"
# Run comprehensive test
python -c "
from hiphops_hook import license
try:
info = license()
print('✅ Package works correctly')
print(f'License info: {info}')
except Exception as e:
print(f'❌ Package test failed: {e}')
"
# Test with license token (if available)
LICENSE_TOKEN=your_token_here python -c "
from hiphops_hook import license
try:
info = license()
print('✅ License verification test:')
print(f'Verified: {info.get(\"verified\", False)}')
print(f'License info: {info}')
except Exception as e:
print(f'❌ License test failed: {e}')
"
# Clean up
deactivate
rm -rf test_env
Test Installation from PyPI (Future)
Once published to PyPI:
# Create clean environment
python -m venv test_pypi
source test_pypi/bin/activate
# Install from PyPI
pip install hiphops-hook
# Test functionality
LICENSE_TOKEN=your_token_here python -c "
from hiphops_hook import license
info = license()
print('PyPI package works correctly')
print(info)
"
# Test with different environment variables
SKIP_HOOK_DOWNLOAD=true pip install --force-reinstall hiphops-hook
HIPHOPS_HOOK_BIN=/custom/path python -c "from hiphops_hook import license"
# Clean up
deactivate
rm -rf test_pypi
Testing Binary Download Process
# Test automatic binary download
python -c "
import os
import subprocess
import tempfile
# Create temporary directory
with tempfile.TemporaryDirectory() as tmpdir:
# Install package in clean environment
env = os.environ.copy()
env['VIRTUAL_ENV'] = tmpdir
result = subprocess.run([
'pip', 'install', 'dist/hiphops-hook-*.tar.gz'
], env=env, capture_output=True, text=True)
if 'Successfully downloaded hook binary' in result.stdout:
print('✅ Binary download works correctly')
else:
print('❌ Binary download may have issues')
print(result.stdout)
print(result.stderr)
"
Development Workflow
Complete Development Cycle
# 1. Make code changes
# Edit files in hiphops_hook/
# 2. Test locally without installation
PYTHONPATH=. python scripts/test.py
# 3. Test with editable installation
pip install -e .
python scripts/test.py
# 4. Build package
python setup.py sdist
# 5. Test built package in clean environment
python -m venv test_clean
source test_clean/bin/activate
pip install dist/hiphops-hook-*.tar.gz
python -c "from hiphops_hook import license; print(license())"
deactivate
rm -rf test_clean
# 6. Code quality checks
black hiphops_hook/ scripts/
flake8 hiphops_hook/ scripts/
mypy hiphops_hook/
Debugging
Enable verbose logging:
import logging
logging.basicConfig(level=logging.DEBUG)
from hiphops_hook import license
info = license()
Code Quality Tools
# Format code (requires black)
pip install black
black hiphops_hook/ scripts/
# Lint code (requires flake8)
pip install flake8
flake8 hiphops_hook/ scripts/
# Type checking (requires mypy)
pip install mypy
mypy hiphops_hook/
# Install all quality tools
pip install black flake8 mypy
Publishing to PyPI
Prerequisites
- PyPI Account: Create account at pypi.org
- Trusted Publisher: Configure trusted publisher for
hiphops-hookon PyPI - GitHub Environment: Create
pypienvironment in repository settings
Automated Publishing (Recommended)
Publishing is automated via GitHub Actions and triggered during the release process:
- Individual PyPI publish: Use
publish-pypi.ymlworkflow - Automatic release publishing: Both
publish-npm.ymlandpublish-pypi.ymlare triggered automatically during releases
The workflow automatically:
- Sets up Python environment
- Installs dependencies (skips binary download)
- Builds the package
- Publishes to PyPI using trusted publishing (no API tokens needed)
Manual Publishing (Development)
For testing or manual releases:
# Install publishing tools
pip install build twine
# Build the package
python setup.py sdist
# Check the package (optional but recommended)
twine check dist/*
# Publish to TestPyPI (for testing)
twine upload --repository testpypi dist/*
# Publish to PyPI (production)
twine upload dist/*
Version Management
- Python package version is synchronized with npm package
- Version is set in
pyproject.tomlandsetup.py - Must match the Hook binary version for compatibility
Support
For issues and questions, please visit: https://github.com/hiphops-io/hook/issues
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 Distributions
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 hiphops_hook-0.0.1a32.tar.gz.
File metadata
- Download URL: hiphops_hook-0.0.1a32.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82e55f6f0b6ec5cf4c20c26b3148927a7dd6d3abdaf81d22a23d2775aeaf6283
|
|
| MD5 |
0c395518269a8be30f2e03d44662e521
|
|
| BLAKE2b-256 |
96495fa57f35c97aa44833f0501d9ed19517e514213732aed014e57cfee515bd
|
Provenance
The following attestation bundles were made for hiphops_hook-0.0.1a32.tar.gz:
Publisher:
publish-pypi.yml on hiphops-io/hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hiphops_hook-0.0.1a32.tar.gz -
Subject digest:
82e55f6f0b6ec5cf4c20c26b3148927a7dd6d3abdaf81d22a23d2775aeaf6283 - Sigstore transparency entry: 267810733
- Sigstore integration time:
-
Permalink:
hiphops-io/hook@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hiphops-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hiphops_hook-0.0.1a32-py3-none-win_amd64.whl.
File metadata
- Download URL: hiphops_hook-0.0.1a32-py3-none-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d55101b4b860764d771984c3092211ee3dac2ac72d0026ab92054cb491897fe8
|
|
| MD5 |
80b545f3eeabe052cf51933457997c4f
|
|
| BLAKE2b-256 |
527b5697349a525c46794cb44184136307f80c965a78ac682378d693995446b0
|
Provenance
The following attestation bundles were made for hiphops_hook-0.0.1a32-py3-none-win_amd64.whl:
Publisher:
publish-pypi.yml on hiphops-io/hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hiphops_hook-0.0.1a32-py3-none-win_amd64.whl -
Subject digest:
d55101b4b860764d771984c3092211ee3dac2ac72d0026ab92054cb491897fe8 - Sigstore transparency entry: 267810764
- Sigstore integration time:
-
Permalink:
hiphops-io/hook@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hiphops-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hiphops_hook-0.0.1a32-py3-none-manylinux_2_17_x86_64.whl.
File metadata
- Download URL: hiphops_hook-0.0.1a32-py3-none-manylinux_2_17_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0080eb375b9ea6f97649b1d5a0c533c2b7f8b01738f98053e72a7339aa3b7be
|
|
| MD5 |
9cc172d72081f5790449df1b5a60f8c7
|
|
| BLAKE2b-256 |
8e5cbac9fcc7237df0cbda775f7a1098554eecb60954e109b9ac7b3c36e47718
|
Provenance
The following attestation bundles were made for hiphops_hook-0.0.1a32-py3-none-manylinux_2_17_x86_64.whl:
Publisher:
publish-pypi.yml on hiphops-io/hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hiphops_hook-0.0.1a32-py3-none-manylinux_2_17_x86_64.whl -
Subject digest:
a0080eb375b9ea6f97649b1d5a0c533c2b7f8b01738f98053e72a7339aa3b7be - Sigstore transparency entry: 267810758
- Sigstore integration time:
-
Permalink:
hiphops-io/hook@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hiphops-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hiphops_hook-0.0.1a32-py3-none-macosx_11_0_x86_64.whl.
File metadata
- Download URL: hiphops_hook-0.0.1a32-py3-none-macosx_11_0_x86_64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c06b39c1b5afc903859bfd3bf3557ac281c3d28c0011522baee65542dc8c6f40
|
|
| MD5 |
660b68cc826ea41049fb5664d015f968
|
|
| BLAKE2b-256 |
d54e5cd530ad73e78b6ec3009d757f16aea8305186b879dfab98d7492587555f
|
Provenance
The following attestation bundles were made for hiphops_hook-0.0.1a32-py3-none-macosx_11_0_x86_64.whl:
Publisher:
publish-pypi.yml on hiphops-io/hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hiphops_hook-0.0.1a32-py3-none-macosx_11_0_x86_64.whl -
Subject digest:
c06b39c1b5afc903859bfd3bf3557ac281c3d28c0011522baee65542dc8c6f40 - Sigstore transparency entry: 267810749
- Sigstore integration time:
-
Permalink:
hiphops-io/hook@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hiphops-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hiphops_hook-0.0.1a32-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: hiphops_hook-0.0.1a32-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f155137501392bbc4c5cbb5f6d235c4a64b93d8228409993a766a4d0b4404a2
|
|
| MD5 |
378c17822bb26a86ed983dd9aa26ed5f
|
|
| BLAKE2b-256 |
ae18e9a94d8b0b50aa347c92b13ceecee68db32cf61f14f9312f0a19ef3d59cd
|
Provenance
The following attestation bundles were made for hiphops_hook-0.0.1a32-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on hiphops-io/hook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hiphops_hook-0.0.1a32-py3-none-macosx_11_0_arm64.whl -
Subject digest:
2f155137501392bbc4c5cbb5f6d235c4a64b93d8228409993a766a4d0b4404a2 - Sigstore transparency entry: 267810743
- Sigstore integration time:
-
Permalink:
hiphops-io/hook@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/hiphops-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@684db60fe228b5f3cb39b622bb4d4dfd66025ba3 -
Trigger Event:
workflow_dispatch
-
Statement type: