Skip to main content

Python Implementation

The Python implementation lives in the aihint/ directory and provides a full API, CLI, and trust scoring engine.

Requirements: Python 3.8+

Setup

From the repository root, install the required third-party Python packages:

python -m pip install cryptography requests jsonschema click pydantic aiohttp dnspython python-whois

Then run the CLI directly from source:

python -m aihint.cli --help
Run from the repository root

The JSON Schema validator looks for schema/aihint-global.schema.json relative to your working directory. Running commands from the repo root ensures validation works correctly. If the file isn't found, a built-in fallback schema is used.

CLI Usage

Run CLI commands with python -m aihint.cli from the repository root:

Create a hint

python -m aihint.cli create \
--target "https://example.com" \
--issuer "https://trust.example.org" \
--score 0.85 \
--method "aihint-core-v1" \
--public-key-url "https://example.com/.well-known/aihint-pubkey.pem" \
--private-key private_key.pem \
--output aihint.json

Options:

OptionRequiredDescription
--targetYesTarget domain URL
--issuerYesIssuing authority URL
--scoreYesTrust score (0.0–1.0)
--methodYesScoring method identifier
--public-key-urlYesURL of the public key
--private-keyNoPrivate key file to sign the hint
--output / -oNoOutput file path
--expires-inNoExpiration in days (default: 365)
--commentNoOptional comment
--versionNoAiHint version (default: 0.1)

Validate a hint

python -m aihint.cli validate aihint.json

Verify a signature

python -m aihint.cli verify aihint.json

This fetches the public key from the public_key_url in the hint and verifies the RSA-SHA256 signature.

View hint info

python -m aihint.cli info aihint.json

Sign an existing hint

python -m aihint.cli sign aihint.json --private-key private_key.pem

Create with auto-scoring

python -m aihint.cli create-with-score \
--target "https://example.com" \
--issuer "https://trust.example.org" \
--public-key-url "https://example.com/.well-known/aihint-pubkey.pem" \
--private-key private_key.pem \
--output aihint.json

This runs the trust scoring engine against the target domain and uses the result as the score.

Trust scoring

# Score a single website
python -m aihint.cli scoring score https://example.com

# Score with JSON output
python -m aihint.cli scoring score https://example.com --format json

# Score multiple URLs
python -m aihint.cli scoring batch https://example.com https://another.com

# Score URLs from a file
python -m aihint.cli scoring batch --file urls.txt

# Generate a sample config file
python -m aihint.cli scoring config --output scoring-config.json

Scoring output formats: text (default), json, table

Python API

Basic usage

import sys
sys.path.insert(0, '/path/to/aihint-standard')

from datetime import datetime, timezone, timedelta
from aihint import AIHint

api = AIHint()

# Create a hint
hint = api.create_global_hint(
target="https://example.com",
issuer="https://trust.example.org",
score=0.85,
method="aihint-core-v1",
public_key_url="https://example.com/.well-known/aihint-pubkey.pem",
expires_at=datetime.now(timezone.utc) + timedelta(days=365),
comment="Verified domain",
)

# Sign the hint
signed = api.sign_hint(hint, "private_key.pem")

# Save to file
api.save_hint(signed, "aihint.json")

# Load and verify
loaded = api.load_hint("aihint.json")
is_valid = api.validate_hint(loaded) # True if schema-valid
is_verified = api.verify_hint(loaded) # True if signature checks out

Lower-level classes

When running from the repo root, you can import directly:

from aihint import AIHintValidator, AIHintSigner, AIHintVerifier

# Validate a dict against the JSON Schema
validator = AIHintValidator()
validator.validate(hint_dict) # raises AIHintValidationError on failure
validator.validate_file("aihint.json")

# Sign a dict
signer = AIHintSigner("private_key.pem")
signature = signer.sign(hint_dict) # returns Base64 signature string

# Verify a dict (fetches public key from public_key_url)
verifier = AIHintVerifier()
result = verifier.verify(hint_dict) # True/False
verifier.verify_file("aihint.json")

Trust scoring

import asyncio
from aihint.scoring import TrustScoringEngine

engine = TrustScoringEngine()
result = asyncio.run(engine.score_website("https://example.com"))

print(f"Score: {result.final_score}")
print(f"Trust level: {result.trust_level}")
print(f"Security: {result.security_score}")
print(f"Reputation: {result.reputation_score}")
print(f"Compliance: {result.compliance_score}")

The scoring engine evaluates:

CategoryWeightScorers
Security40%SSL/TLS validation, security headers, malware checks
Reputation35%Domain reputation, domain age, incident history
Compliance25%Privacy policy, contact info, compliance checks

Exported Classes

ClassModulePurpose
AIHintaihintHigh-level facade for all operations
AIHintValidatoraihint.coreJSON Schema validation
AIHintSigneraihint.coreRSA-SHA256 signing
AIHintVerifieraihint.coreSignature verification (fetches public key via HTTP)
AIHintGlobalaihint.modelsPydantic model for a Global Hint document
AIHintDataaihint.modelsPydantic model for hint data
TrustScoringEngineaihint.scoringAsync trust scoring engine

Required Python Packages

These third-party packages must be installed for the implementation to work:

PackagePurpose
cryptographyRSA signing and verification
requestsHTTP requests (public key fetching)
jsonschemaJSON Schema validation
clickCLI framework
pydanticData models and validation
aiohttpAsync HTTP for trust scoring
dnspythonDNS resolution for scoring
python-whoisWHOIS lookups for domain age scoring

Install all at once:

python -m pip install cryptography requests jsonschema click pydantic aiohttp dnspython python-whois