Skip to main content

Fail-closed Tor session enforcement for Python HTTP(S) traffic

Project description

PyPI version Python versions License

ProtoX GateKeeper

ProtoX GateKeeper is a small, opinionated Python library that enforces fail-closed Tor routing for HTTP(S) traffic.

The goal is simple:

If Tor is not active and verified, nothing runs.

GateKeeper is designed to be fire-and-forget: create a client once, then perform network operations with a hard guarantee that traffic exits through the Tor network.


What GateKeeper Is

  • A Tor-verified HTTP client
  • A thin wrapper around requests.Session with safe helpers
  • Fail-closed by default (no silent clearnet fallback)
  • Observable (exit IP, optional geo info)
  • Suitable for scripts, tooling, and automation

What GateKeeper Is NOT

  • ❌ A Tor controller
  • ❌ A crawler or scanner
  • ❌ An anonymization silver bullet
  • ❌ A replacement for Tor Browser

GateKeeper enforces transport routing only. You are still responsible for what you do with it.


Requirements

  • A locally running Tor client
  • SOCKS proxy enabled (default: 127.0.0.1:9150)

On Windows this usually means Tor Browser running in the background.


Installation

From PyPI

pip install protox-gatekeeper

From source (development)

pip install -e .

(Recommended while developing or testing.)


Basic Usage

import logging
from protox_gatekeeper import GateKeeper

logging.basicConfig(
    level=logging.INFO,
    format='[%(levelname)s] %(name)s - %(message)s'
)

gk = GateKeeper(geo=True)

gk.download(
    "https://httpbin.org/bytes/1024",
    "downloads/test.bin"
)

Example output

[INFO] gatekeeper.core - Tor verified: 89.xxx.xxx.xxx -> 185.xxx.xxx.xxx
[INFO] gatekeeper.core - Tor exit location: Brandenburg, DE
[INFO] gatekeeper.core - [Tor 185.xxx.xxx.xxx] downloading https://httpbin.org/bytes/1024 -> downloads/test.bin

This confirms:

  • clearnet IP was measured
  • Tor routing was verified
  • all traffic used the Tor exit shown

HTTP requests

GateKeeper can also be used as a Tor-verified HTTP client:

with GateKeeper() as gk:
    response = gk.get("https://httpbin.org/ip")
    print(response.json())

All requests are guaranteed to use the verified Tor session.


API Overview

GateKeeper(...)

gk = GateKeeper(
    socks_port=9150,
    geo=False
)

Parameters:

  • socks_port (int) – Tor SOCKS port (default: 9150)
  • geo (bool) – Enable best-effort Tor exit geolocation (optional)

Raises RuntimeError if Tor routing cannot be verified.


request(method, url, **kwargs)

Performs an arbitrary HTTP request through the verified Tor session.

This is a thin passthrough to requests.Session.request, with enforced Tor routing and logging.

r = gk.request(
    "GET",
    "https://httpbin.org/ip",
    timeout=10
)
print(r.json())
  • method – HTTP verb (GET, POST, PUT, DELETE, ...)
  • url – Target URL
  • **kwargs – Forwarded directly to requests

This is the core execution path used internally by helper methods like get() and post().


download(url, target_path)

Downloads a resource through the verified Tor session.

gk.download(url, target_path)
  • url – HTTP(S) URL
  • target_path – Full local file path (directories created automatically)

download(url, target_path)

Downloads a resource through the verified Tor session.

gk.download(url, target_path)
  • url – HTTP(S) URL
  • target_path – Full local file path (directories created automatically)

get(url, **kwargs)

Performs a Tor-verified HTTP GET request.

response = gk.get(url, timeout=10)

Returns a standard requests.Response.


post(url, data=None, json=None, **kwargs)

Performs a Tor-verified HTTP POST request.

response = gk.post(url, json={"key": "value"})

Returns a standard requests.Response.


Design Principles

  • Fail closed: no Tor → no execution
  • Single verification point (during construction)
  • No global state
  • No logging configuration inside the library
  • Session reuse without re-verification

Logging is emitted by the library, but configured by the application.


Logging

GateKeeper uses standard Python logging:

import logging
logging.basicConfig(level=logging.INFO)

The library does not call logging.basicConfig() internally.


Security Notes

  • Tor exit IPs may rotate over time
  • Geo information is best-effort and may be unavailable (rate-limits, CAPTCHAs)
  • GateKeeper guarantees transport routing, not anonymity

License

MIT License


Status

  • Version: v0.2.2
  • Phase 2 in progress
  • API intentionally minimal

Future versions may add optional features such as:

  • circuit rotation
  • ControlPort support
  • higher-level request helpers

Without breaking the core contract.

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

protox_gatekeeper-0.2.2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

protox_gatekeeper-0.2.2-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file protox_gatekeeper-0.2.2.tar.gz.

File metadata

  • Download URL: protox_gatekeeper-0.2.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for protox_gatekeeper-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0474c7478cabe1398e8207f1420a6f6d1151265bb2a02a133b7b610f8bf65aa1
MD5 a5bb03131f942ea5581941be9da8b10e
BLAKE2b-256 8d9b9ab408d4f03f427f5cec16d20532442a08ff12af27e66d16f08bcc8bb602

See more details on using hashes here.

File details

Details for the file protox_gatekeeper-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for protox_gatekeeper-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ef26a8069aff802c9c97239eb732f61fef137aa94e939047fc3ad1b1b0353a6
MD5 6076d1be328c543e34c01584a32c27aa
BLAKE2b-256 5ff67453b43f7ec9e5f1afe4632779d3fda9fdc4420b9401e1f803c3910a3813

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