Skip to main content

governed-http

A lightweight HTTP client with typed request/response contracts, request interception, and built-in request tracing.

It behaves like requests, but adds:

  • Optional preflight checks before a request is sent
  • Structured decision logging
  • Pydantic-based request and response validation
  • Dry-run mode (no network call)
  • Pluggable transport for testing

Minimal dependencies: standard library + Pydantic.

Why use this?

Most HTTP clients simply send requests and return responses.

This client adds a control layer:

  • Every request can be inspected before execution
  • Calls can be blocked based on host or custom rules
  • Each request records what was attempted and what happened
  • Responses can be validated against typed models

Useful for:

  • Restricting outbound API calls
  • Enforcing allowed hosts
  • Building typed API wrappers
  • Testing external integrations deterministically
  • Capturing structured request traces

Installation

pip install governed-http-sdk

Quick Example

from governed_http import Client

client = Client(
    base_url="https://api.example.com",
    allowed_hosts=["api.example.com"]
)

res = client.get("/status")
print(res.status_code)

Typed Operations

from pydantic import BaseModel
from governed_http import Client, Operation

class CreateThing(BaseModel):
    name: str

class Thing(BaseModel):
    id: int
    name: str

op = Operation(
    method="POST",
    path="/v1/things",
    request=CreateThing,
    response=Thing,
)

client = Client(
    base_url="https://api.example.com",
    allowed_hosts=["api.example.com"]
)

result: Thing = client.call(op, {"name": "example"})

The payload is validated before sending. The response is parsed into a typed model.

Dry Run (No Network)

preview = client.dry_run_request("GET", "/v1/things")
print(preview)

Returns:

  • Final URL
  • Headers
  • Request body
  • Preflight decision

Interceptors

Custom logic can be added before or after a request:

  • Allow or deny outbound calls
  • Modify headers
  • Record additional metadata
  • Enforce custom policy rules

Testing with Mock Transport

The built-in MockTransport allows deterministic testing without network access.

Summary

This package provides:

  • A small, dependency-light HTTP client
  • Typed request/response validation
  • Optional outbound host restrictions
  • Structured request tracing
  • Pluggable transport for testing

It is designed for applications that need more control and visibility over outbound HTTP calls than a basic client provides.

Install (editable)

Push-Location artifact-verifier
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .
Pop-Location

Release files for governed-http-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for governed-http-sdk 0.1.1
File Size Uploaded
governed_http_sdk-0.1.1.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for governed-http-sdk 0.1.1
File Interpreter ABI Platform
governed_http_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / governed_http_sdk-0.1.1.tar.gz

Download URL governed_http_sdk-0.1.1.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d04308b2ba2fda3871da2e200793035203b980af3dec34d5aadf8c411540c542
BLAKE2b-256 checksum
How to use checksums
58d338cb5973b95a640763e627c40a8b525118ce53bdd9110e145343f797c849
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / governed_http_sdk-0.1.1-py3-none-any.whl

Download URL governed_http_sdk-0.1.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c496d17973c7a71b1ef80ee1abbcc7a82b933e94d494c7d52df7cd7815ad9a0
BLAKE2b-256 checksum
How to use checksums
64df4e3507edbe3a0604edbc9b4e7e73381c3a5b5f43099bbc5a5d35d39decce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page