Skip to main content

Governed HTTP client SDK with Requests-like ergonomics and typed contracts

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

governed_http_sdk-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

governed_http_sdk-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file governed_http_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: governed_http_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for governed_http_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d04308b2ba2fda3871da2e200793035203b980af3dec34d5aadf8c411540c542
MD5 78049f23518a18cdd29b1a694c8feaef
BLAKE2b-256 58d338cb5973b95a640763e627c40a8b525118ce53bdd9110e145343f797c849

See more details on using hashes here.

File details

Details for the file governed_http_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for governed_http_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c496d17973c7a71b1ef80ee1abbcc7a82b933e94d494c7d52df7cd7815ad9a0
MD5 2278d988b49bcdc4c22a562b13f60845
BLAKE2b-256 64df4e3507edbe3a0604edbc9b4e7e73381c3a5b5f43099bbc5a5d35d39decce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page