Skip to main content

In-process WSGI HTTP and WebSocket test doubles (fake sockets, no listening port).

Project description

wsgiref-fake

In-process WSGI test doubles: fake sockets and a minimal server harness so you can exercise HTTP (and optionally WebSocket) applications without binding a real port or talking over the network.

Useful for fast, deterministic tests against code built on wsgiref and similar stacks.

Requirements

  • Python 3.10 or newer
  • Runtime dependency: six (Python 2/3 compatibility helpers used in this library)

Installation

pip install wsgiref-fake

With uv:

uv add wsgiref-fake

Optional extras

Extra Purpose
gevent Gevent-based WebSocket client helpers
ws4py Integration helpers around ws4py
pip install "wsgiref-fake[gevent]"
pip install "wsgiref-fake[ws4py]"

Quick start (HTTP)

Wire your WSGI app to an in-process server, then drive it with HTTPClient:

from wsgiref_fake.http.client import HTTPClient
from wsgiref_fake.server import make_server


def app(environ, start_response):
    start_response("200 OK", [("Content-Type", "text/plain")])
    return [b"Hello World"]


server = make_server(app=app)
client = HTTPClient(server=server)

response = client.request(method="GET", path="/")
assert response.status == 200
body = response.read()

HTTPClient.request accepts method, path, optional json (sets Content-Type and body), and optional headers.

Why this exists

  • No listening socket — tests stay hermetic and parallel-friendly.
  • Same WSGI surface as production-oriented wsgiref servers, without TCP overhead.
  • WebSocket-related helpers are available when you install the optional dependency groups above.

Development

Clone the repository, then install the project with dev dependencies:

uv sync

Run the test suite:

uv run pytest

Lint and format the whole tree:

uv run ruff check .
uv run ruff format .

Contributing

Issues and pull requests are welcome. Please run tests before opening a PR.

License

This project is licensed under the MIT License.

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

wsgiref_fake-1.0.4.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

wsgiref_fake-1.0.4-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file wsgiref_fake-1.0.4.tar.gz.

File metadata

  • Download URL: wsgiref_fake-1.0.4.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wsgiref_fake-1.0.4.tar.gz
Algorithm Hash digest
SHA256 282a20c91de19383409be0140ba4dc79e45136bdbd0422b4b8a71078110698e1
MD5 0f891c4d1494523011332ee56c3615d4
BLAKE2b-256 6e186fe20ea23a883bf96b424e8f693cd96e04fbed363ca9ad020298cdbfe511

See more details on using hashes here.

File details

Details for the file wsgiref_fake-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: wsgiref_fake-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for wsgiref_fake-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e932c14c3208af5d1d5c6e9061059ad499ac2e010c59c0bbd2a67e8069524942
MD5 29043e8605b3e3f7f0056621eee4108e
BLAKE2b-256 8586e750d87cba5c8cdb5d0566a527c26785919d545253c0eb1c58d88cb57177

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